diff --git a/pkg/status/render/fixtures/check_stats.json b/pkg/status/render/fixtures/check_stats.json new file mode 100644 index 0000000000000..ab6a327cef73e --- /dev/null +++ b/pkg/status/render/fixtures/check_stats.json @@ -0,0 +1,539 @@ +{ + "pyLoaderStats": { + "ConfigureErrors": {}, + "Py3Warnings": {} + }, + "pythonInit": { + "Errors": [ + "could not initialize rtloader: error initializing string utils: No module named 'yaml'" + ] + }, + "python_version": "n/a", + "remoteConfiguration": { + "apiKeyScoped": "false", + "lastError": "", + "orgEnabled": "false" + }, + "runnerStats": { + "Checks": { + "cpu": { + "cpu": { + "AverageExecutionTime": 0, + "CheckConfigSource": "file:/opt/datadog-agent/etc/conf.d/cpu.d/conf.yaml.default", + "CheckID": "cpu", + "CheckName": "cpu", + "CheckVersion": "", + "EventPlatformEvents": {}, + "Events": 0, + "ExecutionTimes": [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 0, + 0, + 0, + 0, + 0 + ], + "HistogramBuckets": 0, + "LastError": "", + "LastExecutionTime": 0, + "LastSuccessDate": 1701259541, + "LastWarnings": [], + "MetricSamples": 8, + "ServiceChecks": 0, + "TotalErrors": 0, + "TotalEventPlatformEvents": {}, + "TotalEvents": 0, + "TotalHistogramBuckets": 0, + "TotalMetricSamples": 985, + "TotalRuns": 124, + "TotalServiceChecks": 0, + "TotalWarnings": 0, + "UpdateTimestamp": 1701259541 + } + }, + "disk": { + "disk": { + "AverageExecutionTime": 1, + "CheckConfigSource": "file:/opt/datadog-agent/etc/conf.d/disk.d/conf.yaml.default", + "CheckID": "disk", + "CheckName": "disk", + "CheckVersion": "", + "EventPlatformEvents": {}, + "Events": 0, + "ExecutionTimes": [ + 0, + 2, + 0, + 0, + 4, + 1, + 1, + 1, + 2, + 1, + 4, + 1, + 1, + 2, + 3, + 1, + 2, + 1, + 1, + 0, + 2, + 2, + 4, + 2, + 3, + 1, + 2, + 2, + 2, + 2, + 2, + 1 + ], + "HistogramBuckets": 0, + "LastError": "", + "LastExecutionTime": 2, + "LastSuccessDate": 1701259533, + "LastWarnings": [], + "MetricSamples": 84, + "ServiceChecks": 0, + "TotalErrors": 0, + "TotalEventPlatformEvents": {}, + "TotalEvents": 0, + "TotalHistogramBuckets": 0, + "TotalMetricSamples": 10332, + "TotalRuns": 123, + "TotalServiceChecks": 0, + "TotalWarnings": 0, + "UpdateTimestamp": 1701259533 + } + }, + "file_handle": { + "file_handle": { + "AverageExecutionTime": 0, + "CheckConfigSource": "file:/Users/gustavo.caso/go/src/github.com/DataDog/datadog-agent/bin/agent/dist/conf.d/file_handle.d/conf.yaml.default", + "CheckID": "file_handle", + "CheckName": "file_handle", + "CheckVersion": "", + "EventPlatformEvents": {}, + "Events": 0, + "ExecutionTimes": [ + 0, + 0, + 1, + 0, + 1, + 0, + 0, + 1, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 1, + 0, + 0, + 5, + 0, + 1, + 0, + 0, + 0, + 1, + 0, + 1, + 2, + 1, + 0, + 0 + ], + "HistogramBuckets": 0, + "LastError": "open /proc/sys/fs/file-nr: no such file or directory", + "LastExecutionTime": 0, + "LastSuccessDate": 0, + "LastWarnings": [], + "MetricSamples": 0, + "ServiceChecks": 0, + "TotalErrors": 123, + "TotalEventPlatformEvents": {}, + "TotalEvents": 0, + "TotalHistogramBuckets": 0, + "TotalMetricSamples": 0, + "TotalRuns": 123, + "TotalServiceChecks": 0, + "TotalWarnings": 0, + "UpdateTimestamp": 1701259538 + } + }, + "io": { + "io": { + "AverageExecutionTime": 0, + "CheckConfigSource": "file:/opt/datadog-agent/etc/conf.d/io.d/conf.yaml.default", + "CheckID": "io", + "CheckName": "io", + "CheckVersion": "", + "EventPlatformEvents": {}, + "Events": 0, + "ExecutionTimes": [ + 1, + 1, + 0, + 0, + 1, + 1, + 1, + 1, + 2, + 1, + 1, + 1, + 0, + 0, + 0, + 0, + 1, + 0, + 1, + 0, + 1, + 0, + 0, + 4, + 1, + 0, + 1, + 1, + 0, + 1, + 1, + 1 + ], + "HistogramBuckets": 0, + "LastError": "", + "LastExecutionTime": 1, + "LastSuccessDate": 1701259540, + "LastWarnings": [], + "MetricSamples": 15, + "ServiceChecks": 0, + "TotalErrors": 0, + "TotalEventPlatformEvents": {}, + "TotalEvents": 0, + "TotalHistogramBuckets": 0, + "TotalMetricSamples": 1836, + "TotalRuns": 123, + "TotalServiceChecks": 0, + "TotalWarnings": 0, + "UpdateTimestamp": 1701259540 + } + }, + "load": { + "load": { + "AverageExecutionTime": 0, + "CheckConfigSource": "file:/opt/datadog-agent/etc/conf.d/load.d/conf.yaml.default", + "CheckID": "load", + "CheckName": "load", + "CheckVersion": "", + "EventPlatformEvents": {}, + "Events": 0, + "ExecutionTimes": [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ], + "HistogramBuckets": 0, + "LastError": "", + "LastExecutionTime": 0, + "LastSuccessDate": 1701259532, + "LastWarnings": [], + "MetricSamples": 6, + "ServiceChecks": 0, + "TotalErrors": 0, + "TotalEventPlatformEvents": {}, + "TotalEvents": 0, + "TotalHistogramBuckets": 0, + "TotalMetricSamples": 738, + "TotalRuns": 123, + "TotalServiceChecks": 0, + "TotalWarnings": 0, + "UpdateTimestamp": 1701259532 + } + }, + "memory": { + "memory": { + "AverageExecutionTime": 0, + "CheckConfigSource": "file:/opt/datadog-agent/etc/conf.d/memory.d/conf.yaml.default", + "CheckID": "memory", + "CheckName": "memory", + "CheckVersion": "", + "EventPlatformEvents": {}, + "Events": 0, + "ExecutionTimes": [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 0, + 0, + 1, + 0, + 0, + 0, + 0 + ], + "HistogramBuckets": 0, + "LastError": "", + "LastExecutionTime": 0, + "LastSuccessDate": 1701259539, + "LastWarnings": [], + "MetricSamples": 11, + "ServiceChecks": 0, + "TotalErrors": 0, + "TotalEventPlatformEvents": {}, + "TotalEvents": 0, + "TotalHistogramBuckets": 0, + "TotalMetricSamples": 1353, + "TotalRuns": 123, + "TotalServiceChecks": 0, + "TotalWarnings": 0, + "UpdateTimestamp": 1701259539 + } + }, + "ntp": { + "ntp:3c427a42a70bbf8": { + "AverageExecutionTime": 172, + "CheckConfigSource": "file:/opt/datadog-agent/etc/conf.d/ntp.d/conf.yaml.default", + "CheckID": "ntp:3c427a42a70bbf8", + "CheckName": "ntp", + "CheckVersion": "", + "EventPlatformEvents": {}, + "Events": 0, + "ExecutionTimes": [ + 143, + 187, + 186, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ], + "HistogramBuckets": 0, + "LastError": "", + "LastExecutionTime": 186, + "LastSuccessDate": 1701259498, + "LastWarnings": [], + "MetricSamples": 1, + "ServiceChecks": 1, + "TotalErrors": 0, + "TotalEventPlatformEvents": {}, + "TotalEvents": 0, + "TotalHistogramBuckets": 0, + "TotalMetricSamples": 3, + "TotalRuns": 3, + "TotalServiceChecks": 3, + "TotalWarnings": 0, + "UpdateTimestamp": 1701259498 + } + }, + "uptime": { + "uptime": { + "AverageExecutionTime": 0, + "CheckConfigSource": "file:/opt/datadog-agent/etc/conf.d/uptime.d/conf.yaml.default", + "CheckID": "uptime", + "CheckName": "uptime", + "CheckVersion": "", + "EventPlatformEvents": {}, + "Events": 0, + "ExecutionTimes": [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ], + "HistogramBuckets": 0, + "LastError": "", + "LastExecutionTime": 0, + "LastSuccessDate": 1701259546, + "LastWarnings": [], + "MetricSamples": 1, + "ServiceChecks": 0, + "TotalErrors": 0, + "TotalEventPlatformEvents": {}, + "TotalEvents": 0, + "TotalHistogramBuckets": 0, + "TotalMetricSamples": 124, + "TotalRuns": 124, + "TotalServiceChecks": 0, + "TotalWarnings": 0, + "UpdateTimestamp": 1701259546 + } + } + }, + "Errors": 123, + "Running": { + "container_image": "2023-11-29T12:34:55+01:00", + "container_lifecycle": "2023-11-29T12:34:55+01:00" + }, + "RunningChecks": 2, + "Runs": 866, + "Workers": { + "Count": 6, + "Instances": { + "worker_1": { + "Utilization": 1 + }, + "worker_2": { + "Utilization": 1 + }, + "worker_3": { + "Utilization": 0 + }, + "worker_4": { + "Utilization": 0 + }, + "worker_5": { + "Utilization": 0 + }, + "worker_6": { + "Utilization": 0 + } + } + } + } +} diff --git a/pkg/status/render/fixtures/check_stats.text b/pkg/status/render/fixtures/check_stats.text new file mode 100755 index 0000000000000..c7cf3e7084b9c --- /dev/null +++ b/pkg/status/render/fixtures/check_stats.text @@ -0,0 +1,115 @@ +========= +Collector +========= + Error initializing Python + ========================= + - could not initialize rtloader: error initializing string utils: No module named 'yaml' + + + Running Checks + ============== + + cpu + --- + Instance ID: cpu [OK] + Configuration Source: file:/opt/datadog-agent/etc/conf.d/cpu.d/conf.yaml.default + Total Runs: 124 + Metric Samples: Last Run: 8, Total: 985 + Events: Last Run: 0, Total: 0 + Service Checks: Last Run: 0, Total: 0 + Average Execution Time : 0s + Last Execution Date : 2023-11-29 12:05:41 UTC (1701259541000) + Last Successful Execution Date : 2023-11-29 12:05:41 UTC (1701259541000) + + + disk + ---- + Instance ID: disk [OK] + Configuration Source: file:/opt/datadog-agent/etc/conf.d/disk.d/conf.yaml.default + Total Runs: 123 + Metric Samples: Last Run: 84, Total: 10,332 + Events: Last Run: 0, Total: 0 + Service Checks: Last Run: 0, Total: 0 + Average Execution Time : 1ms + Last Execution Date : 2023-11-29 12:05:33 UTC (1701259533000) + Last Successful Execution Date : 2023-11-29 12:05:33 UTC (1701259533000) + + + file_handle + ----------- + Instance ID: file_handle [ERROR] + Configuration Source: file:/Users/gustavo.caso/go/src/github.com/DataDog/datadog-agent/bin/agent/dist/conf.d/file_handle.d/conf.yaml.default + Total Runs: 123 + Metric Samples: Last Run: 0, Total: 0 + Events: Last Run: 0, Total: 0 + Service Checks: Last Run: 0, Total: 0 + Average Execution Time : 0s + Last Execution Date : 2023-11-29 12:05:38 UTC (1701259538000) + Last Successful Execution Date : Never + Error: open /proc/sys/fs/file-nr: no such file or directory + No traceback + + io + -- + Instance ID: io [OK] + Configuration Source: file:/opt/datadog-agent/etc/conf.d/io.d/conf.yaml.default + Total Runs: 123 + Metric Samples: Last Run: 15, Total: 1,836 + Events: Last Run: 0, Total: 0 + Service Checks: Last Run: 0, Total: 0 + Average Execution Time : 0s + Last Execution Date : 2023-11-29 12:05:40 UTC (1701259540000) + Last Successful Execution Date : 2023-11-29 12:05:40 UTC (1701259540000) + + + load + ---- + Instance ID: load [OK] + Configuration Source: file:/opt/datadog-agent/etc/conf.d/load.d/conf.yaml.default + Total Runs: 123 + Metric Samples: Last Run: 6, Total: 738 + Events: Last Run: 0, Total: 0 + Service Checks: Last Run: 0, Total: 0 + Average Execution Time : 0s + Last Execution Date : 2023-11-29 12:05:32 UTC (1701259532000) + Last Successful Execution Date : 2023-11-29 12:05:32 UTC (1701259532000) + + + memory + ------ + Instance ID: memory [OK] + Configuration Source: file:/opt/datadog-agent/etc/conf.d/memory.d/conf.yaml.default + Total Runs: 123 + Metric Samples: Last Run: 11, Total: 1,353 + Events: Last Run: 0, Total: 0 + Service Checks: Last Run: 0, Total: 0 + Average Execution Time : 0s + Last Execution Date : 2023-11-29 12:05:39 UTC (1701259539000) + Last Successful Execution Date : 2023-11-29 12:05:39 UTC (1701259539000) + + + ntp + --- + Instance ID: ntp:3c427a42a70bbf8 [OK] + Configuration Source: file:/opt/datadog-agent/etc/conf.d/ntp.d/conf.yaml.default + Total Runs: 3 + Metric Samples: Last Run: 1, Total: 3 + Events: Last Run: 0, Total: 0 + Service Checks: Last Run: 1, Total: 3 + Average Execution Time : 172ms + Last Execution Date : 2023-11-29 12:04:58 UTC (1701259498000) + Last Successful Execution Date : 2023-11-29 12:04:58 UTC (1701259498000) + + + uptime + ------ + Instance ID: uptime [OK] + Configuration Source: file:/opt/datadog-agent/etc/conf.d/uptime.d/conf.yaml.default + Total Runs: 124 + Metric Samples: Last Run: 1, Total: 124 + Events: Last Run: 0, Total: 0 + Service Checks: Last Run: 0, Total: 0 + Average Execution Time : 0s + Last Execution Date : 2023-11-29 12:05:46 UTC (1701259546000) + Last Successful Execution Date : 2023-11-29 12:05:46 UTC (1701259546000) + diff --git a/pkg/status/render/render_test.go b/pkg/status/render/render_test.go index 1689c31382e2b..9936e85ea21e5 100644 --- a/pkg/status/render/render_test.go +++ b/pkg/status/render/render_test.go @@ -137,3 +137,34 @@ func TestFormatProcessAgentStatus(t *testing.T) { assert.NotContains(t, actual, statusRenderErrors) }) } + +func TestFormatCheckStats(t *testing.T) { + originalTZ := os.Getenv("TZ") + os.Setenv("TZ", "UTC") + defer func() { + os.Setenv("TZ", originalTZ) + }() + jsonBytes, err := os.ReadFile("fixtures/check_stats.json") + require.NoError(t, err) + agentText, err := os.ReadFile("fixtures/check_stats.text") + require.NoError(t, err) + const statusRenderErrors = "Status render errors" + + t.Run("render errors", func(t *testing.T) { + actual, err := FormatCheckStats([]byte{}) + require.NoError(t, err) + assert.Contains(t, actual, statusRenderErrors) + }) + + t.Run("no render errors", func(t *testing.T) { + actual, err := FormatCheckStats(jsonBytes) + require.NoError(t, err) + + // We replace windows line break by linux so the tests pass on every OS + result := strings.Replace(string(agentText), "\r\n", "\n", -1) + actual = strings.Replace(actual, "\r\n", "\n", -1) + + assert.Equal(t, actual, result) + assert.NotContains(t, actual, statusRenderErrors) + }) +}