Skip to content

Commit 2b0cccf

Browse files
harshit-splunkrockb1017
authored andcommitted
added test for multi-container pod
1 parent 7628e42 commit 2b0cccf

File tree

5 files changed

+76
-23
lines changed

5 files changed

+76
-23
lines changed

test/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,7 @@
2626

2727
# How metric tests works
2828
Test collects test data from metric_data, each data contains metric name, field selector for metric and list of asserions.
29-
For example, for `kube.node.uptime` test, selector value is `node`. So test will search `| mstats max(kube.node.uptime) where index=ci_metric by node`. It will collect uptime value for each node and test will assert each values to be greater than zero.
30-
All selector fields are listed in [selector.conf](https://github.com/splunk/splunk-connect-for-kubernetes/blob/develop/test/k8s_metrics_tests/metric_data/selector.conf) file.
29+
30+
Generic search query used in metric tests: `| mstats max(<metric-name>) where index=<index-name> by <selector field>`
31+
32+
All selector fields are listed in [selector.md](https://github.com/splunk/splunk-connect-for-kubernetes/blob/develop/test/k8s_metrics_tests/metric_data/selector.md)

test/k8s_metrics_tests/metric_data/selector.conf

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
This file is for documentation purposes only. It contains which selector field used in each test
2+
3+
4+
5+
| Metric type | selector for stats | selector for summary | selector for cAdvisor | selector for aggregated |
6+
| ----------- | ------------------ | -------------------- | --------------------- | ----------------------- |
7+
| container | - | container-name | container_name | name |
8+
| pod | - | pod-name | pod_name | name |
9+
| node | node | node | - | node |
10+
| namespace | - | - | - | name |
11+
| cluster | - | - | - | name |
12+
13+
Selector field suggest unique identifier field for given metric.
14+
Here, `"-"` means the given type of metric doesn't exist in metric source(i.e stats/summary/cAdvisor)
15+
16+
For example, `kube.container.uptime` summary metric suggest container uptime. Each containers will have different uptime. So, we can group all `kube.container.uptime` by container's name. Summary scrapper will set the container's name as `container-name`. For this metric, since it is container metric and it's coming from summary api, the selector field will be `container-name`.
17+
18+
Test will search following query in splunk for example test: `| mstats max(kube.container.cpu.uptime) where index=<index> by container-name`
19+

test/k8s_metrics_tests/test_metric_aggr_plugin.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,39 @@ def test_namespace_limit_and_requests(setup, index_metrics):
185185
+ actual_data["splunk-fluentd-k8s-objects"]
186186
+ actual_data["splunk-fluentd-k8s-metrics-agg"]
187187
)
188+
189+
def test_multi_container_pod_limit_and_request(setup, index_metrics):
190+
selector = "name"
191+
for resource in ["cpu", "memory"]:
192+
for metric in ["limit", "request"]:
193+
logger.info(
194+
"testing {} metric".format(f"kube.container.{resource}.{metric} for multi-container pods")
195+
)
196+
container_events = collect_metric_from_splunk(
197+
f"kube.container.{resource}.{metric}",
198+
index_metrics,
199+
selector,
200+
url=setup["splunkd_url"],
201+
user=setup["splunk_user"],
202+
password=setup["splunk_password"],
203+
func="avg",
204+
)
205+
if not "pod-wo-index-wo-ns-index-dup" in container_events:
206+
pytest.fail("pod 'pod-wo-index-wo-ns-index-dup' not found" )
207+
208+
assert container_events["pod-wo-index-wo-ns-index"] == 50
209+
assert container_events["pod-wo-index-wo-ns-index-dup"] == 50
210+
211+
pod_events = collect_metric_from_splunk(
212+
f"kube.pod.{resource}.{metric}",
213+
index_metrics,
214+
selector,
215+
url=setup["splunkd_url"],
216+
user=setup["splunk_user"],
217+
password=setup["splunk_password"],
218+
func="avg",
219+
)
220+
221+
for pod_name, metric_value in pod_events.items():
222+
if "pod-wo-index-wo-ns-index" in pod_name:
223+
assert metric_value == 100, f"{resource}.{metric} of pod '{pod_name}' should be 100"

test/test_setup.yaml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,20 @@ spec:
145145
spec:
146146
containers:
147147
- name: pod-wo-index-wo-ns-index
148-
image: rock1017/log-generator:2.2.6
148+
image: rock1017/log-generator:2.2.6
149+
resources:
150+
limits:
151+
cpu: 50m
152+
memory: 50Mi
153+
requests:
154+
cpu: 50m
155+
memory: 50Mi
156+
- name: pod-wo-index-wo-ns-index-dup
157+
image: rock1017/log-generator:2.2.6
158+
resources:
159+
limits:
160+
cpu: 50m
161+
memory: 50Mi
162+
requests:
163+
cpu: 50m
164+
memory: 50Mi

0 commit comments

Comments
 (0)