diff --git a/pkg/pillar/types/global.go b/pkg/pillar/types/global.go index ed7feec9e8..0c46553337 100644 --- a/pkg/pillar/types/global.go +++ b/pkg/pillar/types/global.go @@ -287,14 +287,18 @@ const ( ConsoleAccess GlobalSettingKey = "debug.enable.console" // Shim VM VNC access global setting key VncShimVMAccess GlobalSettingKey = "debug.enable.vnc.shim.vm" - // DefaultLogLevel global setting key + // DefaultLogLevel default level of logs produced by EVE microservices DefaultLogLevel GlobalSettingKey = "debug.default.loglevel" - // DefaultRemoteLogLevel global setting key + // DefaultRemoteLogLevel default level of logs sent by EVE microservices to the controller DefaultRemoteLogLevel GlobalSettingKey = "debug.default.remote.loglevel" - // SyslogLogLevel global setting key + // SyslogLogLevel level of the produced syslog messages SyslogLogLevel GlobalSettingKey = "debug.syslog.loglevel" - // KernelLogLevel global setting key + // SyslogRemoteLogLevel level of the syslog messages sent to the controller + SyslogRemoteLogLevel GlobalSettingKey = "debug.syslog.remote.loglevel" + // KernelLogLevel level of the produced kernel messages KernelLogLevel GlobalSettingKey = "debug.kernel.loglevel" + // KernelRemoteLogLevel level of the kernel messages sent to the controller + KernelRemoteLogLevel GlobalSettingKey = "debug.kernel.remote.loglevel" // FmlCustomResolution global setting key FmlCustomResolution GlobalSettingKey = "app.fml.resolution" @@ -380,17 +384,19 @@ var ( // SyslogKernelLogLevelNum is a number representation of syslog/kernel // loglevels. SyslogKernelLogLevelNum = map[string]uint32{ - "emerg": 0, - "alert": 1, - "crit": 2, - "critical": 2, - "err": 3, - "error": 3, - "warning": 4, - "warn": 4, - "notice": 5, - "info": 6, - "debug": 7, + "none": 0, + "emerg": 1, + "alert": 2, + "crit": 3, + "critical": 3, + "err": 4, + "error": 4, + "warning": 5, + "warn": 5, + "notice": 6, + "info": 7, + "debug": 8, + "all": 99, } // SyslogKernelDefaultLogLevel is a default loglevel for syslog and kernel. SyslogKernelDefaultLogLevel = "info" @@ -982,15 +988,17 @@ func NewConfigItemSpecMap() ConfigItemSpecMap { // Add String Items configItemSpecMap.AddStringItem(SSHAuthorizedKeys, "", blankValidator) - configItemSpecMap.AddStringItem(DefaultLogLevel, "info", validateLogrusLevel) - configItemSpecMap.AddStringItem(DefaultRemoteLogLevel, "info", validateLogrusLevel) + configItemSpecMap.AddStringItem(DefaultLogLevel, "info", validateLogLevel) + configItemSpecMap.AddStringItem(DefaultRemoteLogLevel, "info", validateLogLevel) configItemSpecMap.AddStringItem(SyslogLogLevel, "info", validateSyslogKernelLevel) configItemSpecMap.AddStringItem(KernelLogLevel, "info", validateSyslogKernelLevel) + configItemSpecMap.AddStringItem(SyslogRemoteLogLevel, "info", validateSyslogKernelLevel) + configItemSpecMap.AddStringItem(KernelRemoteLogLevel, "info", validateSyslogKernelLevel) configItemSpecMap.AddStringItem(FmlCustomResolution, FmlResolutionUnset, blankValidator) // Add Agent Settings - configItemSpecMap.AddAgentSettingStringItem(LogLevel, "info", validateLogrusLevel) - configItemSpecMap.AddAgentSettingStringItem(RemoteLogLevel, "info", validateLogrusLevel) + configItemSpecMap.AddAgentSettingStringItem(LogLevel, "info", validateLogLevel) + configItemSpecMap.AddAgentSettingStringItem(RemoteLogLevel, "info", validateLogLevel) // Add NetDump settings configItemSpecMap.AddBoolItem(NetDumpEnable, true) @@ -1003,10 +1011,15 @@ func NewConfigItemSpecMap() ConfigItemSpecMap { return configItemSpecMap } -// validateLogrusLevel - Wrapper for validating logrus loglevel -func validateLogrusLevel(level string) error { - _, err := logrus.ParseLevel(level) - return err +// validateLogLevel - make sure the log level has one of the supported values +func validateLogLevel(level string) error { + switch level { + case "none", "all": + return nil + default: + _, err := logrus.ParseLevel(level) + return err + } } // validateSyslogKernelLevel - Wrapper for validating syslog and kernel diff --git a/pkg/pillar/types/global_test.go b/pkg/pillar/types/global_test.go index 444b41917c..022c0a25d7 100644 --- a/pkg/pillar/types/global_test.go +++ b/pkg/pillar/types/global_test.go @@ -124,7 +124,7 @@ func TestAddStringItem(t *testing.T) { } for testname, test := range testMatrix { t.Logf("Running test case %s", testname) - (&specMap).AddStringItem(test.key, test.defaultString, validateLogrusLevel) + (&specMap).AddStringItem(test.key, test.defaultString, validateLogLevel) assert.Equal(t, test.expectedVal, specMap.GlobalSettings[test.key].StringDefault) } } @@ -204,7 +204,9 @@ func TestNewConfigItemSpecMap(t *testing.T) { SSHAuthorizedKeys, DefaultLogLevel, DefaultRemoteLogLevel, + SyslogRemoteLogLevel, SyslogLogLevel, + KernelRemoteLogLevel, KernelLogLevel, FmlCustomResolution, DisableDHCPAllOnesNetMask, diff --git a/pkg/pillar/types/newlogtypes.go b/pkg/pillar/types/newlogtypes.go index 6813b884b5..05e0022894 100644 --- a/pkg/pillar/types/newlogtypes.go +++ b/pkg/pillar/types/newlogtypes.go @@ -4,12 +4,19 @@ package types import ( + "fmt" + "strconv" + "strings" "time" ) const ( - // DevPrefix - device log file prefix string + // DevPrefix - general file prefix string for device log files DevPrefix = "dev.log." + // DevPrefixUpload - file prefix string for device log files to upload + DevPrefixUpload = "dev.log.upload." + // DevPrefixKeep - file prefix string for device log files to keep on device + DevPrefixKeep = "dev.log.keep." // AppPrefix - app log file prefix string AppPrefix = "app." // AppSuffix - app log file suffix string, the appuuid is between the AppPrefix and AppSuffix @@ -65,6 +72,8 @@ type NewlogMetrics struct { NumKmessages uint64 // total input kmessages NumSyslogMessages uint64 // total input syslog message DevTop10InputBytesPCT map[string]uint32 // top 10 sources device log input in percentage + TotalSizeLogs uint64 // total size of logs on device + OldestSavedDeviceLog time.Time // timestamp of the latest device log saved on device // upload latency Latency cloudDelay @@ -75,3 +84,22 @@ type NewlogMetrics struct { DevMetrics logfileMetrics // Device metrics AppMetrics logfileMetrics // App metrics } + +// GetTimestampFromGzipName - get timestamp from gzip file name +func GetTimestampFromGzipName(fName string) (time.Time, error) { + // here are example file names: + // app.6656f860-7563-4bbf-8bba-051f5942982b.log.1730464687367.gz + // dev.log.keep.1730404601953.gz + // dev.log.upload.1730404601953.gz + // the timestamp is the number between the last two dots + nameParts := strings.Split(fName, ".") + if len(nameParts) < 2 { + return time.Time{}, fmt.Errorf("getTimestampFromGzipName: invalid log file name %s", fName) + } + timeStr := nameParts[len(nameParts)-2] + fTime, err := strconv.Atoi(timeStr) + if err != nil { + return time.Time{}, fmt.Errorf("getTimestampFromGzipName: %w", err) + } + return time.Unix(0, int64(fTime)*int64(time.Millisecond)), nil +}