Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
XuanWang-Amos committed Jun 3, 2024
1 parent 57e0df3 commit 1baecae
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions tests/gamma/csm_observability_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,9 @@ 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)
self.filter_label_based_on_lang(
self.lang_spec.client_lang, expected_metric_labels
)
for metric in HISTOGRAM_CLIENT_METRICS:
actual_metric_labels = all_results[metric].metric_labels
self.assertDictEqual(
Expand All @@ -328,8 +329,9 @@ 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)
self.filter_label_based_on_lang(
self.lang_spec.server_lang, expected_metric_labels
)
for metric in HISTOGRAM_SERVER_METRICS:
actual_metric_labels = all_results[metric].metric_labels
self.assertDictEqual(
Expand All @@ -346,8 +348,9 @@ 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)
self.filter_label_based_on_lang(
self.lang_spec.client_lang, expected_metric_labels
)
for metric in COUNTER_CLIENT_METRICS:
actual_metric_labels = all_results[metric].metric_labels
self.assertDictEqual(
Expand All @@ -363,8 +366,9 @@ 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)
self.filter_label_based_on_lang(
self.lang_spec.server_lang, expected_metric_labels
)
for metric in COUNTER_SERVER_METRICS:
actual_metric_labels = all_results[metric].metric_labels
self.assertDictEqual(
Expand Down Expand Up @@ -467,16 +471,18 @@ def build_counter_query(cls, metric_type: str, namespace: str) -> str:
)

@staticmethod
def remove_otel_scope_labels(labels: Dict[str, Any]) -> None:
def filter_label_based_on_lang(
language: _Lang, 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.
Filter labels to check based on language.
"""
if "otel_scope_version" in labels:
del labels["otel_scope_version"]
if "otel_scope_name" in labels:
del labels["otel_scope_name"]
if language == _Lang.PYTHON:
# 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,
Expand Down

0 comments on commit 1baecae

Please sign in to comment.