Skip to content

Commit

Permalink
Test journald log collection with new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
atoulme committed Jan 22, 2024
1 parent 29ee8d8 commit 6089f05
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 25 deletions.
11 changes: 11 additions & 0 deletions functional_tests/functional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,11 +591,18 @@ func testAgentLogs(t *testing.T) {
excludeNs := true
var sourcetypes []string
var indices []string
var journalDsourceTypes []string

for i := 0; i < len(logsConsumer.AllLogs()); i++ {
l := logsConsumer.AllLogs()[i]
for j := 0; j < l.ResourceLogs().Len(); j++ {
rl := l.ResourceLogs().At(j)
if value, ok := rl.Resource().Attributes().Get("com.splunk.source"); ok && value.AsString() == "/run/log/journal" {
if value, ok := rl.Resource().Attributes().Get("com.splunk.sourcetype"); ok {
sourcetype := value.AsString()
journalDsourceTypes = append(journalDsourceTypes, sourcetype)
}
}
if value, ok := rl.Resource().Attributes().Get("com.splunk.sourcetype"); ok {
sourcetype := value.AsString()
sourcetypes = append(sourcetypes, sourcetype)
Expand Down Expand Up @@ -626,6 +633,10 @@ func testAgentLogs(t *testing.T) {
}
}
}
t.Run("test journald sourcetypes are set", func(t *testing.T) {
assert.Contains(t, journalDsourceTypes, "kube:journald:containerd.service")
assert.Contains(t, journalDsourceTypes, "kube:journald:kubelet.service")
})
t.Run("test node.js log records", func(t *testing.T) {
assert.NotNil(t, helloWorldLogRecord)
sourceType, ok := helloWorldResource.Attributes().Get("com.splunk.sourcetype")
Expand Down
1 change: 1 addition & 0 deletions functional_tests/testdata/test_values.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ splunkPlatform:
logsCollection:
journald:
enabled: true
directory: /run/log/journal
agent:
config:
exporters:
Expand Down
25 changes: 0 additions & 25 deletions test/k8s_logging_tests/test_config_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,31 +106,6 @@ def test_custom_metadata_fields_annotations(setup, label, index, value, expected
len(events))
assert len(events) >= expected

@pytest.mark.parametrize("test_input,expected", [
("containerd.service", 1),
("docker.service", 1),
("kubelet.service", 1),
("empty_unit", 0)
])
def test_journald_unit(setup, test_input, expected):
'''
Test that all configured journald units are present in target index.
'''
logger.info("testing for presence of journald_unit={0} expected={1} event(s)".format(
test_input, expected))
index_logging = os.environ["CI_INDEX_EVENTS"] if os.environ["CI_INDEX_EVENTS"] else "ci_events"
search_query = "index=" + index_logging + " sourcetype=kube:journald:" + test_input
events = check_events_from_splunk(start_time="-1h@h",
url=setup["splunkd_url"],
user=setup["splunk_user"],
query=["search {0}".format(
search_query)],
password=setup["splunk_password"])
logger.info("Splunk received %s events in the last hour",
len(events))
assert len(events) >= expected if test_input != "empty_unit" else len(
events) == expected

@pytest.mark.parametrize("index,expected", [
("test_metrics", 1)
])
Expand Down

0 comments on commit 6089f05

Please sign in to comment.