Skip to content

Commit

Permalink
Enable python CSM observability test
Browse files Browse the repository at this point in the history
  • Loading branch information
XuanWang-Amos committed Jun 3, 2024
1 parent 61cbaea commit 57e0df3
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions tests/gamma/csm_observability_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import dataclasses
import logging
import time
from typing import Callable, Iterable, TextIO
from typing import Any, Callable, Dict, Iterable, TextIO
import unittest.mock

from absl import flags
Expand Down Expand Up @@ -173,9 +173,13 @@ class CsmObservabilityTest(xds_gamma_testcase.GammaXdsKubernetesTestCase):

@staticmethod
def is_supported(config: skips.TestConfig) -> bool:
if config.client_lang == _Lang.CPP and config.server_lang == _Lang.CPP:
# CSM Observability Test is only supported for CPP for now.
if config.client_lang == _Lang.CPP or config.server_lang == _Lang.CPP:
return config.version_gte("v1.62.x")
elif (
config.client_lang == _Lang.PYTHON
or config.server_lang == _Lang.PYTHON
):
return config.version_gte("v1.65.x")
return False

@classmethod
Expand Down Expand Up @@ -297,6 +301,8 @@ def test_csm_observability(self):
"otel_scope_version": ANY,
"pod": test_client.hostname,
}
if self.lang_spec.client_lang == _Lang.PYTHON:
self.remove_otel_scope_labels(expected_metric_labels)
for metric in HISTOGRAM_CLIENT_METRICS:
actual_metric_labels = all_results[metric].metric_labels
self.assertDictEqual(
Expand All @@ -322,6 +328,8 @@ def test_csm_observability(self):
"otel_scope_version": ANY,
"pod": test_server.hostname,
}
if self.lang_spec.server_lang == _Lang.PYTHON:
self.remove_otel_scope_labels(expected_metric_labels)
for metric in HISTOGRAM_SERVER_METRICS:
actual_metric_labels = all_results[metric].metric_labels
self.assertDictEqual(
Expand All @@ -338,6 +346,8 @@ def test_csm_observability(self):
"otel_scope_version": ANY,
"pod": test_client.hostname,
}
if self.lang_spec.client_lang == _Lang.PYTHON:
self.remove_otel_scope_labels(expected_metric_labels)
for metric in COUNTER_CLIENT_METRICS:
actual_metric_labels = all_results[metric].metric_labels
self.assertDictEqual(
Expand All @@ -353,6 +363,8 @@ def test_csm_observability(self):
"otel_scope_version": ANY,
"pod": test_server.hostname,
}
if self.lang_spec.server_lang == _Lang.PYTHON:
self.remove_otel_scope_labels(expected_metric_labels)
for metric in COUNTER_SERVER_METRICS:
actual_metric_labels = all_results[metric].metric_labels
self.assertDictEqual(
Expand Down Expand Up @@ -454,6 +466,18 @@ def build_counter_query(cls, metric_type: str, namespace: str) -> str:
f'resource.labels.namespace = "{namespace}"'
)

@staticmethod
def remove_otel_scope_labels(labels: Dict[str, Any]) -> None:
"""
Removes the 'otel_scope_version' and 'otel_scope_name' from the labels to check.
TODO(xuanwn): Remove this once https://github.com/open-telemetry/opentelemetry-python/issues/3072 is fixed.
"""
if "otel_scope_version" in labels:
del labels["otel_scope_version"]
if "otel_scope_name" in labels:
del labels["otel_scope_name"]

def query_metrics(
self,
metric_names: Iterable[str],
Expand Down

0 comments on commit 57e0df3

Please sign in to comment.