Skip to content

Commit

Permalink
set the instance identifier in the deployment, use in the code
Browse files Browse the repository at this point in the history
  • Loading branch information
gvelez17 committed Apr 24, 2024
1 parent f1b7fec commit 55ff56d
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 13 deletions.
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ RUN npm install

WORKDIR /

COPY entrypoint.sh .
RUN chmod +x ./entrypoint.sh

COPY runner.sh .

ENTRYPOINT ["./entrypoint.sh"]
CMD [ "./runner.sh" ]
2 changes: 1 addition & 1 deletion config/env/dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"traceRatio": "@@METRICS_TRACE_RATIO",
"exportIntervalMillis": "@@METRICS_EXPORT_INTERVAL_MS",
"exportTimeoutMillis": "@@METRICS_EXPORT_TIMEOUT_MS",
"instanceIdentifier": "@@ECS_CONTAINER_METADATA_URI",
"instanceIdentifier": "@@INSTANCE_IDENTIFIER",
"prometheusPort": "@@METRICS_PORT"
},
"db": {
Expand Down
2 changes: 1 addition & 1 deletion config/env/prod.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"traceRatio": "@@METRICS_TRACE_RATIO",
"exportIntervalMillis": "@@METRICS_EXPORT_INTERVAL_MS",
"exportTimeoutMillis": "@@METRICS_EXPORT_TIMEOUT_MS",
"instanceIdentifier": "@@ECS_CONTAINER_METADATA_URI",
"instanceIdentifier": "@@INSTANCE_IDENTIFIER",
"prometheusPort": "@@METRICS_PORT"
},
"db": {
Expand Down
2 changes: 1 addition & 1 deletion config/env/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"traceRatio": "@@METRICS_TRACE_RATIO",
"exportIntervalMillis": "@@METRICS_EXPORT_INTERVAL_MS",
"exportTimeoutMillis": "@@METRICS_EXPORT_TIMEOUT_MS",
"instanceIdentifier": "@@ECS_CONTAINER_METADATA_URI",
"instanceIdentifier": "@@INSTANCE_IDENTIFIER",
"prometheusPort": "@@METRICS_PORT"
},
"db": {
Expand Down
14 changes: 14 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

instance_uri=$ECS_CONTAINER_METADATA_URI

# Parse the last portion of the URI
instance_id=${instance_uri##*/}

# Remove everything after the hyphen to get the task ID
instance_id=${instance_id%%-*}

# if present, will be the task ID, otherwise empty string
export INSTANCE_IDENTIFIER=$instance_id

exec "$@"
11 changes: 1 addition & 10 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,7 @@ export class CeramicAnchorApp {
Metrics.count('HELLO', 1)
logger.imp('Metrics exporter started')
if (this.config.metrics.instanceIdentifier) {
// In the API server, the instanceIdentifer is set from ECS_CONTAINER_METADATA_URI
// example value: http://169.254.170.2/v3/234fae8d117d4b76a7af0600b94fc195-2439726129

// in this case, return only the task id following the last /
const match = this.config.metrics.instanceIdentifier.match(/\/([^/]*)$/);
if (match && match[1]) {
Metrics.setInstanceIdentifier(match[1])
} else {
Metrics.setInstanceIdentifier(this.config.metrics.instanceIdentifier)
}
Metrics.setInstanceIdentifier(this.config.metrics.instanceIdentifier)
}
} catch (e: any) {
logger.imp('ERROR: Metrics exporter failed to start. Continuing anyway.')
Expand Down

0 comments on commit 55ff56d

Please sign in to comment.