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

CONTAINER_NAME doesn't output the correct "io.kubernetes.container.name" label #336

Open
ankitdbst opened this issue May 19, 2022 · 2 comments

Comments

@ankitdbst
Copy link

With docker, the below daemon.json for journald:

{
    "log-driver": "journald",
    "log-opts": {
      "tag":"{{.ID}}",
      "labels": "io.kubernetes.container.name,io.kubernetes.pod.name"
    }
}

We can filter journalctl logs by IO_KUBERNETES_CONTAINER_NAME=<container-name>. Where container-name is the one defined in the k8s manifest.

      ...
      containers:
      - args:
        ...
        name: kafka

In crio, when logging to journald, the CONTAINER_NAME filter outputs the pod name instead along with some hash:

k8s_kafka_kafka-0_default_4067521d-941e-460a-b8c0-8ec98ecb9dd0_0

Is there a way to configure the fields we send to journald like docker does? So that we can have only kafka returned when doing the filter match?

@haircommander
Copy link
Collaborator

Thanks for giving CRI-O a try!

we don't currently support adding a label, so support for that would need to be added.

also, technically, from cri-o's perspective the container name is that whole string. Here's how that string is constructed:

    name := strings.Join([]string{                                                                                                                
        "k8s",                                                                                                                                    
        c.config.Metadata.Name,                                                                                                                   
        c.sboxConfig.Metadata.Name,                                                                                                               
        c.sboxConfig.Metadata.Namespace,                                                                                                          
        c.sboxConfig.Metadata.Uid,                                                                                                                
        fmt.Sprintf("%d", c.config.Metadata.Attempt),                                                                                             
    }, "_")                                                                                                                                       

I don't remember exactly why it's done this way.

What changes would be required to meet your use cases?

@ankitdbst
Copy link
Author

Thanks for the reply @haircommander

Yes, if we can provide a way to add the label like docker daemon.json it would be great.
Else if we can have another filter IO_KUBERNETES_CONTAINER_NAME with only the container name (c.config.Metadata.Name) then it would help filter logs with it.

Is there a way to plug your filters in before we send out to journald?

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

2 participants