-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PP-11224: Add Dockerfile, config, and unit test workflow
- Loading branch information
Showing
11 changed files
with
925 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: Build and test | ||
|
||
on: | ||
workflow_dispatch: | ||
workflow_call: | ||
pull_request: | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
detect-secrets: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Git checkout | ||
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab | ||
- name: Detect secrets | ||
uses: alphagov/pay-ci/actions/detect-secrets@master | ||
|
||
build-and-test: | ||
name: Container Build Tests | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab | ||
- name: Docker build | ||
run: | | ||
docker build -t pay-adot:github-tests . | ||
- name: Run tests | ||
working-directory: tests/ | ||
run: ./test.sh | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
FROM amazon/aws-otel-collector:v0.30.0 | ||
|
||
COPY config.yml /etc/ecs/govuk-pay-adot-sidecar-config.yaml | ||
|
||
CMD ["--config=/etc/ecs/govuk-pay-adot-sidecar-config.yaml"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
receivers: | ||
prometheus: | ||
config: | ||
global: | ||
scrape_interval: 15s | ||
scrape_timeout: 10s | ||
scrape_configs: | ||
- job_name: "adot-sidecar-scrape-application" | ||
static_configs: | ||
- targets: [ "127.0.0.1:$APPLICATION_PORT" ] | ||
honor_labels: true | ||
honor_timestamps: true | ||
|
||
processors: | ||
|
||
exporters: | ||
prometheusremotewrite: | ||
endpoint: $PROMETHEUS_ENDPOINT_URL | ||
resource_to_telemetry_conversion: | ||
enabled: false | ||
auth: | ||
authenticator: sigv4auth | ||
logging: | ||
loglevel: info | ||
|
||
extensions: | ||
sigv4auth: | ||
region: $AWS_REGION | ||
service: aps | ||
assume_role: | ||
arn: $PROMETHEUS_WRITE_ASSUME_ROLE_ARN | ||
|
||
service: | ||
extensions: [sigv4auth] | ||
pipelines: | ||
metrics/application: | ||
receivers: [prometheus] | ||
exporters: [logging, prometheusremotewrite] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
version: "3" | ||
services: | ||
test-app: | ||
build: node_service/ | ||
expose: | ||
- 3000 | ||
ports: | ||
- 3000:3000 | ||
healthcheck: | ||
test: ["CMD", "wget", "-O", "/dev/null", "-q", "http://localhost:3000/metrics"] | ||
interval: 1s | ||
timeout: 10s | ||
retries: 30 | ||
|
||
adot-sidecar: | ||
build: ../. | ||
volumes: | ||
- "./test-config.yml:/etc/ecs/govuk-pay-adot-sidecar-config.yaml" | ||
depends_on: | ||
- prometheus | ||
- test-app | ||
environment: | ||
- APPLICATION_PORT=3000 | ||
- PROMETHEUS_REMOTE_WRITE_URL=http://prometheus:9090/api/v1/write | ||
|
||
prometheus: | ||
image: prom/prometheus:v2.45.0 | ||
expose: | ||
- 9090 | ||
ports: | ||
- 9090:9090 | ||
command: | ||
- --web.enable-remote-write-receiver | ||
- --config.file=/etc/prometheus/prometheus.yml | ||
healthcheck: | ||
test: ["CMD", "wget", "-O", "/dev/null", "-q", "http://localhost:9090/-/ready"] | ||
interval: 5s | ||
timeout: 10s | ||
retries: 30 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
FROM node:20-alpine | ||
|
||
RUN apk add --no-cache tini | ||
|
||
WORKDIR /app | ||
|
||
COPY package*.json ./ | ||
RUN npm ci --no-progress --omit=dev | ||
|
||
COPY ./index.mjs index.mjs | ||
|
||
EXPOSE 3000 | ||
|
||
ENTRYPOINT ["/sbin/tini", "--"] | ||
|
||
CMD ["node", "index.mjs"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { randomUUID } from 'crypto' | ||
import promClient from 'prom-client' | ||
import express from 'express' | ||
|
||
promClient.collectDefaultMetrics({ timeout: 10000 }) | ||
promClient.register.metrics().then(str => console.log('Metrics registered')) | ||
|
||
function defaultLabels() { | ||
return { | ||
ecsClusterName: "local-test", | ||
ecsServiceName: "test-node-app", | ||
awsAccountName: "local", | ||
} | ||
} | ||
|
||
try { | ||
promClient.register.setDefaultLabels(defaultLabels()); | ||
} catch (ex) { | ||
const labels = {} | ||
console.log(`Failed to get labels ${ex}`) | ||
} | ||
|
||
const counters = { | ||
index: new promClient.Counter({ | ||
name: 'page_count_index', | ||
help: 'Count of hits to the index page', | ||
}), | ||
foo: new promClient.Counter({ | ||
name: 'page_count_foo', | ||
help: 'Count of hits to the foo page', | ||
}), | ||
metrics: new promClient.Counter({ | ||
name: 'page_count_metrics', | ||
help: 'Count of hits to the metrics page', | ||
}), | ||
|
||
} | ||
|
||
const app = express() | ||
const port = 3000 | ||
|
||
app.get('/', (req, res) => { | ||
counters.index.inc() | ||
console.log('GET /') | ||
res.send('Hello World!') | ||
}) | ||
|
||
app.get('/foo', (req, res) => { | ||
counters.foo.inc() | ||
console.log('GET /foo') | ||
res.send('Foo woo hoo') | ||
}) | ||
|
||
app.get('/metrics', async (req, res) => { | ||
counters.metrics.inc() | ||
console.log('GET /metrics') | ||
try { | ||
res.set('Content-Type', promClient.register.contentType) | ||
const metrics = await promClient.register.metrics() | ||
res.end(metrics) | ||
} catch (ex) { | ||
res.status(500).end(ex) | ||
} | ||
}) | ||
|
||
app.listen(port, () => { | ||
console.log(`Example app listening on port ${port}`) | ||
}) |
Oops, something went wrong.