|
| 1 | +# Amazon ECS EC2 Deployment |
| 2 | +Familiarity with Amazon ECS using launch type EC2 is assumed. Consult the |
| 3 | +[Getting started with the Amazon ECS console using Amazon EC2](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/getting-started-ecs-ec2.html) |
| 4 | +for further reading. |
| 5 | + |
| 6 | +The |
| 7 | +[Splunk OpenTelemetry Connector](https://github.com/signalfx/splunk-otel-collector) |
| 8 | +(Collector) should to be run as a Daemon service in an EC2 ECS cluster. |
| 9 | + |
| 10 | +Requires Connector release v0.34.0 or newer which corresponds to image tag 0.34.0 and newer. |
| 11 | +See image repository [here](https://quay.io/repository/signalfx/splunk-otel-collector?tab=tags). |
| 12 | + |
| 13 | +## Getting Started |
| 14 | +### Create Task Definition |
| 15 | +Take the task definition JSON for the Collector [here](./splunk-otel-collector.json), replace |
| 16 | +`MY_SPLUNK_ACCESS_TOKEN` and `MY_SPLUNK_REALM` with valid values. Update the image tag to |
| 17 | +the newest version. Use the JSON to create a task definition of **EC2 launch type** following |
| 18 | +the instructions [here](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/create-task-definition.html). |
| 19 | + |
| 20 | +The Collector is configured to use the default configuration file `/etc/otel/collector/ecs_ec2_config.yaml`. |
| 21 | +The Collector image Dockerfile is available [here](../../../cmd/otelcol/Dockerfile) and the contents of the default |
| 22 | +configuration file can be seen [here](../../../cmd/otelcol/config/collector/ecs_ec2_config.yaml). |
| 23 | + |
| 24 | +**Note**: You do not need the `smartagent/ecs-metadata` metrics receiver in the default |
| 25 | +configuration file if all you want is tracing. You can take the default configuration, remove |
| 26 | +the receiver, then use the configuration in a custom configuration following the direction |
| 27 | +in the [custom configuration](#custom-configuration) section. |
| 28 | + |
| 29 | +The configured network mode for the task is **host**. This means that **task metadata endpoint |
| 30 | +version 2** used by receiver `smartagent/ecs-metadata` is not enabled by default. See |
| 31 | +[here](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-metadata-endpoint.html) |
| 32 | +if **task metadata endpoint version 3** is enabled by default for your task. If enabled add the |
| 33 | +following to the **environment** list in the task definition JSON: |
| 34 | +```json |
| 35 | +{ |
| 36 | + "name": "ECS_TASK_METADATA_ENDPOINT", |
| 37 | + "value": "${ECS_CONTAINER_METADATA_URI}/task" |
| 38 | +}, |
| 39 | +{ |
| 40 | + "name": "ECS_TASK_STATS_ENDPOINT", |
| 41 | + "value": "${ECS_CONTAINER_METADATA_URI}/task/stats" |
| 42 | +} |
| 43 | +``` |
| 44 | + |
| 45 | +Assign a stringified array of metrics you want excluded to environment variable |
| 46 | +`METRICS_TO_EXCLUDE`. You can set the memory limit for the memory limiter processor using |
| 47 | +environment variable `SPLUNK_MEMORY_LIMIT_MIB`. The default memory limit is 512 MiB. For |
| 48 | +more information about the memory limiter processor, see |
| 49 | +[here](https://github.com/open-telemetry/opentelemetry-collector/blob/main/processor/memorylimiter/README.md) |
| 50 | + |
| 51 | +### Launch the Collector |
| 52 | +The Collector is designed to be run as a Daemon service in an EC2 ECS cluster. |
| 53 | + |
| 54 | +To create a Collector service from the Amazon ECS console: |
| 55 | + |
| 56 | +Go to your cluster in the console |
| 57 | +1. Click on the "Services" tab. |
| 58 | +2. Click "Create" at the top of the tab. |
| 59 | +3. Select: |
| 60 | + - Launch Type -> EC2 |
| 61 | + - Task Definition (Family) -> splunk-otel-collector |
| 62 | + - Task Definition (Revision) -> 1 (or whatever the latest is in your case) |
| 63 | + - Service Name -> splunk-otel-collector |
| 64 | + - Service type -> DAEMON |
| 65 | +4. Leave everything else at default and click "Next step" |
| 66 | +5. Leave everything on this next page at their defaults and click "Next step". |
| 67 | +6. Leave everything on this next page at their defaults and click "Next step". |
| 68 | +7. Click "Create Service" and the collector should be deployed onto each node in the ECS cluster. You should see infrastructure and docker metrics flowing soon. |
| 69 | + |
| 70 | +## Custom Configuration |
| 71 | +To use a custom configuration file, replace the value of environment variable |
| 72 | +`SPLUNK_CONFIG` with the file path of the custom configuration file in Collector |
| 73 | +task definition. |
| 74 | + |
| 75 | +Alternatively, you can specify the custom configuration YAML directly using environment |
| 76 | +variable `SPLUNK_CONFIG_YAML` as describe [below](#direct-configuration). |
| 77 | + |
| 78 | +### ecs_observer |
| 79 | +Use extension |
| 80 | +[Amazon Elastic Container Service Observer](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/extension/observer/ecsobserver#amazon-elastic-container-service-observer) |
| 81 | +(`ecs_observer`) in your custom configuration to discover metrics targets |
| 82 | +in running tasks, filtered by service names, task definitions and container labels. |
| 83 | +`ecs_observer` is currently limited to Prometheus targets and requires the read-only |
| 84 | +permissions below. You can add the permissions to the task role by adding them to a |
| 85 | +customer-managed policy that is attached to the task role. |
| 86 | +```text |
| 87 | +ecs:List* |
| 88 | +ecs:Describe* |
| 89 | +``` |
| 90 | + |
| 91 | +Below is an example of a custom configuration in which the `ecs_observer` is configured to find |
| 92 | +Prometheus targets in cluster `lorem-ipsum-cluster`, region `us-west-2`, where the task ARN |
| 93 | +pattern is `^arn:aws:ecs:us-west-2:906383545488:task-definition/lorem-ipsum-task:[0-9]+$`. |
| 94 | +The results are written to file `/etc/ecs_sd_targets.yaml`. The `prometheus` receiver is |
| 95 | +configured to read targets from the results file. The values for `access_token` |
| 96 | +and `realm` are read from environment variables `SPLUNK_ACCESS_TOKEN` and `SPLUNK_REALM` |
| 97 | +respectively, which must be specified in your container definition. |
| 98 | + |
| 99 | +```yaml |
| 100 | +extensions: |
| 101 | + ecs_observer: |
| 102 | + refresh_interval: 10s |
| 103 | + cluster_name: 'lorem-ipsum-cluster' |
| 104 | + cluster_region: 'us-west-2' |
| 105 | + result_file: '/etc/ecs_sd_targets.yaml' |
| 106 | + task_definitions: |
| 107 | + - arn_pattern: "^arn:aws:ecs:us-west-2:906383545488:task-definition/lorem-ipsum-task:[0-9]+$" |
| 108 | + metrics_ports: [9113] |
| 109 | + metrics_path: /metrics |
| 110 | +receivers: |
| 111 | + prometheus: |
| 112 | + config: |
| 113 | + scrape_configs: |
| 114 | + - job_name: 'lorem-ipsum-nginx' |
| 115 | + scrape_interval: 10s |
| 116 | + file_sd_configs: |
| 117 | + - files: |
| 118 | + - '/etc/ecs_sd_targets.yaml' |
| 119 | +processors: |
| 120 | + batch: |
| 121 | + resourcedetection: |
| 122 | + detectors: [ecs] |
| 123 | + override: false |
| 124 | +exporters: |
| 125 | + signalfx: |
| 126 | + access_token: ${SPLUNK_ACCESS_TOKEN} |
| 127 | + realm: ${SPLUNK_REALM} |
| 128 | +service: |
| 129 | + extensions: [ecs_observer] |
| 130 | + pipelines: |
| 131 | + metrics: |
| 132 | + receivers: [prometheus] |
| 133 | + processors: [batch, resourcedetection] |
| 134 | + exporters: [signalfx] |
| 135 | +``` |
| 136 | +
|
| 137 | +### Direct Configuration |
| 138 | +The Collector provides environment variable `SPLUNK_CONFIG_YAML` for specifying the |
| 139 | +configuration YAML directly which can be used instead of `SPLUNK_CONFIG`. |
| 140 | + |
| 141 | +For example, you can store the custom configuration above in a parameter called |
| 142 | +`splunk-otel-collector-config` in **AWS Systems Manager Parameter Store**. Then |
| 143 | +assign the parameter to environment variable `SPLUNK_CONFIG_YAML` using `valueFrom`. |
| 144 | + |
| 145 | +**Note:** You should add policy `AmazonSSMReadOnlyAccess` to the task role in order for |
| 146 | +the task to have read access to the Parameter Store. |
0 commit comments