Skip to content
This repository has been archived by the owner on Jan 23, 2024. It is now read-only.

Add apm-server-proxy (WIP) #565

Closed
wants to merge 3 commits into from
Closed

Add apm-server-proxy (WIP) #565

wants to merge 3 commits into from

Conversation

sorenlouv
Copy link
Member

@sorenlouv sorenlouv commented Jul 26, 2019

This adds a service that replaces apm server for testing purposes. Any data sent to apm server will be written to file. This file can later be used to replay event duration test scenarios.

  1. Generate normal docker-compose.json file
./scripts/compose.py start master --all --docker-compose-path - > apm-server-proxied.json
  1. In apm-server-proxied.json overwrite apm-server with the following and replace apm-server with apm-server-proxy everywhere:
    "apm-server-proxy": {
      "build": {
        "context": "docker/apm-server-proxy",
        "dockerfile": "Dockerfile"
      },
      "volumes": [
        "./docker/apm-server-proxy/shared-volume:/usr/app/shared-volume"
      ],
      "command": "npm start",
      "ports": ["127.0.0.1:8200:8200"],
      "environment": [
        "ELASTIC_APM_SERVER_HOST=apm-server-proxy",
        "ELASTIC_APM_SERVER_PORT=8200"
      ],
      "healthcheck": {
        "interval": "10s",
        "retries": 36,
        "test": [
          "CMD",
          "curl",
          "--write-out",
          "'HTTP %{http_code}'",
          "--fail",
          "--silent",
          "--output",
          "/dev/null",
          "http://apm-server-proxy:8200/"
        ]
      }
    },
  1. Build and run the image
docker-compose -f apm-server-proxied.json build && docker-compose -f apm-server-proxied.json up

const payloads = [];

app.post('/intake/v2/events', (req, res) => {
console.log('Endpoint: /intake/v2/events');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

console.log statements should be removed during testing. This is only needed for debugging purposes during development


const payloads = [];

app.post('/intake/v2/events', (req, res) => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of listening on a single endpoint we can also listen for all endpoints:

app.post('*', ...)

and write that to file containing the endpoint.

"start": "node server.js"
},
"dependencies": {
"axios": "^0.19.0",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self: axios is no longer neeeded

@sorenlouv
Copy link
Member Author

sorenlouv commented Jul 26, 2019

An example of how events can be replayed from file:

async function init() {
  const content = await readFile('./shared-volume/events.json');
  const items = JSON.parse(content.toString());

  for await (let item of items) {
    try {
      await axios({
        method: 'post',
        url: `http://${APM_SERVER_HOST}:${APM_SERVER_PORT}/intake/v2/events`,
        headers: { 'content-type': 'application/x-ndjson' },
        data: item
      });
    } catch (e) {
      console.log(e.response.data);
    }
  }
}

@v1v
Copy link
Member

v1v commented Jul 30, 2019

I just pushed 953e691 to fix the lint defects which were detected in the CI:

[2019-07-30T04:52:08.239Z] Fix End of Files................................................................................Failed
[2019-07-30T04:52:08.239Z] hookid: end-of-file-fixer
[2019-07-30T04:52:08.239Z] 
[2019-07-30T04:52:08.239Z] Files were modified by this hook. Additional output:
[2019-07-30T04:52:08.239Z] 
[2019-07-30T04:52:08.239Z] Fixing docker/apm-server-proxy/Dockerfile

@sorenlouv
Copy link
Member Author

Closing in favor of #567

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants