Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix metrics sourcetype annotation #1375

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .chloggen/fixmetricssourcetypeannotation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix
# The name of the component, or a single word describing the area of concern, (e.g. agent, clusterReceiver, gateway, operator, chart, other)
component: other
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Fixed updating metrics' sourcetype with annotations
# One or more tracking issues related to the change
issues: []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
issues: []
issues: [1375]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
2 changes: 1 addition & 1 deletion docs/advanced-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ Manage Splunk OTel Collector Logging with these supported annotations.
* Filter logs using pod and/or namespace annotation
* If `logsCollection.containers.useSplunkIncludeAnnotation` is `false` (default: false), set `splunk.com/exclude` annotation to `true` on pod and/or namespace to exclude its logs from ingested.
* If `logsCollection.containers.useSplunkIncludeAnnotation` is `true` (default: false), set `splunk.com/include` annotation to `true` on pod and/or namespace to only include its logs from ingested. All other logs will be ignored.
* Use `splunk.com/sourcetype` annotation on pod to overwrite `sourcetype` field. If not set, it is dynamically generated to be `kube:container:CONTAINER_NAME`.
* Use `splunk.com/sourcetype` annotation on pod to overwrite `sourcetype` field. If not set, it is dynamically generated to be `kube:container:CONTAINER_NAME` for logs and defaults to "httpevent" for metrics.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I might suggest updating this to something like this.

Suggested change
* Use `splunk.com/sourcetype` annotation on pod to overwrite `sourcetype` field. If not set, it is dynamically generated to be `kube:container:CONTAINER_NAME` for logs and defaults to "httpevent" for metrics.
* Use `splunk.com/sourcetype` annotation on pod to overwrite `sourcetype` field.
* For logs, if not set, it defaults to `kube:container:CONTAINER_NAME`.
* For metrics, if not set, it defaults to `httpevent`.


### Performance of native OpenTelemetry logs collection

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ data:
annotations:
- from: pod
key: splunk.com/sourcetype
tag_name: com.splunk.sourcetype
- from: namespace
key: splunk.com/metricsIndex
tag_name: com.splunk.index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ data:
annotations:
- from: pod
key: splunk.com/sourcetype
tag_name: com.splunk.sourcetype
- from: namespace
key: splunk.com/metricsIndex
tag_name: com.splunk.index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ spec:
component: otel-collector-agent
release: default
annotations:
checksum/config: 068897d39969e321b5a814179eddd2f7f737785ba8ff107c45979bcd2a1e788b
checksum/config: 475f8c97681a13e8e30986fdc3baa71eee05a2f3e066c29e0777080a9a8a87c0
kubectl.kubernetes.io/default-container: otel-collector
spec:
hostNetwork: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ spec:
component: otel-k8s-cluster-receiver
release: default
annotations:
checksum/config: b5bdd9198d04f9a84b31a870e0f69c61f29a28dc2af003c2682db0d92a951d11
checksum/config: c238a58b0c8c81f81b1497dcff8d795a79788d35ee239ffafb7ad4f58dc6b09e
spec:
serviceAccountName: default-splunk-otel-collector
nodeSelector:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ data:
annotations:
- from: pod
key: splunk.com/sourcetype
tag_name: com.splunk.sourcetype
- from: namespace
key: splunk.com/metricsIndex
tag_name: com.splunk.index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ data:
annotations:
- from: pod
key: splunk.com/sourcetype
tag_name: com.splunk.sourcetype
- from: namespace
key: splunk.com/metricsIndex
tag_name: com.splunk.index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ spec:
component: otel-collector-agent
release: default
annotations:
checksum/config: 05ef4a80e4010dc707c37364538d5fa1caea6e4ec70e47d40b05d4854604d02a
checksum/config: f1e5fbd7c1b4136ebec743dd00fa834dcb9d6d78c37eed30cff72e4fc0efe22c
kubectl.kubernetes.io/default-container: otel-collector
spec:
hostNetwork: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ spec:
component: otel-k8s-cluster-receiver
release: default
annotations:
checksum/config: b5bdd9198d04f9a84b31a870e0f69c61f29a28dc2af003c2682db0d92a951d11
checksum/config: c238a58b0c8c81f81b1497dcff8d795a79788d35ee239ffafb7ad4f58dc6b09e
spec:
serviceAccountName: default-splunk-otel-collector
nodeSelector:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ data:
annotations:
- from: pod
key: splunk.com/sourcetype
tag_name: com.splunk.sourcetype
- from: namespace
key: splunk.com/metricsIndex
tag_name: com.splunk.index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ data:
annotations:
- from: pod
key: splunk.com/sourcetype
tag_name: com.splunk.sourcetype
- from: namespace
key: splunk.com/metricsIndex
tag_name: com.splunk.index
Expand Down
2 changes: 1 addition & 1 deletion examples/multi-metrics/rendered_manifests/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ spec:
component: otel-collector-agent
release: default
annotations:
checksum/config: 5fe75d65f83fde093bd36e84d7176c1ed4887c3ce0516aceaf06a25f367ac88f
checksum/config: 96af0d7f6f9dba3b552802d25ca1356f443c35bb3a34492873f004325a1c9fb4
kubectl.kubernetes.io/default-container: otel-collector
spec:
hostNetwork: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ spec:
component: otel-k8s-cluster-receiver
release: default
annotations:
checksum/config: b5bdd9198d04f9a84b31a870e0f69c61f29a28dc2af003c2682db0d92a951d11
checksum/config: c238a58b0c8c81f81b1497dcff8d795a79788d35ee239ffafb7ad4f58dc6b09e
spec:
serviceAccountName: default-splunk-otel-collector
nodeSelector:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ data:
annotations:
- from: pod
key: splunk.com/sourcetype
tag_name: com.splunk.sourcetype
- from: namespace
key: splunk.com/metricsIndex
tag_name: com.splunk.index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ data:
annotations:
- from: pod
key: splunk.com/sourcetype
tag_name: com.splunk.sourcetype
- from: namespace
key: splunk.com/metricsIndex
tag_name: com.splunk.index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ spec:
component: otel-collector-agent
release: default
annotations:
checksum/config: c1d5086a46b85ca0828c7fdd4d35e1b421db0eedbb9ac7b525ebb1a87262f77a
checksum/config: ca910388e71a4073e6934a02abfb92b7c2b25a1be94dd1dc902759dd1f6d0aeb
kubectl.kubernetes.io/default-container: otel-collector
spec:
hostNetwork: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ spec:
component: otel-k8s-cluster-receiver
release: default
annotations:
checksum/config: b5bdd9198d04f9a84b31a870e0f69c61f29a28dc2af003c2682db0d92a951d11
checksum/config: c238a58b0c8c81f81b1497dcff8d795a79788d35ee239ffafb7ad4f58dc6b09e
spec:
serviceAccountName: default-splunk-otel-collector
nodeSelector:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ k8sattributes/metrics:
metadata: []
annotations:
- key: splunk.com/sourcetype
tag_name: com.splunk.sourcetype
from: pod
- key: splunk.com/metricsIndex
tag_name: com.splunk.index
Expand Down
21 changes: 21 additions & 0 deletions test/k8s_logging_tests/test_config_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,24 @@ def test_metric_index_from_annotations(setup, index, expected):
logger.info("Splunk received %s events in the last minute",
len(events))
assert len(events) >= expected

@pytest.mark.parametrize("index,sourcetype,expected", [
("test_metrics", "sourcetype-anno", 1)
])
def test_metric_sourcetype_from_annotations(setup, index, sourcetype, expected):

'''
Test that metrics are being assigned the "sourcetype-anno" sourcetype, as defined by splunk.com/sourcetype annotation added during setup
'''
logger.info("testing for metrics index={0} sourcetype={1} expected={2} event(s)".format(index, sourcetype, expected))
search_query = "index={0} filter=\"sourcetype={1}\"".format(index, sourcetype)

events = check_events_from_splunk(start_time="-1h@h",
url=setup["splunkd_url"],
user=setup["splunk_user"],
query=["mpreview {0}".format(
search_query)],
password=setup["splunk_password"])
logger.info("Splunk received %s events in the last minute",
len(events))
assert len(events) >= expected
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is failing in CI/CD still, see what you can do about it.

Loading