I want to use the journald driver for logs, but it doesn't support opts like compress and max-size, what part specifically defines these values in Wings and sets them in the Wings config, and how can I make it skip any opt that is empty, e.g. ""?
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Okay, let's break down how Wings handles Docker logging configuration and how you can modify it to skip empty options.
Understanding the Configuration
The Docker logging configuration for Wings is primarily defined in the DockerConfiguration struct within the config/config_docker.go file. Here's the relevant part:
go
type DockerConfiguration struct {
// ... other fields ...
LogConfig struct {
Type string `default:"local" json:"type" yaml:"type"`
Config map[string]string `default:"{\"max-size\":\"5m\",\"max-file\":\"1\",\"compress\":\"false\",\"mode\":\"non-blocking\"}" json:"config" yaml:"config"`
} `json:"log_config" yaml:"log_config"`
}
LogConfig.Type: This string determines the Docker logging driver to use (e.g., "local", "journald", "json-file"). It defaults to "local".
LogConfig.Config: This is a map[string]string that holds the driver-specific options. The default values are set via the default: tag in the struct definition, {"max-size":"5m","max-file":"1","compress":"false","mode":"non-blocking"}.
How Wings Applies the Configuration
The ContainerLogConfig() method on DockerConfiguration is responsible for converting the stored configuration to a Docker-compatible structure. This method is defined within config/config_docker.go as well:
As you can see, it directly passes the LogConfig.Type and LogConfig.Config to container.LogConfig. It does not filter out empty options.
Modifying Wings to Skip Empty Options
To skip empty options, you'll need to modify the ContainerLogConfig function to filter empty values before passing the map to docker. Here's how you can do it:
go
func (c DockerConfiguration) ContainerLogConfig() container.LogConfig {
if c.LogConfig.Type == "" {
return container.LogConfig{}
}
config := make(map[string]string)
for k, v := range c.LogConfig.Config {
if v != "" {
config[k] = v
}
}
return container.LogConfig{
Type: c.LogConfig.Type,
Config: config,
}
}
Explanation of the changes:
Create a new map: a new config map is created before any iteration begins.
Iterate and filter: We iterate through the original c.LogConfig.Config map.
Check for empty values: inside the loop we check if the current value (v) is empty. If it's not empty, the key-value pair is added to the config map.
Return filtered map: the new config map is then passed to container.LogConfig
How to Apply the Changes
Locate the File: Find the config/config_docker.go file in your Wings repository.
Modify ContainerLogConfig(): Replace the original function with the updated code above.
Recompile Wings: You will need to recompile Wings using make build.
Configure Wings: You can now set the log_config.type to journald and provide other valid options to the log_config.config map in the config.yml file. For journald, valid options are documented in the docker docs. Any empty values defined in the configuration will not be passed to docker.
Example config.yml Configuration:
[Redacted
[Redacted Person]:
log_config:
type: "journald"
config:
# No options are needed for journald to use its defaults.
# This map can be empty.
Important Considerations:
Journald Driver: Be aware that the journald driver doesn't support options like max-size, max-file, or compress. These options are specific to other drivers like local. Setting them when using journald won't have any effect but will not cause errors either as any empty strings will be filtered.
Wings Updates: If you are not running a forked version of Wings, you should be prepared to re-apply this change if you update Wings in the future.
Testing: Thoroughly test your changes after modifying the ContainerLogConfig() function to ensure the logging functions as expected.
By implementing these modifications, you can ensure that Wings does not pass empty configuration options to the Docker API, which can lead to unexpected behavior. This also allows you to use the journald driver as you want.