Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapping error with Docker Swarm labels #6421

Closed
exekias opened this issue Feb 20, 2018 · 1 comment
Closed

Mapping error with Docker Swarm labels #6421

exekias opened this issue Feb 20, 2018 · 1 comment
Assignees

Comments

@exekias
Copy link
Contributor

exekias commented Feb 20, 2018

Both when using add_docker_metadata and Docker autodiscover provider with Docker Swarm, in some cases we see mapping issues due to this labels set:

  "com.docker.swarm.task": "",
  "com.docker.swarm.task.id": "xxxxx",
  "com.docker.swarm.task.name": "xxxxx"

We should offer a way to "dedot" label names, or have an alternative way to detect the situation and avoid mapping errors.

Reference in discuss: https://discuss.elastic.co/t/using-autodiscover-feature-for-docker-does-not-work-when-running-in-swarm-mode/120342

Current workaround is to use drop_field processor like this:

processors:
  - drop_fields:
      fields:
        - "docker.containers.labels.com.docker.swarm.task"
@exekias exekias self-assigned this Feb 20, 2018
exekias pushed a commit to exekias/beats that referenced this issue Feb 25, 2018
This method implements a way to put dotted keys into a MapStr while
ensuring they don't override each other. For example:

```
  a := MapStr{}
  a.Put("com.docker.swarm.task", "x")
  a.Put("com.docker.swarm.task.id", 1)
  a.Put("com.docker.swarm.task.name", "foobar")
```

Will result in `{"com":{"docker":{"swarm":{"task":"x"}}}}`

DeDotPut detects this scenario and renames the common base key, by appending
`.value`:

```
 a := MapStr{}
 safemapstr.Put(a, "com.docker.swarm.task", "x")
 safemapstr.Put(a, "com.docker.swarm.task.id", 1)
 safemapstr.Put(a, "com.docker.swarm.task.name", "foobar")
```

Will result in `{"com":{"docker":{"swarm":{"task":{"id":1,"name":"foobar","value":"x"}}}}}`

The plan is to use this method to convert all unstructured external data, like labels, annotations and so

Related to elastic#6421
andrewkroh pushed a commit that referenced this issue Mar 12, 2018
* Add `safemapstr` to provide `Put`:

This method implements a way to put dotted keys into a MapStr while
ensuring they don't override each other. For example:

```
  a := MapStr{}
  a.Put("com.docker.swarm.task", "x")
  a.Put("com.docker.swarm.task.id", 1)
  a.Put("com.docker.swarm.task.name", "foobar")
```

Will result in `{"com":{"docker":{"swarm":{"task":"x"}}}}`

DeDotPut detects this scenario and renames the common base key, by appending
`.value`:

```
 a := MapStr{}
 safemapstr.Put(a, "com.docker.swarm.task", "x")
 safemapstr.Put(a, "com.docker.swarm.task.id", 1)
 safemapstr.Put(a, "com.docker.swarm.task.name", "foobar")
```

Will result in `{"com":{"docker":{"swarm":{"task":{"id":1,"name":"foobar","value":"x"}}}}}`

The plan is to use this method to convert all unstructured external data, like labels, annotations and so

Related to #6421

* Apply some review comments

* Use tryToMapStr when checking leaf node
@exekias
Copy link
Contributor Author

exekias commented May 9, 2018

This was fixed by #6434

@exekias exekias closed this as completed May 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant