Hashicorp Nomad: Docker Plugin, Fluentd

plugin "docker" {
  config {
 
    extra_labels = ["job_name", "job_id", "task_group_name", "task_name", "namespace", "node_name", "node_id"]
 
    logging {
      type = "fluentd"
      config {
        fluentd-address = "localhost:24224"
        tag = "tag"
        labels = "job_name,job_id,task_group_name,task_name,namespace,node_name,node_id"
      }
    }
}
}

The above is part of my client agent configuration in nomad for configuring the docker plugin. For some reason, only the logs are sent and no nomad metadata.

But the following task specification in my nomad config file works just fine. The logs are sent with nomad metadata.

task "..." {
      driver = "docker"
      config {
        image = "..."
        args  = ["--loglevel", "debug"]
        ports = ["https"]
 
        labels {
          job_name        = "${NOMAD_JOB_NAME}"
          job_id          = "${NOMAD_JOB_ID}"
          task_group_name = "${NOMAD_GROUP_NAME}"
          task_name       = "${NOMAD_TASK_NAME}"
          namespace       = "${NOMAD_NAMESPACE}"
          node_name       = "${node.unique.name}"
          node_id         = "${node.unique.id}"
        }
 
        logging {
          type = "fluentd"
          config {
            fluentd-address = "localhost:24224"
            tag             = "tag"
            labels          = "job_name,job_id,task_group_name,task_name,namespace,node_name,node_id"
          }
        }
      }
}

Both of them send logs to the same fluentd with the same fluentd config.

Can anybody help and tell me what I need to change so the plugin approach works?

Thank you!

I know this thread is old, but I just had the same issue. It seems labels are not correctly propagated when using the global extra_labels config. But I worked arround it by passing env, like

plugin "docker" {
  config {
    disable_log_collection = true
    logging {
      type = "fluentd"
      config {
        # Send logs to a local fluentd service, running on port 4224
        fluentd-address = "127.0.0.1:4224"
        fluentd-async = true
        # This is important for the fluentd service to access the metadata
        env = "NOMAD_JOB_NAME,NOMAD_GROUP_NAME,NOMAD_DC,NOMAD_REGION,NOMAD_TASK_NAME,NOMAD_ALLOC_INDEX,NOMAD_ALLOC_ID,NOMAD_NAMESPACE"
      }
    }
  }
}

setting labels to:

labels = "com.hashicorp.nomad.alloc_id,com.hashicorp.nomad.job_id,com.hashicorp.nomad.job_name,com.hashicorp.nomad.namespace,com.hashicorp.nomad.node_id,com.hashicorp.nomad.node_name,com.hashicorp.nomad.task_group_name,com.hashicorp.nomad.task_name"

worked for me.

1 Like

You’re right, I should have looked closer to a docker inspect output. The labels are simply prefixed with com.hashicorp.nomad. Thanks for the tip !

1 Like

This topic was automatically closed 62 days after the last reply. New replies are no longer allowed.