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

chore(agw): Update metrics naming on exporting #11668

Merged
merged 1 commit into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 15 additions & 16 deletions lte/gateway/python/integ_tests/common/service303_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,25 @@
See the License for the specific language governing permissions and
limitations under the License.
"""
import collections
import logging
import time
from typing import Any, List, NamedTuple

import grpc
import metrics_pb2 as metrics_proto
import orc8r.protos.metricsd_pb2 as metricsd
from integ_tests.gateway.rpc import get_rpc_channel
from orc8r.protos.common_pb2 import Void
from orc8r.protos.service303_pb2 import ServiceInfo
from orc8r.protos.service303_pb2_grpc import Service303Stub

# Container for storing metric values
MetricValue = NamedTuple(
'MetricValue', [
('service', str), ('name', str),
('labels', List), ('value', Any),
],
)


class MetricNotFoundException(Exception):
"""
Expand Down Expand Up @@ -117,12 +124,10 @@ def get_metric_value(
no metric under given metric_name matches the labels.

Args:
metric_name (str): encoded string name of metric.
e.g.: "501" for ue_attach. Use str(protos.metricsd_pb2.ue_attach)
to get "501".
metric_name (str): name of metric.
expected_labels ({str: str}): a dict of {label_name, label_value}
that the metric should have. Optional
e.g.: {'0', 'success'}
e.g.: {'result', 'success'}
default (float): default value to return if metric is not found.
e.g.: 0.

Expand Down Expand Up @@ -164,13 +169,11 @@ def get_metric_value(

def get_start_time(self):
""" Get the start time of the running service """
return self.get_metric_value(
str(metricsd.process_start_time_seconds),
)
return self.get_metric_value("process_start_time_seconds")

def get_uptime(self):
""" Get the uptime (time since service start) of running service """
return self.get_metric_value(str(metricsd.process_cpu_seconds_total))
return self.get_metric_value("process_cpu_seconds_total")

def get_metrics(self):
""" Helper function to query for metrics over grpc """
Expand Down Expand Up @@ -238,8 +241,8 @@ def wait_for_healthy_service(self, started_after_time=0):
info = self._try_to_grpc(self.get_service_info)

if (
info and info.health == ServiceInfo.APP_HEALTHY and
info.state == ServiceInfo.ALIVE
info and info.health == ServiceInfo.APP_HEALTHY
and info.state == ServiceInfo.ALIVE
):
if self._service_started_after(started_after_time):
return True
Expand All @@ -252,10 +255,6 @@ def wait_for_healthy_service(self, started_after_time=0):
return False


# Container for storing metric values
MetricValue = collections.namedtuple('MetricValue', 'service name labels value')


def verify_gateway_metrics(test):
"""
Decorator to verify metrics on an s1aptest. It does this by taking in the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,15 @@
import time
import unittest

import orc8r.protos.metricsd_pb2 as metricsd
import s1ap_types
from integ_tests.s1aptests import s1ap_wrapper


class TestGatewayMetricsAttachDetach(unittest.TestCase):

def setUp(self):
label_values = {str(metricsd.result): "success"}
self._s1ap_wrapper = s1ap_wrapper.TestWrapper()
self._gateway_service = self._s1ap_wrapper.get_gateway_services_util()
v_mme_new_association = self._getMetricValueGivenLabel(
str(metricsd.mme_new_association),
label_values,
)
assert(v_mme_new_association > 0)

def tearDown(self):
self._s1ap_wrapper.cleanup()
Expand All @@ -44,6 +37,14 @@ def _getMetricValueGivenLabel(self, metric_name, label_values):

def test_gateway_metrics_attach_detach(self):
""" Basic gateway metrics with attach/detach for a single UE """

label_values_success = {"result": "success"}
mme_new_association = self._getMetricValueGivenLabel(
"mme_new_association",
label_values_success,
)
self.assertGreater(mme_new_association, 0)

num_ues = 2
detach_type = [
s1ap_types.ueDetachType_t.UE_NORMAL_DETACH.value,
Expand All @@ -53,26 +54,24 @@ def test_gateway_metrics_attach_detach(self):
self._s1ap_wrapper.configUEDevice(num_ues)

label_values_ue_attach_result = \
{str(metricsd.result): "attach_proc_successful"}
label_values_ue_detach_result = {str(metricsd.result): "success"}
label_values_session_result = {str(metricsd.result): "success"}
{"result": "attach_proc_successful"}

for i in range(num_ues):
v_ue_attach = self._getMetricValueGivenLabel(
str(metricsd.ue_attach),
"ue_attach",
label_values_ue_attach_result,
)
v_ue_detach = self._getMetricValueGivenLabel(
str(metricsd.ue_detach),
label_values_ue_detach_result,
"ue_detach",
label_values_success,
)
v_spgw_create_session = self._getMetricValueGivenLabel(
str(metricsd.spgw_create_session),
label_values_session_result,
"spgw_create_session",
label_values_success,
)
v_spgw_delete_session = self._getMetricValueGivenLabel(
str(metricsd.spgw_delete_session),
label_values_session_result,
"spgw_delete_session",
label_values_success,
)

req = self._s1ap_wrapper.ue_req
Expand All @@ -93,26 +92,26 @@ def test_gateway_metrics_attach_detach(self):
# waits until the metrics get updated
time.sleep(0.5)
val = self._getMetricValueGivenLabel(
str(metricsd.ue_attach),
"ue_attach",
label_values_ue_attach_result,
)
assert(val == v_ue_attach + 1)

val = self._getMetricValueGivenLabel(
str(metricsd.spgw_create_session),
label_values_session_result,
"spgw_create_session",
label_values_success,
)
assert(val == v_spgw_create_session + 1)

val = self._getMetricValueGivenLabel(
str(metricsd.ue_detach),
label_values_ue_detach_result,
"ue_detach",
label_values_success,
)
assert (val == v_ue_detach)

val = self._getMetricValueGivenLabel(
str(metricsd.spgw_delete_session),
label_values_session_result,
"spgw_delete_session",
label_values_success,
)
assert (val == v_spgw_delete_session)

Expand All @@ -128,14 +127,14 @@ def test_gateway_metrics_attach_detach(self):
# waits so that metrics have time to be updated
time.sleep(0.5)
val = self._getMetricValueGivenLabel(
str(metricsd.ue_detach),
label_values_ue_detach_result,
"ue_detach",
label_values_success,
)
assert(val == v_ue_detach + 1)

val = self._getMetricValueGivenLabel(
str(metricsd.spgw_delete_session),
label_values_session_result,
"spgw_delete_session",
label_values_success,
)
assert (val == v_spgw_delete_session + 1)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import unittest

import orc8r.protos.metricsd_pb2 as metricsd
import s1ap_types
import s1ap_wrapper
from python.integ_tests.common.service303_utils import (
Expand All @@ -28,46 +27,46 @@
# triggers UE context release command.


class NoAttachComplete(unittest.TestCase):
class TestNoAttachComplete(unittest.TestCase):

TEST_METRICS = [
MetricValue(
service="mme",
name=str(metricsd.ue_attach),
name="ue_attach",
labels={
str(metricsd.result): "failure",
str(metricsd.cause): "no_response_for_attach_accept",
"result": "failure",
"cause": "no_response_for_attach_accept",
},
value=1,
),
MetricValue(
service="mme",
name=str(metricsd.ue_attach),
labels={str(metricsd.action): "attach_accept_sent"},
name="ue_attach",
labels={"action": "attach_accept_sent"},
value=1,
),
MetricValue(
service="mme",
name=str(metricsd.ue_detach),
labels={str(metricsd.cause): "implicit_detach"},
name="ue_detach",
labels={"cause": "implicit_detach"},
value=1,
),
MetricValue(
service="mme",
name=str(metricsd.nas_attach_accept_timer_expired),
name="nas_attach_accept_timer_expired",
labels={},
value=1,
),
MetricValue(
service="mme",
name=str(metricsd.mme_spgw_create_session_req),
name="mme_spgw_create_session_req",
labels={},
value=1,
),
MetricValue(
service="mme",
name=str(metricsd.mme_spgw_create_session_rsp),
labels={str(metricsd.result): "success"},
name="mme_spgw_create_session_rsp",
labels={"result": "success"},
value=1,
),
]
Expand Down
21 changes: 10 additions & 11 deletions lte/gateway/python/integ_tests/s1aptests/test_no_auth_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import unittest

import orc8r.protos.metricsd_pb2 as metricsd
import s1ap_types
import s1ap_wrapper
from python.integ_tests.common.service303_utils import (
Expand All @@ -27,35 +26,35 @@ class TestNoAuthResponse(unittest.TestCase):
TEST_METRICS = [
MetricValue(
service="mme",
name=str(metricsd.ue_attach),
name="ue_attach",
labels={
str(metricsd.result): "failure",
str(metricsd.cause): "no_response_for_auth_request",
"result": "failure",
"cause": "no_response_for_auth_request",
},
value=1,
),
MetricValue(
service="mme",
name=str(metricsd.ue_attach),
labels={str(metricsd.action): "attach_accept_sent"},
name="ue_attach",
labels={"action": "attach_accept_sent"},
value=0,
),
MetricValue(
service="mme",
name=str(metricsd.ue_detach),
labels={str(metricsd.cause): "implicit_detach"},
name="ue_detach",
labels={"cause": "implicit_detach"},
value=0,
),
MetricValue(
service="mme",
name=str(metricsd.nas_auth_rsp_timer_expired),
name="nas_auth_rsp_timer_expired",
labels={},
value=1,
),
MetricValue(
service="mme",
name=str(metricsd.spgw_create_session),
labels={str(metricsd.result): "success"},
name="spgw_create_session",
labels={"result": "success"},
value=0,
),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import unittest

import orc8r.protos.metricsd_pb2 as metricsd
import s1ap_types
import s1ap_wrapper
from python.integ_tests.common.service303_utils import (
Expand All @@ -27,35 +26,35 @@ class TestNoSecurityModeComplete(unittest.TestCase):
TEST_METRICS = [
MetricValue(
service="mme",
name=str(metricsd.ue_attach),
name="ue_attach",
labels={
str(metricsd.result): "failure",
str(metricsd.cause): "no_response_for_security_mode_command",
"result": "failure",
"cause": "no_response_for_security_mode_command",
},
value=1,
),
MetricValue(
service="mme",
name=str(metricsd.ue_attach),
labels={str(metricsd.action): "attach_accept_sent"},
name="ue_attach",
labels={"action": "attach_accept_sent"},
value=0,
),
MetricValue(
service="mme",
name=str(metricsd.ue_detach),
labels={str(metricsd.cause): "implicit_detach"},
name="ue_detach",
labels={"cause": "implicit_detach"},
value=1,
),
MetricValue(
service="mme",
name=str(metricsd.nas_security_mode_command_timer_expired),
name="nas_security_mode_command_timer_expired",
labels={},
value=1,
),
MetricValue(
service="mme",
name=str(metricsd.spgw_create_session),
labels={str(metricsd.result): "success"},
name="spgw_create_session",
labels={"result": "success"},
value=0,
),
]
Expand Down