From b17ac6c3dbe7035b766199dab2003472d97740d7 Mon Sep 17 00:00:00 2001 From: Lucas Liseth Date: Mon, 11 Nov 2024 22:10:09 -0500 Subject: [PATCH 01/24] Test integrations logs writes 10 at a time --- .../fixtures/writeTenLogs.py | 13 ++++ .../fixtures/writeTenLogs.yaml | 8 +++ .../integrations_logs_test.go | 60 +++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations-logs/fixtures/writeTenLogs.py create mode 100644 test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations-logs/fixtures/writeTenLogs.yaml create mode 100644 test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations-logs/integrations_logs_test.go diff --git a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations-logs/fixtures/writeTenLogs.py b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations-logs/fixtures/writeTenLogs.py new file mode 100644 index 0000000000000..7897333cde357 --- /dev/null +++ b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations-logs/fixtures/writeTenLogs.py @@ -0,0 +1,13 @@ +from datadog_checks.base import AgentCheck +from datadog_checks.base.utils.time import get_timestamp + + +class HelloCheck(AgentCheck): + def check(self, instance): + data = {} + data['timestamp'] = get_timestamp() + data['message'] = "Wow, this is a custom log message!" + data['ddtags'] = "env:dev,bar:foo" + + for _ in range(10): + self.send_log(data) diff --git a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations-logs/fixtures/writeTenLogs.yaml b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations-logs/fixtures/writeTenLogs.yaml new file mode 100644 index 0000000000000..460d64b257655 --- /dev/null +++ b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations-logs/fixtures/writeTenLogs.yaml @@ -0,0 +1,8 @@ +init_config: +instances: + - min_collection_interval: 1000 + +logs: + - type: integration + source: my_source + service: my_service diff --git a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations-logs/integrations_logs_test.go b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations-logs/integrations_logs_test.go new file mode 100644 index 0000000000000..cc22bfd5cfb15 --- /dev/null +++ b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations-logs/integrations_logs_test.go @@ -0,0 +1,60 @@ +// Unless explicitly stated otherwise all files in this repository are licensed +// under the Apache License Version 2.0. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2016-present Datadog, Inc. + +package integrationslogs + +import ( + _ "embed" + "strings" + "testing" + "time" + + "github.com/stretchr/testify/assert" + + "github.com/DataDog/datadog-agent/test/new-e2e/pkg/e2e" + "github.com/DataDog/datadog-agent/test/new-e2e/pkg/environments" + awshost "github.com/DataDog/datadog-agent/test/new-e2e/pkg/environments/aws/host" + "github.com/DataDog/datadog-agent/test/new-e2e/pkg/utils/e2e/client/agentclient" + "github.com/DataDog/test-infra-definitions/components/datadog/agentparams" +) + +type LinuxFakeintakeSuite struct { + e2e.BaseSuite[environments.Host] +} + +//go:embed fixtures/writeTenLogs.py +var writeTenLogsCheck string + +//go:embed fixtures/writeTenLogs.yaml +var writeTenLogsConfig string + +// TestLinuxFakeIntakeSuite +func TestLinuxFakeIntakeSuite(t *testing.T) { + suiteParams := []e2e.SuiteOption{ + e2e.WithProvisioner(awshost.Provisioner(awshost.WithAgentOptions( + agentparams.WithLogs(), + // set the integration log file max size to 1MB + agentparams.WithAgentConfig("logs_config.integrations_logs_files_max_size: 1"), + agentparams.WithFile("/etc/datadog-agent/checks.d/writeTenLogs.py", writeTenLogsCheck, true), + agentparams.WithFile("/etc/datadog-agent/conf.d/writeTenLogs.yaml", writeTenLogsConfig, true))))} + + suiteParams = append(suiteParams, e2e.WithDevMode()) + + e2e.Run(t, &LinuxFakeintakeSuite{}, suiteParams...) +} + +// TestWriteTenLogsCheck ensures a check that logs are written to the file ten +// logs at a time +func (v *LinuxFakeintakeSuite) TestWriteTenLogsCheck() { + writeTenLogs := v.Env().Agent.Client.Check(agentclient.WithArgs([]string{"writeTenLogs"})) + assert.Contains(v.T(), writeTenLogs, "writeTenLogs") + + v.EventuallyWithT(func(c *assert.CollectT) { + output := v.Env().RemoteHost.MustExecute("sudo cat /opt/datadog-agent/run/integrations/writeTenLogs*.log") + newLineCount := strings.Count(output, "\n") + assert.Equal(c, newLineCount%10, 0) + assert.GreaterOrEqual(c, 10, newLineCount) + }, 1*time.Minute, 5*time.Second) +} From 3bd211415c530fbe9e0577050ad133e0d7a65aff Mon Sep 17 00:00:00 2001 From: Lucas Liseth Date: Mon, 11 Nov 2024 22:14:54 -0500 Subject: [PATCH 02/24] Switch greater than or equal to --- .../linux-log/integrations-logs/integrations_logs_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations-logs/integrations_logs_test.go b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations-logs/integrations_logs_test.go index cc22bfd5cfb15..a3153de40392e 100644 --- a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations-logs/integrations_logs_test.go +++ b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations-logs/integrations_logs_test.go @@ -55,6 +55,6 @@ func (v *LinuxFakeintakeSuite) TestWriteTenLogsCheck() { output := v.Env().RemoteHost.MustExecute("sudo cat /opt/datadog-agent/run/integrations/writeTenLogs*.log") newLineCount := strings.Count(output, "\n") assert.Equal(c, newLineCount%10, 0) - assert.GreaterOrEqual(c, 10, newLineCount) + assert.GreaterOrEqual(c, newLineCount, 10) }, 1*time.Minute, 5*time.Second) } From 38efced35c2628632f41d5fc0c2e3691b870194c Mon Sep 17 00:00:00 2001 From: Lucas Liseth Date: Tue, 12 Nov 2024 09:46:22 -0500 Subject: [PATCH 03/24] Rename files to comply with linter --- .../{integrations-logs => integrations}/fixtures/writeTenLogs.py | 0 .../fixtures/writeTenLogs.yaml | 0 .../integrations_logs_test.go => integrations/logs_test.go} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/{integrations-logs => integrations}/fixtures/writeTenLogs.py (100%) rename test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/{integrations-logs => integrations}/fixtures/writeTenLogs.yaml (100%) rename test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/{integrations-logs/integrations_logs_test.go => integrations/logs_test.go} (100%) diff --git a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations-logs/fixtures/writeTenLogs.py b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/writeTenLogs.py similarity index 100% rename from test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations-logs/fixtures/writeTenLogs.py rename to test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/writeTenLogs.py diff --git a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations-logs/fixtures/writeTenLogs.yaml b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/writeTenLogs.yaml similarity index 100% rename from test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations-logs/fixtures/writeTenLogs.yaml rename to test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/writeTenLogs.yaml diff --git a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations-logs/integrations_logs_test.go b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go similarity index 100% rename from test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations-logs/integrations_logs_test.go rename to test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go From 70acb8e640d559771679c7d057dfa00ff85a59e3 Mon Sep 17 00:00:00 2001 From: Lucas Liseth Date: Tue, 12 Nov 2024 10:16:47 -0500 Subject: [PATCH 04/24] Rename check files to comply with linter --- .../integrations/fixtures/{writeTenLogs.py => tenLogs.py} | 0 .../integrations/fixtures/{writeTenLogs.yaml => tenLogs.yaml} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/{writeTenLogs.py => tenLogs.py} (100%) rename test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/{writeTenLogs.yaml => tenLogs.yaml} (100%) diff --git a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/writeTenLogs.py b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/tenLogs.py similarity index 100% rename from test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/writeTenLogs.py rename to test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/tenLogs.py diff --git a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/writeTenLogs.yaml b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/tenLogs.yaml similarity index 100% rename from test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/writeTenLogs.yaml rename to test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/tenLogs.yaml From 367098598eb9366a323da8fccf6f9c4f55f400c4 Mon Sep 17 00:00:00 2001 From: Lucas Liseth Date: Tue, 12 Nov 2024 16:12:26 -0500 Subject: [PATCH 05/24] Add a check for fake intake logs --- .../linux-log/integrations/fixtures/tenLogs.py | 2 +- .../linux-log/integrations/fixtures/tenLogs.yaml | 4 ++-- .../log-agent/linux-log/integrations/logs_test.go | 15 +++++++++------ 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/tenLogs.py b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/tenLogs.py index 7897333cde357..7b5312dbacb0c 100644 --- a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/tenLogs.py +++ b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/tenLogs.py @@ -6,7 +6,7 @@ class HelloCheck(AgentCheck): def check(self, instance): data = {} data['timestamp'] = get_timestamp() - data['message'] = "Wow, this is a custom log message!" + data['message'] = "Custom log message" data['ddtags'] = "env:dev,bar:foo" for _ in range(10): diff --git a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/tenLogs.yaml b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/tenLogs.yaml index 460d64b257655..759a3a1e79b76 100644 --- a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/tenLogs.yaml +++ b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/tenLogs.yaml @@ -4,5 +4,5 @@ instances: logs: - type: integration - source: my_source - service: my_service + source: ten_logs_source + service: ten_logs_service diff --git a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go index a3153de40392e..147eea1546768 100644 --- a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go +++ b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go @@ -17,21 +17,22 @@ import ( "github.com/DataDog/datadog-agent/test/new-e2e/pkg/environments" awshost "github.com/DataDog/datadog-agent/test/new-e2e/pkg/environments/aws/host" "github.com/DataDog/datadog-agent/test/new-e2e/pkg/utils/e2e/client/agentclient" + "github.com/DataDog/datadog-agent/test/new-e2e/tests/agent-metrics-logs/log-agent/utils" "github.com/DataDog/test-infra-definitions/components/datadog/agentparams" ) -type LinuxFakeintakeSuite struct { +type IntegrationsLogsSuite struct { e2e.BaseSuite[environments.Host] } -//go:embed fixtures/writeTenLogs.py +//go:embed fixtures/tenLogs.py var writeTenLogsCheck string -//go:embed fixtures/writeTenLogs.yaml +//go:embed fixtures/tenLogs.yaml var writeTenLogsConfig string // TestLinuxFakeIntakeSuite -func TestLinuxFakeIntakeSuite(t *testing.T) { +func TestIntegrationsLogsSuite(t *testing.T) { suiteParams := []e2e.SuiteOption{ e2e.WithProvisioner(awshost.Provisioner(awshost.WithAgentOptions( agentparams.WithLogs(), @@ -42,12 +43,12 @@ func TestLinuxFakeIntakeSuite(t *testing.T) { suiteParams = append(suiteParams, e2e.WithDevMode()) - e2e.Run(t, &LinuxFakeintakeSuite{}, suiteParams...) + e2e.Run(t, &IntegrationsLogsSuite{}, suiteParams...) } // TestWriteTenLogsCheck ensures a check that logs are written to the file ten // logs at a time -func (v *LinuxFakeintakeSuite) TestWriteTenLogsCheck() { +func (v *IntegrationsLogsSuite) TestWriteTenLogsCheck() { writeTenLogs := v.Env().Agent.Client.Check(agentclient.WithArgs([]string{"writeTenLogs"})) assert.Contains(v.T(), writeTenLogs, "writeTenLogs") @@ -57,4 +58,6 @@ func (v *LinuxFakeintakeSuite) TestWriteTenLogsCheck() { assert.Equal(c, newLineCount%10, 0) assert.GreaterOrEqual(c, newLineCount, 10) }, 1*time.Minute, 5*time.Second) + + utils.CheckLogsExpected(v.T(), v.Env().FakeIntake, "ten_logs_service", "Custom log message", []string{}) } From d19caa888f317cc8e883f520e2c8139c5f8989df Mon Sep 17 00:00:00 2001 From: Lucas Liseth Date: Wed, 13 Nov 2024 10:23:07 -0500 Subject: [PATCH 06/24] Remove devmode --- .../log-agent/linux-log/integrations/logs_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go index 147eea1546768..65ab1f7a8122e 100644 --- a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go +++ b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go @@ -41,8 +41,6 @@ func TestIntegrationsLogsSuite(t *testing.T) { agentparams.WithFile("/etc/datadog-agent/checks.d/writeTenLogs.py", writeTenLogsCheck, true), agentparams.WithFile("/etc/datadog-agent/conf.d/writeTenLogs.yaml", writeTenLogsConfig, true))))} - suiteParams = append(suiteParams, e2e.WithDevMode()) - e2e.Run(t, &IntegrationsLogsSuite{}, suiteParams...) } From 86d1004dccb43c6bd9219db373ee8e96a89a8b90 Mon Sep 17 00:00:00 2001 From: Lucas Liseth Date: Wed, 13 Nov 2024 13:44:30 -0500 Subject: [PATCH 07/24] Check for logs tags --- .../log-agent/linux-log/integrations/logs_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go index 65ab1f7a8122e..074c972b981d7 100644 --- a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go +++ b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go @@ -57,5 +57,5 @@ func (v *IntegrationsLogsSuite) TestWriteTenLogsCheck() { assert.GreaterOrEqual(c, newLineCount, 10) }, 1*time.Minute, 5*time.Second) - utils.CheckLogsExpected(v.T(), v.Env().FakeIntake, "ten_logs_service", "Custom log message", []string{}) + utils.CheckLogsExpected(v.T(), v.Env().FakeIntake, "ten_logs_service", "Custom log message", []string{"env:dev", "bar:foo"}) } From fc36e97563308a5329e5211c545b3aba7370b697 Mon Sep 17 00:00:00 2001 From: Lucas Liseth Date: Thu, 14 Nov 2024 15:04:39 -0500 Subject: [PATCH 08/24] Add max size check --- .../integrations/fixtures/maxSize.py | 14 +++++++ .../integrations/fixtures/maxSize.yaml | 8 ++++ .../linux-log/integrations/logs_test.go | 39 ++++++++++++++++++- 3 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/maxSize.py create mode 100644 test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/maxSize.yaml diff --git a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/maxSize.py b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/maxSize.py new file mode 100644 index 0000000000000..28912c298bf03 --- /dev/null +++ b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/maxSize.py @@ -0,0 +1,14 @@ +from datadog_checks.base import AgentCheck + + +class HelloCheck(AgentCheck): + def check(self, instance): + data = {} + # Create a 1 MB string + string_one_mb = "a" * 1024 * 1024 + # Remove 16 characters to account for the json the launcher adds and the + # extra newline character + string_one_mb = string_one_mb[:-15] + data['message'] = string_one_mb + + self.send_log(data) diff --git a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/maxSize.yaml b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/maxSize.yaml new file mode 100644 index 0000000000000..3d2af8f21e241 --- /dev/null +++ b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/maxSize.yaml @@ -0,0 +1,8 @@ +init_config: +instances: + [{}] + +logs: + - type: integration + source: my_source + service: my_service diff --git a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go index 074c972b981d7..468f71be329a1 100644 --- a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go +++ b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go @@ -31,15 +31,23 @@ var writeTenLogsCheck string //go:embed fixtures/tenLogs.yaml var writeTenLogsConfig string +//go:embed fixtures/maxSize.py +var maxSizeCheck string + +//go:embed fixtures/maxSize.yaml +var maxSizeConfig string + // TestLinuxFakeIntakeSuite func TestIntegrationsLogsSuite(t *testing.T) { suiteParams := []e2e.SuiteOption{ e2e.WithProvisioner(awshost.Provisioner(awshost.WithAgentOptions( agentparams.WithLogs(), // set the integration log file max size to 1MB - agentparams.WithAgentConfig("logs_config.integrations_logs_files_max_size: 1"), + agentparams.WithAgentConfig("logs_config.integrations_logs_files_max_size: 2"), agentparams.WithFile("/etc/datadog-agent/checks.d/writeTenLogs.py", writeTenLogsCheck, true), - agentparams.WithFile("/etc/datadog-agent/conf.d/writeTenLogs.yaml", writeTenLogsConfig, true))))} + agentparams.WithFile("/etc/datadog-agent/conf.d/writeTenLogs.yaml", writeTenLogsConfig, true), + agentparams.WithFile("/etc/datadog-agent/checks.d/maxSize.py", maxSizeCheck, true), + agentparams.WithFile("/etc/datadog-agent/conf.d/maxSize.yaml", maxSizeConfig, true))))} e2e.Run(t, &IntegrationsLogsSuite{}, suiteParams...) } @@ -59,3 +67,30 @@ func (v *IntegrationsLogsSuite) TestWriteTenLogsCheck() { utils.CheckLogsExpected(v.T(), v.Env().FakeIntake, "ten_logs_service", "Custom log message", []string{"env:dev", "bar:foo"}) } + +// TestIntegrationLogFileMaxSize ensures integration log files don't exceed the max file size +func (v *IntegrationsLogsSuite) TestIntegrationLogFileMaxSize() { + maxSizeCheck := v.Env().Agent.Client.Check(agentclient.WithArgs([]string{"maxSize"})) + assert.Contains(v.T(), maxSizeCheck, "maxSize") + + // Since it's not yet possible to write to the integration log file by calling + // the agent check command, we can test if the file size limits are being + // respected using the following method: + // 1. Wait until the integration log file reaches the maximum allowable size + // (it won't be deleted until the next log that exceeds the maximum allowable + // size is written). + // 2. Check immediately that on the subsequent write, the file is smaller than + // in step 1, indicating the log file has been deleted and remade, and thus + // respects the set size. + v.EventuallyWithT(func(c *assert.CollectT) { + output := v.Env().RemoteHost.MustExecute("sudo cat /opt/datadog-agent/run/integrations/maxSize*.log") + integrationLogFileSize := len(output) + assert.Equal(c, 2*1024*1024, integrationLogFileSize) + }, 1*time.Minute, 5*time.Second) + + v.EventuallyWithT(func(c *assert.CollectT) { + output := v.Env().RemoteHost.MustExecute("sudo cat /opt/datadog-agent/run/integrations/maxSize*.log") + integrationLogFileSize := len(output) + assert.Equal(c, 1*1024*1024, integrationLogFileSize) + }, 1*time.Minute, 5*time.Second) +} From 375ddf890a809bbbc13d31505791f9fc6c7cde9b Mon Sep 17 00:00:00 2001 From: Lucas Liseth Date: Fri, 15 Nov 2024 15:06:23 -0500 Subject: [PATCH 09/24] Remove testing for implementation --- .../log-agent/linux-log/integrations/logs_test.go | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go index 074c972b981d7..bd70db87ca4c3 100644 --- a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go +++ b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go @@ -7,16 +7,11 @@ package integrationslogs import ( _ "embed" - "strings" "testing" - "time" - - "github.com/stretchr/testify/assert" "github.com/DataDog/datadog-agent/test/new-e2e/pkg/e2e" "github.com/DataDog/datadog-agent/test/new-e2e/pkg/environments" awshost "github.com/DataDog/datadog-agent/test/new-e2e/pkg/environments/aws/host" - "github.com/DataDog/datadog-agent/test/new-e2e/pkg/utils/e2e/client/agentclient" "github.com/DataDog/datadog-agent/test/new-e2e/tests/agent-metrics-logs/log-agent/utils" "github.com/DataDog/test-infra-definitions/components/datadog/agentparams" ) @@ -47,15 +42,5 @@ func TestIntegrationsLogsSuite(t *testing.T) { // TestWriteTenLogsCheck ensures a check that logs are written to the file ten // logs at a time func (v *IntegrationsLogsSuite) TestWriteTenLogsCheck() { - writeTenLogs := v.Env().Agent.Client.Check(agentclient.WithArgs([]string{"writeTenLogs"})) - assert.Contains(v.T(), writeTenLogs, "writeTenLogs") - - v.EventuallyWithT(func(c *assert.CollectT) { - output := v.Env().RemoteHost.MustExecute("sudo cat /opt/datadog-agent/run/integrations/writeTenLogs*.log") - newLineCount := strings.Count(output, "\n") - assert.Equal(c, newLineCount%10, 0) - assert.GreaterOrEqual(c, newLineCount, 10) - }, 1*time.Minute, 5*time.Second) - utils.CheckLogsExpected(v.T(), v.Env().FakeIntake, "ten_logs_service", "Custom log message", []string{"env:dev", "bar:foo"}) } From 8afa07f9717e85b18e0810eff537dc4193eda36c Mon Sep 17 00:00:00 2001 From: Lucas Liseth Date: Tue, 19 Nov 2024 10:55:43 -0500 Subject: [PATCH 10/24] Update maxsize test to check fakeintake --- .../linux-log/integrations/fixtures/maxSize.yaml | 4 ++-- .../log-agent/linux-log/integrations/logs_test.go | 12 +++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/maxSize.yaml b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/maxSize.yaml index 3d2af8f21e241..0927b4f0d895a 100644 --- a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/maxSize.yaml +++ b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/maxSize.yaml @@ -4,5 +4,5 @@ instances: logs: - type: integration - source: my_source - service: my_service + source: max_size_source + service: max_size_service diff --git a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go index 2c5305bdb3314..9ec2c19221f9c 100644 --- a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go +++ b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go @@ -7,13 +7,16 @@ package integrationslogs import ( _ "embed" + "strings" "testing" + "time" "github.com/DataDog/datadog-agent/test/new-e2e/pkg/e2e" "github.com/DataDog/datadog-agent/test/new-e2e/pkg/environments" awshost "github.com/DataDog/datadog-agent/test/new-e2e/pkg/environments/aws/host" "github.com/DataDog/datadog-agent/test/new-e2e/tests/agent-metrics-logs/log-agent/utils" "github.com/DataDog/test-infra-definitions/components/datadog/agentparams" + "github.com/stretchr/testify/assert" ) type IntegrationsLogsSuite struct { @@ -55,9 +58,6 @@ func (v *IntegrationsLogsSuite) TestWriteTenLogsCheck() { // TestIntegrationLogFileMaxSize ensures integration log files don't exceed the max file size func (v *IntegrationsLogsSuite) TestIntegrationLogFileMaxSize() { - maxSizeCheck := v.Env().Agent.Client.Check(agentclient.WithArgs([]string{"maxSize"})) - assert.Contains(v.T(), maxSizeCheck, "maxSize") - // Since it's not yet possible to write to the integration log file by calling // the agent check command, we can test if the file size limits are being // respected using the following method: @@ -67,6 +67,7 @@ func (v *IntegrationsLogsSuite) TestIntegrationLogFileMaxSize() { // 2. Check immediately that on the subsequent write, the file is smaller than // in step 1, indicating the log file has been deleted and remade, and thus // respects the set size. + // 3. After the file sizes are confirmed, check to make sure fakeIntake still receives logs v.EventuallyWithT(func(c *assert.CollectT) { output := v.Env().RemoteHost.MustExecute("sudo cat /opt/datadog-agent/run/integrations/maxSize*.log") integrationLogFileSize := len(output) @@ -78,4 +79,9 @@ func (v *IntegrationsLogsSuite) TestIntegrationLogFileMaxSize() { integrationLogFileSize := len(output) assert.Equal(c, 1*1024*1024, integrationLogFileSize) }, 1*time.Minute, 5*time.Second) + + stringSize := 1024 * 1024 + logString := strings.Repeat("a", stringSize-15) + + utils.CheckLogsExpected(v.T(), v.Env().FakeIntake, "max_size_service", logString, []string{}) } From ad92114763c9136fd08b23f7aea5870145de44ae Mon Sep 17 00:00:00 2001 From: Lucas Liseth Date: Wed, 20 Nov 2024 16:38:46 -0500 Subject: [PATCH 11/24] Treat fakeintake as a black box --- .../integrations/fixtures/maxSize.py | 22 +++++++-- .../integrations/fixtures/tenLogs.yaml | 2 +- .../linux-log/integrations/logs_test.go | 47 +++++++------------ 3 files changed, 36 insertions(+), 35 deletions(-) diff --git a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/maxSize.py b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/maxSize.py index 28912c298bf03..acb1811ca1050 100644 --- a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/maxSize.py +++ b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/maxSize.py @@ -1,14 +1,26 @@ +import uuid + from datadog_checks.base import AgentCheck class HelloCheck(AgentCheck): + def __init__(self, name, init_config, instances): + super().__init__(name, init_config, instances) + # Initialize a local variable to simulate a counter + self.counter = 0 + def check(self, instance): + self.counter = self.counter + 1 data = {} + + uuid_str = str(uuid.uuid4()) # Create a 1 MB string - string_one_mb = "a" * 1024 * 1024 - # Remove 16 characters to account for the json the launcher adds and the - # extra newline character - string_one_mb = string_one_mb[:-15] - data['message'] = string_one_mb + total_size = 1024 * 256 + # Remove 37 characters to account for the json characters, tags, and + # newline character the launcher adds to the log + padding_size = total_size - len(uuid_str) - 37 + log_str = uuid_str + ('a' * padding_size) + data['message'] = log_str self.send_log(data) + self.monotonic_count("rotate_logs_sent", self.counter, tags=["foo:bar"]) diff --git a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/tenLogs.yaml b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/tenLogs.yaml index 759a3a1e79b76..20c720a5f29d5 100644 --- a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/tenLogs.yaml +++ b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/tenLogs.yaml @@ -1,6 +1,6 @@ init_config: instances: - - min_collection_interval: 1000 + [{}] logs: - type: integration diff --git a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go index 9ec2c19221f9c..77c3baa75a0a6 100644 --- a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go +++ b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go @@ -7,9 +7,7 @@ package integrationslogs import ( _ "embed" - "strings" "testing" - "time" "github.com/DataDog/datadog-agent/test/new-e2e/pkg/e2e" "github.com/DataDog/datadog-agent/test/new-e2e/pkg/environments" @@ -41,7 +39,7 @@ func TestIntegrationsLogsSuite(t *testing.T) { e2e.WithProvisioner(awshost.Provisioner(awshost.WithAgentOptions( agentparams.WithLogs(), // set the integration log file max size to 1MB - agentparams.WithAgentConfig("logs_config.integrations_logs_files_max_size: 2"), + agentparams.WithAgentConfig("logs_config.integrations_logs_files_max_size: 1"), agentparams.WithFile("/etc/datadog-agent/checks.d/writeTenLogs.py", writeTenLogsCheck, true), agentparams.WithFile("/etc/datadog-agent/conf.d/writeTenLogs.yaml", writeTenLogsConfig, true), agentparams.WithFile("/etc/datadog-agent/checks.d/maxSize.py", maxSizeCheck, true), @@ -56,32 +54,23 @@ func (v *IntegrationsLogsSuite) TestWriteTenLogsCheck() { utils.CheckLogsExpected(v.T(), v.Env().FakeIntake, "ten_logs_service", "Custom log message", []string{"env:dev", "bar:foo"}) } -// TestIntegrationLogFileMaxSize ensures integration log files don't exceed the max file size -func (v *IntegrationsLogsSuite) TestIntegrationLogFileMaxSize() { +// TestIntegrationLogFileRotation ensures integration log files don't exceed the max file size +func (v *IntegrationsLogsSuite) TestIntegrationLogFileRotation() { // Since it's not yet possible to write to the integration log file by calling - // the agent check command, we can test if the file size limits are being - // respected using the following method: - // 1. Wait until the integration log file reaches the maximum allowable size - // (it won't be deleted until the next log that exceeds the maximum allowable - // size is written). - // 2. Check immediately that on the subsequent write, the file is smaller than - // in step 1, indicating the log file has been deleted and remade, and thus - // respects the set size. - // 3. After the file sizes are confirmed, check to make sure fakeIntake still receives logs - v.EventuallyWithT(func(c *assert.CollectT) { - output := v.Env().RemoteHost.MustExecute("sudo cat /opt/datadog-agent/run/integrations/maxSize*.log") - integrationLogFileSize := len(output) - assert.Equal(c, 2*1024*1024, integrationLogFileSize) - }, 1*time.Minute, 5*time.Second) + // the agent check command, we can test if the file rotation works using the following method: + // 1. Send logs until to the logs from integrations launcher until their + // cumulative size is greater than integration_logs_files_max_size (for logs + // of size 256kb, this will be four logs given the max size of 1mb) + // 2. Check that the logs received from fakeIntake are unique by checking the + // UUID and at the same time ensure monotonic_count is equal to 1 (indicating + // a 1:1 correlation between a log and metric) - v.EventuallyWithT(func(c *assert.CollectT) { - output := v.Env().RemoteHost.MustExecute("sudo cat /opt/datadog-agent/run/integrations/maxSize*.log") - integrationLogFileSize := len(output) - assert.Equal(c, 1*1024*1024, integrationLogFileSize) - }, 1*time.Minute, 5*time.Second) - - stringSize := 1024 * 1024 - logString := strings.Repeat("a", stringSize-15) - - utils.CheckLogsExpected(v.T(), v.Env().FakeIntake, "max_size_service", logString, []string{}) + for i := 0; i < 5; i++ { + utils.CheckLogsExpected(v.T(), v.Env().FakeIntake, "max_size_service", ".*aaaaaaaaaaa.*", []string{}) + metrics, err := v.Env().FakeIntake.Client().FilterMetrics("rotate_logs_sent") + assert.NoError(v.T(), err) + points := metrics[len(metrics)-1].Points + point := metrics[len(metrics)-1].Points[len(points)-1].Value + assert.Equal(v.T(), 1.0, point) + } } From 758e3aecfa7a57722aae6ad26b034132f06a4f91 Mon Sep 17 00:00:00 2001 From: Lucas Liseth Date: Thu, 21 Nov 2024 15:48:39 -0500 Subject: [PATCH 12/24] Add log ID checking for log rotation test --- .../fixtures/{maxSize.py => rotation.py} | 2 +- .../fixtures/{maxSize.yaml => rotation.yaml} | 4 +- .../linux-log/integrations/logs_test.go | 48 +++++++++++++------ 3 files changed, 37 insertions(+), 17 deletions(-) rename test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/{maxSize.py => rotation.py} (90%) rename test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/{maxSize.yaml => rotation.yaml} (50%) diff --git a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/maxSize.py b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/rotation.py similarity index 90% rename from test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/maxSize.py rename to test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/rotation.py index acb1811ca1050..a878fd9e9589e 100644 --- a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/maxSize.py +++ b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/rotation.py @@ -23,4 +23,4 @@ def check(self, instance): data['message'] = log_str self.send_log(data) - self.monotonic_count("rotate_logs_sent", self.counter, tags=["foo:bar"]) + self.monotonic_count("rotate_logs_sent", self.counter) diff --git a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/maxSize.yaml b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/rotation.yaml similarity index 50% rename from test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/maxSize.yaml rename to test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/rotation.yaml index 0927b4f0d895a..0e16957a99626 100644 --- a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/maxSize.yaml +++ b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/rotation.yaml @@ -4,5 +4,5 @@ instances: logs: - type: integration - source: max_size_source - service: max_size_service + source: rotation_source + service: rotation_service diff --git a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go index 77c3baa75a0a6..1184dfce25a9e 100644 --- a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go +++ b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go @@ -8,6 +8,7 @@ package integrationslogs import ( _ "embed" "testing" + "time" "github.com/DataDog/datadog-agent/test/new-e2e/pkg/e2e" "github.com/DataDog/datadog-agent/test/new-e2e/pkg/environments" @@ -27,23 +28,24 @@ var writeTenLogsCheck string //go:embed fixtures/tenLogs.yaml var writeTenLogsConfig string -//go:embed fixtures/maxSize.py -var maxSizeCheck string +//go:embed fixtures/rotation.py +var rotationCheck string -//go:embed fixtures/maxSize.yaml -var maxSizeConfig string +//go:embed fixtures/rotation.yaml +var rotationConfig string // TestLinuxFakeIntakeSuite func TestIntegrationsLogsSuite(t *testing.T) { suiteParams := []e2e.SuiteOption{ e2e.WithProvisioner(awshost.Provisioner(awshost.WithAgentOptions( agentparams.WithLogs(), - // set the integration log file max size to 1MB agentparams.WithAgentConfig("logs_config.integrations_logs_files_max_size: 1"), agentparams.WithFile("/etc/datadog-agent/checks.d/writeTenLogs.py", writeTenLogsCheck, true), agentparams.WithFile("/etc/datadog-agent/conf.d/writeTenLogs.yaml", writeTenLogsConfig, true), - agentparams.WithFile("/etc/datadog-agent/checks.d/maxSize.py", maxSizeCheck, true), - agentparams.WithFile("/etc/datadog-agent/conf.d/maxSize.yaml", maxSizeConfig, true))))} + agentparams.WithFile("/etc/datadog-agent/checks.d/rotation.py", rotationCheck, true), + agentparams.WithFile("/etc/datadog-agent/conf.d/rotation.yaml", rotationConfig, true))))} + + suiteParams = append(suiteParams, e2e.WithDevMode()) e2e.Run(t, &IntegrationsLogsSuite{}, suiteParams...) } @@ -54,7 +56,8 @@ func (v *IntegrationsLogsSuite) TestWriteTenLogsCheck() { utils.CheckLogsExpected(v.T(), v.Env().FakeIntake, "ten_logs_service", "Custom log message", []string{"env:dev", "bar:foo"}) } -// TestIntegrationLogFileRotation ensures integration log files don't exceed the max file size +// TestIntegrationLogFileRotation ensures logs are captured after a integration +// log file is rotated func (v *IntegrationsLogsSuite) TestIntegrationLogFileRotation() { // Since it's not yet possible to write to the integration log file by calling // the agent check command, we can test if the file rotation works using the following method: @@ -65,12 +68,29 @@ func (v *IntegrationsLogsSuite) TestIntegrationLogFileRotation() { // UUID and at the same time ensure monotonic_count is equal to 1 (indicating // a 1:1 correlation between a log and metric) + seen := make(map[string]bool) + + // Check each log is received and is unique for i := 0; i < 5; i++ { - utils.CheckLogsExpected(v.T(), v.Env().FakeIntake, "max_size_service", ".*aaaaaaaaaaa.*", []string{}) - metrics, err := v.Env().FakeIntake.Client().FilterMetrics("rotate_logs_sent") - assert.NoError(v.T(), err) - points := metrics[len(metrics)-1].Points - point := metrics[len(metrics)-1].Points[len(points)-1].Value - assert.Equal(v.T(), 1.0, point) + assert.EventuallyWithT(v.T(), func(c *assert.CollectT) { + logs, err := utils.FetchAndFilterLogs(v.Env().FakeIntake, "rotation_service", ".*message.*") + assert.NoError(c, err) + + if assert.NotEmpty(c, logs) { + log := logs[i] + // Take the first 48 characters of the log, this part contains the UUID + logID := log.Message[:48] + assert.False(v.T(), seen[logID]) + seen[logID] = true + } + + // Check each log received has increased the monotonic counter by 1 + metrics, err := v.Env().FakeIntake.Client().FilterMetrics("rotate_logs_sent") + assert.NoError(v.T(), err) + points := metrics[len(metrics)-1].Points + point := metrics[len(metrics)-1].Points[len(points)-1].Value + assert.Equal(v.T(), 1.0, point) + }, 2*time.Minute, 5*time.Second) + } } From 7430b2d2fbf48654b6e15477ced2786b99a5d490 Mon Sep 17 00:00:00 2001 From: Lucas Liseth Date: Mon, 25 Nov 2024 14:45:42 -0600 Subject: [PATCH 13/24] Prevent truncated logs by reducing log size --- .../log-agent/linux-log/integrations/fixtures/rotation.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/rotation.py b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/rotation.py index a878fd9e9589e..994e9e283c23b 100644 --- a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/rotation.py +++ b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/rotation.py @@ -14,13 +14,14 @@ def check(self, instance): data = {} uuid_str = str(uuid.uuid4()) - # Create a 1 MB string - total_size = 1024 * 256 + # Create a 256kb string + total_size = 1024 * 249 # Remove 37 characters to account for the json characters, tags, and # newline character the launcher adds to the log padding_size = total_size - len(uuid_str) - 37 log_str = uuid_str + ('a' * padding_size) data['message'] = log_str + data['ddtags'] = "env:dev,bar:foo" self.send_log(data) self.monotonic_count("rotate_logs_sent", self.counter) From f44e61e1fe2d3d3f815b6447878ddafd62ff1eae Mon Sep 17 00:00:00 2001 From: Lucas Liseth Date: Thu, 5 Dec 2024 15:37:31 -0500 Subject: [PATCH 14/24] Updated tests to use yaml template --- .../integrations/fixtures/rotation.py | 4 +- .../integrations/fixtures/rotation.yaml | 8 -- .../integrations/fixtures/tenLogs.py | 14 ++-- .../integrations/fixtures/tenLogs.yaml | 8 -- .../linux-log/integrations/logs_test.go | 77 ++++++++++++++++--- 5 files changed, 77 insertions(+), 34 deletions(-) delete mode 100644 test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/rotation.yaml delete mode 100644 test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/tenLogs.yaml diff --git a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/rotation.py b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/rotation.py index 994e9e283c23b..0fca597b3f7ef 100644 --- a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/rotation.py +++ b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/rotation.py @@ -15,13 +15,13 @@ def check(self, instance): uuid_str = str(uuid.uuid4()) # Create a 256kb string - total_size = 1024 * 249 + total_size = instance["log_size"] # Remove 37 characters to account for the json characters, tags, and # newline character the launcher adds to the log padding_size = total_size - len(uuid_str) - 37 log_str = uuid_str + ('a' * padding_size) data['message'] = log_str - data['ddtags'] = "env:dev,bar:foo" + data['ddtags'] = instance['integration_tags'] self.send_log(data) self.monotonic_count("rotate_logs_sent", self.counter) diff --git a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/rotation.yaml b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/rotation.yaml deleted file mode 100644 index 0e16957a99626..0000000000000 --- a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/rotation.yaml +++ /dev/null @@ -1,8 +0,0 @@ -init_config: -instances: - [{}] - -logs: - - type: integration - source: rotation_source - service: rotation_service diff --git a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/tenLogs.py b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/tenLogs.py index 7b5312dbacb0c..a98dd2be59205 100644 --- a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/tenLogs.py +++ b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/tenLogs.py @@ -1,13 +1,17 @@ from datadog_checks.base import AgentCheck -from datadog_checks.base.utils.time import get_timestamp class HelloCheck(AgentCheck): def check(self, instance): + log_str = instance['log_message'] data = {} - data['timestamp'] = get_timestamp() - data['message'] = "Custom log message" - data['ddtags'] = "env:dev,bar:foo" + # data['timestamp'] = get_timestamp() + data['message'] = log_str + # data['ddtags'] = "env:dev,bar:foo" + tags = instance['integration_tags'] + data['ddtags'] = tags - for _ in range(10): + num_logs = instance['log_count'] + + for _ in range(num_logs): self.send_log(data) diff --git a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/tenLogs.yaml b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/tenLogs.yaml deleted file mode 100644 index 20c720a5f29d5..0000000000000 --- a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/tenLogs.yaml +++ /dev/null @@ -1,8 +0,0 @@ -init_config: -instances: - [{}] - -logs: - - type: integration - source: ten_logs_source - service: ten_logs_service diff --git a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go index 1184dfce25a9e..79f375392e6ed 100644 --- a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go +++ b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go @@ -7,9 +7,12 @@ package integrationslogs import ( _ "embed" + "strings" "testing" "time" + "gopkg.in/yaml.v3" + "github.com/DataDog/datadog-agent/test/new-e2e/pkg/e2e" "github.com/DataDog/datadog-agent/test/new-e2e/pkg/environments" awshost "github.com/DataDog/datadog-agent/test/new-e2e/pkg/environments/aws/host" @@ -25,25 +28,34 @@ type IntegrationsLogsSuite struct { //go:embed fixtures/tenLogs.py var writeTenLogsCheck string -//go:embed fixtures/tenLogs.yaml -var writeTenLogsConfig string - //go:embed fixtures/rotation.py var rotationCheck string -//go:embed fixtures/rotation.yaml -var rotationConfig string +type Config struct { + InitConfig interface{} `yaml:"init_config"` + Instances []Instance `yaml:"instances"` + Logs []LogsConfig `yaml:"logs"` +} + +type Instance struct { + LogMessage string `yaml:"log_message"` + LogSize int `yaml:"log_size"` + LogCount int `yaml:"log_count"` + IntegrationTags string `yaml:"integration_tags"` +} + +type LogsConfig struct { + Type string `yaml:"type"` + Source string `yaml:"source"` + Service string `yaml:"service"` +} // TestLinuxFakeIntakeSuite func TestIntegrationsLogsSuite(t *testing.T) { suiteParams := []e2e.SuiteOption{ e2e.WithProvisioner(awshost.Provisioner(awshost.WithAgentOptions( agentparams.WithLogs(), - agentparams.WithAgentConfig("logs_config.integrations_logs_files_max_size: 1"), - agentparams.WithFile("/etc/datadog-agent/checks.d/writeTenLogs.py", writeTenLogsCheck, true), - agentparams.WithFile("/etc/datadog-agent/conf.d/writeTenLogs.yaml", writeTenLogsConfig, true), - agentparams.WithFile("/etc/datadog-agent/checks.d/rotation.py", rotationCheck, true), - agentparams.WithFile("/etc/datadog-agent/conf.d/rotation.yaml", rotationConfig, true))))} + agentparams.WithAgentConfig("logs_config.integrations_logs_files_max_size: 1"))))} suiteParams = append(suiteParams, e2e.WithDevMode()) @@ -53,7 +65,16 @@ func TestIntegrationsLogsSuite(t *testing.T) { // TestWriteTenLogsCheck ensures a check that logs are written to the file ten // logs at a time func (v *IntegrationsLogsSuite) TestWriteTenLogsCheck() { - utils.CheckLogsExpected(v.T(), v.Env().FakeIntake, "ten_logs_service", "Custom log message", []string{"env:dev", "bar:foo"}) + tags := []string{"foo:bar", "env:dev"} + yamlData, err := generateYaml("Custom log message", 1, 10, tags, "logs_from_integrations_source", "logs_from_integrations_service") + assert.NoError(v.T(), err) + + v.UpdateEnv(awshost.Provisioner(awshost.WithAgentOptions( + agentparams.WithLogs(), + agentparams.WithFile("/etc/datadog-agent/conf.d/writeTenLogs.yaml", string(yamlData), true), + agentparams.WithFile("/etc/datadog-agent/checks.d/writeTenLogs.py", writeTenLogsCheck, true)))) + + utils.CheckLogsExpected(v.T(), v.Env().FakeIntake, "logs_from_integrations_service", "", tags) } // TestIntegrationLogFileRotation ensures logs are captured after a integration @@ -68,6 +89,15 @@ func (v *IntegrationsLogsSuite) TestIntegrationLogFileRotation() { // UUID and at the same time ensure monotonic_count is equal to 1 (indicating // a 1:1 correlation between a log and metric) + tags := []string{"test:rotate"} + yamlData, err := generateYaml("a", 1024*245, 1, tags, "rotation_source", "rotation_service") + assert.NoError(v.T(), err) + + v.UpdateEnv(awshost.Provisioner(awshost.WithAgentOptions( + agentparams.WithLogs(), + agentparams.WithFile("/etc/datadog-agent/conf.d/rotation.yaml", string(yamlData), true), + agentparams.WithFile("/etc/datadog-agent/checks.d/rotation.py", rotationCheck, true)))) + seen := make(map[string]bool) // Check each log is received and is unique @@ -94,3 +124,28 @@ func (v *IntegrationsLogsSuite) TestIntegrationLogFileRotation() { } } + +// generateYaml Generates a YAML config for checks to use +func generateYaml(logMessage string, logSize int, logCount int, integrationTags []string, logSource string, logService string) ([]byte, error) { + // Define the YAML structure + config := Config{ + InitConfig: nil, + Instances: []Instance{ + { + LogMessage: logMessage, + LogSize: logSize, + LogCount: logCount, + IntegrationTags: strings.Join(integrationTags, ","), + }, + }, + Logs: []LogsConfig{ + { + Type: "integration", + Source: logSource, + Service: logService, + }, + }, + } + + return yaml.Marshal(&config) +} From 894174f5d382b2a7b924806ca78750946cafca10 Mon Sep 17 00:00:00 2001 From: Lucas Liseth Date: Thu, 5 Dec 2024 16:00:52 -0500 Subject: [PATCH 15/24] Remove comment from python check --- .../log-agent/linux-log/integrations/fixtures/tenLogs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/tenLogs.py b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/tenLogs.py index a98dd2be59205..3bccc0ffc5237 100644 --- a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/tenLogs.py +++ b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/tenLogs.py @@ -1,13 +1,13 @@ from datadog_checks.base import AgentCheck +from datadog_checks.base.utils.time import get_timestamp class HelloCheck(AgentCheck): def check(self, instance): log_str = instance['log_message'] data = {} - # data['timestamp'] = get_timestamp() + data['timestamp'] = get_timestamp() data['message'] = log_str - # data['ddtags'] = "env:dev,bar:foo" tags = instance['integration_tags'] data['ddtags'] = tags From 61ebd79d41e901d072d114d4561d5052a0b81a03 Mon Sep 17 00:00:00 2001 From: Lucas Liseth Date: Fri, 6 Dec 2024 10:06:38 -0500 Subject: [PATCH 16/24] Remove flaky monotonic counter --- .../log-agent/linux-log/integrations/fixtures/rotation.py | 1 - .../log-agent/linux-log/integrations/logs_test.go | 7 ------- 2 files changed, 8 deletions(-) diff --git a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/rotation.py b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/rotation.py index 0fca597b3f7ef..a0ee0daf4357a 100644 --- a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/rotation.py +++ b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/rotation.py @@ -24,4 +24,3 @@ def check(self, instance): data['ddtags'] = instance['integration_tags'] self.send_log(data) - self.monotonic_count("rotate_logs_sent", self.counter) diff --git a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go index 79f375392e6ed..385da0b629ef3 100644 --- a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go +++ b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go @@ -113,13 +113,6 @@ func (v *IntegrationsLogsSuite) TestIntegrationLogFileRotation() { assert.False(v.T(), seen[logID]) seen[logID] = true } - - // Check each log received has increased the monotonic counter by 1 - metrics, err := v.Env().FakeIntake.Client().FilterMetrics("rotate_logs_sent") - assert.NoError(v.T(), err) - points := metrics[len(metrics)-1].Points - point := metrics[len(metrics)-1].Points[len(points)-1].Value - assert.Equal(v.T(), 1.0, point) }, 2*time.Minute, 5*time.Second) } From e9077370a5623959e5e5a8ba942442d3016c29a7 Mon Sep 17 00:00:00 2001 From: Lucas Liseth Date: Fri, 6 Dec 2024 13:43:53 -0500 Subject: [PATCH 17/24] Combined python check files --- .../{tenLogs.py => customIntegration.py} | 13 ++++++++-- .../integrations/fixtures/rotation.py | 26 ------------------- .../linux-log/integrations/logs_test.go | 22 +++++++--------- 3 files changed, 21 insertions(+), 40 deletions(-) rename test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/{tenLogs.py => customIntegration.py} (60%) delete mode 100644 test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/rotation.py diff --git a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/tenLogs.py b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/customIntegration.py similarity index 60% rename from test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/tenLogs.py rename to test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/customIntegration.py index 3bccc0ffc5237..84ffd51c63c78 100644 --- a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/tenLogs.py +++ b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/customIntegration.py @@ -1,16 +1,25 @@ +import uuid + from datadog_checks.base import AgentCheck from datadog_checks.base.utils.time import get_timestamp class HelloCheck(AgentCheck): def check(self, instance): - log_str = instance['log_message'] data = {} + log_str = instance['log_message'] data['timestamp'] = get_timestamp() - data['message'] = log_str tags = instance['integration_tags'] data['ddtags'] = tags + log_str = instance['log_message'] * instance['log_size'] + if instance['unique_message']: + uuid_str = str(uuid.uuid4()) + log_str = uuid_str + log_str + data['message'] = log_str + else: + data['message'] = log_str + num_logs = instance['log_count'] for _ in range(num_logs): diff --git a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/rotation.py b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/rotation.py deleted file mode 100644 index a0ee0daf4357a..0000000000000 --- a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/rotation.py +++ /dev/null @@ -1,26 +0,0 @@ -import uuid - -from datadog_checks.base import AgentCheck - - -class HelloCheck(AgentCheck): - def __init__(self, name, init_config, instances): - super().__init__(name, init_config, instances) - # Initialize a local variable to simulate a counter - self.counter = 0 - - def check(self, instance): - self.counter = self.counter + 1 - data = {} - - uuid_str = str(uuid.uuid4()) - # Create a 256kb string - total_size = instance["log_size"] - # Remove 37 characters to account for the json characters, tags, and - # newline character the launcher adds to the log - padding_size = total_size - len(uuid_str) - 37 - log_str = uuid_str + ('a' * padding_size) - data['message'] = log_str - data['ddtags'] = instance['integration_tags'] - - self.send_log(data) diff --git a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go index 385da0b629ef3..15b18b0eddc81 100644 --- a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go +++ b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go @@ -25,11 +25,8 @@ type IntegrationsLogsSuite struct { e2e.BaseSuite[environments.Host] } -//go:embed fixtures/tenLogs.py -var writeTenLogsCheck string - -//go:embed fixtures/rotation.py -var rotationCheck string +//go:embed fixtures/customIntegration.py +var customIntegration string type Config struct { InitConfig interface{} `yaml:"init_config"` @@ -39,6 +36,7 @@ type Config struct { type Instance struct { LogMessage string `yaml:"log_message"` + UniqueMessage bool `yaml:"unique_message"` LogSize int `yaml:"log_size"` LogCount int `yaml:"log_count"` IntegrationTags string `yaml:"integration_tags"` @@ -66,13 +64,13 @@ func TestIntegrationsLogsSuite(t *testing.T) { // logs at a time func (v *IntegrationsLogsSuite) TestWriteTenLogsCheck() { tags := []string{"foo:bar", "env:dev"} - yamlData, err := generateYaml("Custom log message", 1, 10, tags, "logs_from_integrations_source", "logs_from_integrations_service") + yamlData, err := generateYaml("Custom log message", false, 1, 10, tags, "logs_from_integrations_source", "logs_from_integrations_service") assert.NoError(v.T(), err) v.UpdateEnv(awshost.Provisioner(awshost.WithAgentOptions( agentparams.WithLogs(), agentparams.WithFile("/etc/datadog-agent/conf.d/writeTenLogs.yaml", string(yamlData), true), - agentparams.WithFile("/etc/datadog-agent/checks.d/writeTenLogs.py", writeTenLogsCheck, true)))) + agentparams.WithFile("/etc/datadog-agent/checks.d/writeTenLogs.py", customIntegration, true)))) utils.CheckLogsExpected(v.T(), v.Env().FakeIntake, "logs_from_integrations_service", "", tags) } @@ -90,13 +88,13 @@ func (v *IntegrationsLogsSuite) TestIntegrationLogFileRotation() { // a 1:1 correlation between a log and metric) tags := []string{"test:rotate"} - yamlData, err := generateYaml("a", 1024*245, 1, tags, "rotation_source", "rotation_service") + yamlData, err := generateYaml("a", true, 1024*245, 1, tags, "rotation_source", "rotation_service") assert.NoError(v.T(), err) v.UpdateEnv(awshost.Provisioner(awshost.WithAgentOptions( agentparams.WithLogs(), agentparams.WithFile("/etc/datadog-agent/conf.d/rotation.yaml", string(yamlData), true), - agentparams.WithFile("/etc/datadog-agent/checks.d/rotation.py", rotationCheck, true)))) + agentparams.WithFile("/etc/datadog-agent/checks.d/rotation.py", customIntegration, true)))) seen := make(map[string]bool) @@ -106,7 +104,7 @@ func (v *IntegrationsLogsSuite) TestIntegrationLogFileRotation() { logs, err := utils.FetchAndFilterLogs(v.Env().FakeIntake, "rotation_service", ".*message.*") assert.NoError(c, err) - if assert.NotEmpty(c, logs) { + if assert.NotEmpty(c, logs) && len(logs) >= i { log := logs[i] // Take the first 48 characters of the log, this part contains the UUID logID := log.Message[:48] @@ -114,18 +112,18 @@ func (v *IntegrationsLogsSuite) TestIntegrationLogFileRotation() { seen[logID] = true } }, 2*time.Minute, 5*time.Second) - } } // generateYaml Generates a YAML config for checks to use -func generateYaml(logMessage string, logSize int, logCount int, integrationTags []string, logSource string, logService string) ([]byte, error) { +func generateYaml(logMessage string, uniqueMessage bool, logSize int, logCount int, integrationTags []string, logSource string, logService string) ([]byte, error) { // Define the YAML structure config := Config{ InitConfig: nil, Instances: []Instance{ { LogMessage: logMessage, + UniqueMessage: uniqueMessage, LogSize: logSize, LogCount: logCount, IntegrationTags: strings.Join(integrationTags, ","), From 8a01fb591d4818d35138d35fce91aaf0b0cfed89 Mon Sep 17 00:00:00 2001 From: Lucas Liseth Date: Fri, 6 Dec 2024 13:45:31 -0500 Subject: [PATCH 18/24] Remove devmode --- .../log-agent/linux-log/integrations/logs_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go index 15b18b0eddc81..97aac52efc22e 100644 --- a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go +++ b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go @@ -55,8 +55,6 @@ func TestIntegrationsLogsSuite(t *testing.T) { agentparams.WithLogs(), agentparams.WithAgentConfig("logs_config.integrations_logs_files_max_size: 1"))))} - suiteParams = append(suiteParams, e2e.WithDevMode()) - e2e.Run(t, &IntegrationsLogsSuite{}, suiteParams...) } From 1b266849d2f8d927c9f1180e4353d258f31704eb Mon Sep 17 00:00:00 2001 From: Lucas Liseth Date: Fri, 6 Dec 2024 13:55:08 -0500 Subject: [PATCH 19/24] Renamed file --- .../fixtures/{customIntegration.py => integration.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/{customIntegration.py => integration.py} (100%) diff --git a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/customIntegration.py b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/integration.py similarity index 100% rename from test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/customIntegration.py rename to test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/integration.py From 536c064bce939be9127f30b54386385360519634 Mon Sep 17 00:00:00 2001 From: Lucas Liseth Date: Fri, 6 Dec 2024 14:13:08 -0500 Subject: [PATCH 20/24] Update fixtures file --- .../log-agent/linux-log/integrations/logs_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go index 97aac52efc22e..3c868fa2b7d93 100644 --- a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go +++ b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go @@ -25,7 +25,7 @@ type IntegrationsLogsSuite struct { e2e.BaseSuite[environments.Host] } -//go:embed fixtures/customIntegration.py +//go:embed fixtures/integration.py var customIntegration string type Config struct { From caba1fbedef2424b4fbb93b8db34747ece4a32e0 Mon Sep 17 00:00:00 2001 From: Lucas Liseth Date: Fri, 6 Dec 2024 15:39:56 -0500 Subject: [PATCH 21/24] Updated bounds for logs check --- .../log-agent/linux-log/integrations/logs_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go index 3c868fa2b7d93..56e212bdc6939 100644 --- a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go +++ b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go @@ -102,7 +102,7 @@ func (v *IntegrationsLogsSuite) TestIntegrationLogFileRotation() { logs, err := utils.FetchAndFilterLogs(v.Env().FakeIntake, "rotation_service", ".*message.*") assert.NoError(c, err) - if assert.NotEmpty(c, logs) && len(logs) >= i { + if assert.NotEmpty(c, logs) && len(logs) >= i+1 { log := logs[i] // Take the first 48 characters of the log, this part contains the UUID logID := log.Message[:48] From ac80d1cf3eed3b0589ad85c9897b5b428c12e4ff Mon Sep 17 00:00:00 2001 From: Lucas Liseth Date: Thu, 12 Dec 2024 18:03:58 +0100 Subject: [PATCH 22/24] Replace UUID for logs with increasing counts --- .../integrations/fixtures/integration.py | 13 ++++----- .../linux-log/integrations/logs_test.go | 27 ++++++++++++------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/integration.py b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/integration.py index 84ffd51c63c78..665e432bf1375 100644 --- a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/integration.py +++ b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/integration.py @@ -1,21 +1,22 @@ -import uuid - from datadog_checks.base import AgentCheck from datadog_checks.base.utils.time import get_timestamp class HelloCheck(AgentCheck): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.counter = 0 # Initialize increasing variable + def check(self, instance): data = {} log_str = instance['log_message'] data['timestamp'] = get_timestamp() - tags = instance['integration_tags'] - data['ddtags'] = tags + data['ddtags'] = instance['integration_tags'] log_str = instance['log_message'] * instance['log_size'] if instance['unique_message']: - uuid_str = str(uuid.uuid4()) - log_str = uuid_str + log_str + self.counter += 1 + log_str = "counter: " + str(self.counter) + log_str data['message'] = log_str else: data['message'] = log_str diff --git a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go index 56e212bdc6939..f69572e77b660 100644 --- a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go +++ b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go @@ -7,6 +7,8 @@ package integrationslogs import ( _ "embed" + "regexp" + "strconv" "strings" "testing" "time" @@ -81,9 +83,8 @@ func (v *IntegrationsLogsSuite) TestIntegrationLogFileRotation() { // 1. Send logs until to the logs from integrations launcher until their // cumulative size is greater than integration_logs_files_max_size (for logs // of size 256kb, this will be four logs given the max size of 1mb) - // 2. Check that the logs received from fakeIntake are unique by checking the - // UUID and at the same time ensure monotonic_count is equal to 1 (indicating - // a 1:1 correlation between a log and metric) + // 2. Put a counter in the logs that increases by 1 every time the check is + // called, then check that each log's counter is 1 more than the previous log tags := []string{"test:rotate"} yamlData, err := generateYaml("a", true, 1024*245, 1, tags, "rotation_source", "rotation_service") @@ -94,9 +95,8 @@ func (v *IntegrationsLogsSuite) TestIntegrationLogFileRotation() { agentparams.WithFile("/etc/datadog-agent/conf.d/rotation.yaml", string(yamlData), true), agentparams.WithFile("/etc/datadog-agent/checks.d/rotation.py", customIntegration, true)))) - seen := make(map[string]bool) - // Check each log is received and is unique + prevLogCount := -1 for i := 0; i < 5; i++ { assert.EventuallyWithT(v.T(), func(c *assert.CollectT) { logs, err := utils.FetchAndFilterLogs(v.Env().FakeIntake, "rotation_service", ".*message.*") @@ -104,10 +104,19 @@ func (v *IntegrationsLogsSuite) TestIntegrationLogFileRotation() { if assert.NotEmpty(c, logs) && len(logs) >= i+1 { log := logs[i] - // Take the first 48 characters of the log, this part contains the UUID - logID := log.Message[:48] - assert.False(v.T(), seen[logID]) - seen[logID] = true + regex := regexp.MustCompile(`counter: (\d+)`) + matches := regex.FindStringSubmatch(log.Message) + assert.Greater(v.T(), len(matches), 1, "Did not find count in log") + + number := matches[1] + count, err := strconv.Atoi(number) + assert.Nil(v.T(), err) + + if prevLogCount != -1 { + assert.Equal(v.T(), count, prevLogCount+1) + } + + prevLogCount = count } }, 2*time.Minute, 5*time.Second) } From ca4ae9b78517e7c81532f6ef2ad2bb4a41d62485 Mon Sep 17 00:00:00 2001 From: Lucas Liseth Date: Fri, 13 Dec 2024 15:18:38 +0100 Subject: [PATCH 23/24] Mofify test to remove flakiness --- .../linux-log/integrations/fixtures/integration.py | 10 +++++++--- .../log-agent/linux-log/integrations/logs_test.go | 11 ++++++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/integration.py b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/integration.py index 665e432bf1375..3631c0758bc82 100644 --- a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/integration.py +++ b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/fixtures/integration.py @@ -13,15 +13,19 @@ def check(self, instance): data['timestamp'] = get_timestamp() data['ddtags'] = instance['integration_tags'] - log_str = instance['log_message'] * instance['log_size'] + log_str = instance['log_message'] if instance['unique_message']: + log_str = instance['log_message'] * instance['log_size'] self.counter += 1 - log_str = "counter: " + str(self.counter) + log_str + log_str = "counter: " + str(self.counter) + ' ' + log_str data['message'] = log_str else: data['message'] = log_str num_logs = instance['log_count'] - for _ in range(num_logs): + if num_logs != 1: + for _ in range(num_logs): + self.send_log(data) + else: self.send_log(data) diff --git a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go index f69572e77b660..35eae207ec33f 100644 --- a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go +++ b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go @@ -7,6 +7,7 @@ package integrationslogs import ( _ "embed" + "fmt" "regexp" "strconv" "strings" @@ -57,6 +58,8 @@ func TestIntegrationsLogsSuite(t *testing.T) { agentparams.WithLogs(), agentparams.WithAgentConfig("logs_config.integrations_logs_files_max_size: 1"))))} + suiteParams = append(suiteParams, e2e.WithDevMode()) + e2e.Run(t, &IntegrationsLogsSuite{}, suiteParams...) } @@ -87,7 +90,7 @@ func (v *IntegrationsLogsSuite) TestIntegrationLogFileRotation() { // called, then check that each log's counter is 1 more than the previous log tags := []string{"test:rotate"} - yamlData, err := generateYaml("a", true, 1024*245, 1, tags, "rotation_source", "rotation_service") + yamlData, err := generateYaml("a", true, 1024*230, 1, tags, "rotation_source", "rotation_service") assert.NoError(v.T(), err) v.UpdateEnv(awshost.Provisioner(awshost.WithAgentOptions( @@ -99,7 +102,7 @@ func (v *IntegrationsLogsSuite) TestIntegrationLogFileRotation() { prevLogCount := -1 for i := 0; i < 5; i++ { assert.EventuallyWithT(v.T(), func(c *assert.CollectT) { - logs, err := utils.FetchAndFilterLogs(v.Env().FakeIntake, "rotation_service", ".*message.*") + logs, err := utils.FetchAndFilterLogs(v.Env().FakeIntake, "rotation_service", ".*counter: \\d+.*") assert.NoError(c, err) if assert.NotEmpty(c, logs) && len(logs) >= i+1 { @@ -112,8 +115,10 @@ func (v *IntegrationsLogsSuite) TestIntegrationLogFileRotation() { count, err := strconv.Atoi(number) assert.Nil(v.T(), err) + fmt.Printf("iteration: %d, previous: %d, count: %d\n\n", i, prevLogCount, count) + if prevLogCount != -1 { - assert.Equal(v.T(), count, prevLogCount+1) + assert.Equal(v.T(), prevLogCount+1, count) } prevLogCount = count From 5ca8269ae44d97f6b3dcaa73e763c46b9a62087d Mon Sep 17 00:00:00 2001 From: Lucas Liseth Date: Fri, 13 Dec 2024 16:32:29 +0100 Subject: [PATCH 24/24] Remove print statement --- .../log-agent/linux-log/integrations/logs_test.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go index 35eae207ec33f..37721a72867c8 100644 --- a/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go +++ b/test/new-e2e/tests/agent-metrics-logs/log-agent/linux-log/integrations/logs_test.go @@ -7,7 +7,6 @@ package integrationslogs import ( _ "embed" - "fmt" "regexp" "strconv" "strings" @@ -115,8 +114,6 @@ func (v *IntegrationsLogsSuite) TestIntegrationLogFileRotation() { count, err := strconv.Atoi(number) assert.Nil(v.T(), err) - fmt.Printf("iteration: %d, previous: %d, count: %d\n\n", i, prevLogCount, count) - if prevLogCount != -1 { assert.Equal(v.T(), prevLogCount+1, count) }