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

[conmon] pass custom --log-opt #10694

Closed
tobwen opened this issue Jun 16, 2021 · 10 comments
Closed

[conmon] pass custom --log-opt #10694

tobwen opened this issue Jun 16, 2021 · 10 comments
Labels
kind/feature Categorizes issue or PR as related to a new feature. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.

Comments

@tobwen
Copy link
Contributor

tobwen commented Jun 16, 2021

/kind feature

Description
It would be nice to pass custom --log-opt to conmon. That way, I could finish containers/conmon#273

Example

--log-opt="message-prefix={{.Name}}[{{.Tag}}]"
or
--log-opt="message-prefix=podman-nginx[test-build-20210706]"

to get

Jun 7 00:00:00 debian conmon[666]: podman-nginx[test-build-20210706] message
@openshift-ci openshift-ci bot added the kind/feature Categorizes issue or PR as related to a new feature. label Jun 16, 2021
@haircommander
Copy link
Collaborator

would you be interested in submitting a patch :)

@tobwen
Copy link
Contributor Author

tobwen commented Jun 16, 2021

would you be interested in submitting a patch :)

Trust me, you really don't want me to mess around in GO. But I can give it a try.

@tobwen
Copy link
Contributor Author

tobwen commented Jun 16, 2021

Okay, here we go... WIP

https://github.com/containers/podman/blob/master/pkg/bindings/containers/types.go#L13

type LogOptions struct {
        Follow     *bool
        PrefixMsg  *string // new, to prefix a string (e.g. a name, an ID or anything else) to the message
        Since      *string
        Stderr     *bool
        Stdout     *bool
        Tail       *string
        Timestamps *bool
        Until      *string
}

https://github.com/containers/podman/blob/master/cmd/podman/common/specgen.go#L593

	logOpts := make(map[string]string)
	for _, o := range c.LogOptions {
		split := strings.SplitN(o, "=", 2)
		if len(split) < 2 {
			return errors.Errorf("invalid log option %q", o)
		}
		switch strings.ToLower(split[0]) {
		case "driver":
			s.LogConfiguration.Driver = split[1]
		case "path":
			s.LogConfiguration.Path = split[1]
		case "prefixmsg":
			s.LogConfiguration.PrefixMsg = split[1]
		case "max-size":
			logSize, err := units.FromHumanSize(split[1])
			if err != nil {
				return err
			}
			s.LogConfiguration.Size = logSize
		default:
			logOpts[split[0]] = split[1]
		}
	}

https://github.com/containers/podman/blob/master/pkg/specgen/specgen.go#L13

//  LogConfig describes the logging characteristics for a container
type LogConfig struct
	// LogDriver is the container's log driver.
	// Optional.
	Driver string `json:"driver,omitempty"`
	// LogPath is the path the container's logs will be stored at.
	// Only available if LogDriver is set to "json-file" or "k8s-file".
	// Optional.
	Path string `json:"path,omitempty"`
	// Prefix a string (e.g. a name, an ID or anything else) to the message
	// Optional.
	PrefixMsg string `json:"prefixmsg,omitempty"`
	// Size is the maximum size of the log file
	// Optional.
	Size int64 `json:"size,omitempty"`
	// A set of options to accompany the log driver.
	// Optional.
	Options map[string]string `json:"options,omitempty"`
}

@haircommander PTAL
Which name would be "nice" and "compatible"?

@tobwen
Copy link
Contributor Author

tobwen commented Jun 16, 2021

Sorry, I'm stuck here. Maybe I'll make it an environment variable for conmon or just apply the changes to my own builds.

@rhatdan
Copy link
Member

rhatdan commented Jun 16, 2021

Isn't this what tag does?

man podman run
...
   --log-opt=name=value
       Logging driver specific options.

       Set custom logging configuration. The following *name*s are supported:

       path: specify a path to the log file
           (e.g. --log-opt path=/var/log/container/mycontainer.json);

       max-size: specify a max size of the log file
           (e.g. --log-opt max-size=10mb);

       tag: specify a custom log tag for the container
          (e.g. --log-opt tag="{{.ImageName}}".

@tobwen
Copy link
Contributor Author

tobwen commented Jun 16, 2021

Isn't this what tag does?

No, see my report on conmon. The tag ends up in a journald variable, which is pretty costly to extract (see rsyslog docs on their journald module for example).

My approach just prefixes the important stuff to the syslog message, which is processed by default and at high performance.

But I am making use of the tag, of course. All that is missing is a switch to change the behavior to not break default logging (see the PR in conmon).

@mheon
Copy link
Member

mheon commented Jun 16, 2021

Passing new log options is pretty cheap on the Podman side, so long as Conmon is capable of interpreting them correctly (that would be a @haircommander question)

@tobwen
Copy link
Contributor Author

tobwen commented Jun 17, 2021

Passing new log options is pretty cheap on the Podman side, so long as Conmon is capable of interpreting them correctly (that would be a @haircommander question)

Pretty cheap for someone who's into it :-) I'd extent Conmon of course. But I wanted to check if it's possible to get a podmon switch at all. Without it, I would only patch it for my own use (because nobody else would be able to access it).

@tobwen
Copy link
Contributor Author

tobwen commented Jun 17, 2021

@mheon
Could you guide me, how to integrate new log options (as you can see, I already tried) Then I could finish it and present it to you.

@tobwen
Copy link
Contributor Author

tobwen commented Jun 18, 2021

Implementation is too complicated and the audience is too little. Closing.

@tobwen tobwen closed this as completed Jun 18, 2021
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 21, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/feature Categorizes issue or PR as related to a new feature. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

No branches or pull requests

4 participants