mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-09-12 12:36:56 +00:00
2462 debugging logs (#830)
* [refactoring] simplify method and make it more efficient
Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>
* [WIP] Introduce `logs` command to collects logs from various places
Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>
* Handle globs properly and merge default logs with user provided ones
Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>
* Change default logs location to be the current directory
Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>
* Skip new field in the schema tests
TODO: Update the schema and re-enable
Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>
* Remove test focus
Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>
* Add more default services
Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>
* Don't try to run journactl on non systemd distros
Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>
* Add more files (for openrc)
c6fdf6ee67/pkg/bundled/cloudconfigs/09_openrc_services.yaml (L52)
Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>
* Use standard library for globbing
Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>
* Capture all files under `/var/log`
because there is also k3s.log (maybe also k0s) etc. Better have them all
than missing some.
Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>
---------
Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>
This commit is contained in:
committed by
GitHub
parent
41b52e9970
commit
d85d7985fe
45
main.go
45
main.go
@@ -1075,6 +1075,46 @@ The validate command expects a configuration file as its only argument. Local fi
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "logs",
|
||||
Usage: "Collect logs from the system",
|
||||
Description: `Collect logs from various sources on the Kairos system and create a compressed tarball.
|
||||
|
||||
The command will collect logs from:
|
||||
- Journal logs from specified services (default: kairos-agent, systemd, k3s)
|
||||
- Log files from specified paths with globbing support
|
||||
|
||||
Configuration can be provided in the Kairos config file under the 'logs' section:
|
||||
|
||||
logs:
|
||||
journal:
|
||||
- myservice
|
||||
- myotherservice
|
||||
files:
|
||||
- /var/log/mybinary/*
|
||||
- /var/log/something.log
|
||||
|
||||
The output will be a tarball with logs organized by type (journal/, files/).`,
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "output",
|
||||
Usage: "Output path for the logs tarball",
|
||||
Value: "./kairos-logs.tar.gz",
|
||||
Aliases: []string{"o"},
|
||||
},
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
outputPath := c.String("output")
|
||||
|
||||
// Get the filesystem and runner from the config
|
||||
cfg, err := agentConfig.Scan(collector.Directories(constants.GetUserConfigDirs()...), collector.NoLogs)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to scan config: %w", err)
|
||||
}
|
||||
|
||||
return agent.ExecuteLogsCommand(cfg.Fs, cfg.Logger, cfg.Runner, outputPath)
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func main() {
|
||||
@@ -1230,11 +1270,10 @@ func moreThanOneEnabled(bools ...bool) bool {
|
||||
}
|
||||
|
||||
func noneOfEnabled(bools ...bool) bool {
|
||||
count := 0
|
||||
for _, b := range bools {
|
||||
if b {
|
||||
count++
|
||||
return false // Found at least one true, so not "none of enabled"
|
||||
}
|
||||
}
|
||||
return count == 0
|
||||
return true // No true values found, so "none of enabled"
|
||||
}
|
||||
|
Reference in New Issue
Block a user