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

filter.labels doesn't work in swarm #442

Open
erbrecht opened this issue Aug 14, 2019 · 1 comment
Open

filter.labels doesn't work in swarm #442

erbrecht opened this issue Aug 14, 2019 · 1 comment

Comments

@erbrecht
Copy link

I've been evaluating logspout and it has been meeting all my needs until now. I'm able to use filter.labels to only include logs from containers with certain labels. My next step was to try this out in swarm mode. It seems that labels in swarm mode apply to the service, not individual containers. I can inspect containers created by the docker stack deploy command, and they don't have the labels defined in my yml file. These are the labels I had been using in the filter.labels parameter. Those labels DO exist when I inspect the service created by docker stack deploy. Since my individual containers don't have these labels, I get not logs through logspout. If I remove the filter.labels parameter, I get logs from my containers, but the log entries don't include my custom labels either, only the labels the stack applies to the container.

Labels for a container running as part of a stack:

"Labels": {
  "com.docker.stack.namespace": "logspout",
  "com.docker.swarm.node.id": "r01ryq9ozir0ngzezpzyib4tm",
  "com.docker.swarm.service.id": "jvbmw62dkxk6oclt343aeg9ro",
  "com.docker.swarm.service.name": "logspout_logspout",
  "com.docker.swarm.task": "",
  "com.docker.swarm.task.id": "pg18eb97smkts4uaaozqkfq59",
  "com.docker.swarm.task.name": "logspout_logspout.1.pg18eb97smkts4uaaozqkfq59"
}

And labels for the service, which has the id in the com.docker.swarm.service.id label from above:

[
    {
        "ID": "jvbmw62dkxk6oclt343aeg9ro",
        "Version": {
            "Index": 1378
        },
        "CreatedAt": "2019-08-14T02:58:29.023517774Z",
        "UpdatedAt": "2019-08-14T02:58:29.027497629Z",
        "Spec": {
            "Name": "logspout_logspout",
            "Labels": {
                "com.docker.stack.image": "logspout-file:latest",
                "com.docker.stack.namespace": "logspout",
                "mylabel": "works",
                "myotherlabel": "really"
            }
...

A log entry from a (different) container showing just the com.docker.stack and com.docker.swarm labels:

{
  "container": "/log-test_echo.1.w78hfexf4l4g3lqmas90lrheo",
  "labels": {
    "com.docker.stack.namespace": "log-test",
    "com.docker.swarm.node.id": "r01ryq9ozir0ngzezpzyib4tm",
    "com.docker.swarm.service.id": "b5giiu2exm91gb2bclro3udle",
    "com.docker.swarm.service.name": "log-test_echo",
    "com.docker.swarm.task": "",
    "com.docker.swarm.task.id": "w78hfexf4l4g3lqmas90lrheo",
    "com.docker.swarm.task.name": "log-test_echo.1.w78hfexf4l4g3lqmas90lrheo"
  },
  "timestamp": "2019-08-14T03:46:18Z",
  "source": "stdout",
  "line": "log"
}

Is it possible to check labels for a given service, and filter container logs accordingly? I know that traefik relies heavily on labels, and it's able to detect when a service starts up with given labels. I know it's a different project, and different authors, but it's a similar situation in terms of dealing with swarm mode. Perhaps specifically telling logspout it is operating in a swarm so it knows to check for services instead of just containers? I would take a crack at it but I haven't wrapped my head around the code enough to know where to start.

@erbrecht
Copy link
Author

erbrecht commented Aug 17, 2019

I got this working locally and submitted a pull request, but it failed the circleci tests. The image was too large. From what I can tell it was about 62 MB. Building the image locally, using make build, created a 36 MB image. I did need to add an import for github.com/docker/docker/api/types/swarm into glide.yaml. I must be doing something wrong and it's a bit frustrating because other than the new dependency, I only modified 2 files. Did my changes really inflate the size that much, or am I missing something?

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

No branches or pull requests

1 participant