|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + * |
| 17 | + */ |
| 18 | + |
| 19 | +package org.apache.skywalking.oap.server.receiver.envoy; |
| 20 | + |
| 21 | +import io.prometheus.client.Metrics; |
| 22 | +import org.apache.skywalking.oap.server.receiver.envoy.metrics.adapters.ListenerMetricsAdapter; |
| 23 | +import org.junit.jupiter.api.BeforeEach; |
| 24 | +import org.junit.jupiter.api.Test; |
| 25 | + |
| 26 | +import java.util.HashMap; |
| 27 | + |
| 28 | +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; |
| 29 | + |
| 30 | +public class ListenerMetricsAdapterTest { |
| 31 | + |
| 32 | + private ListenerMetricsAdapter listenerMetricsAdapter; |
| 33 | + private final Metrics.MetricFamily downstream = Metrics.MetricFamily.newBuilder() |
| 34 | + .setName( |
| 35 | + "listener.0.0.0.0_15090.downstream_cx_total") |
| 36 | + .build(); |
| 37 | + private final Metrics.MetricFamily http = Metrics.MetricFamily.newBuilder() |
| 38 | + .setName( |
| 39 | + "listener.0.0.0.0_15090.http.inbound_0.0.0.0_15090.downstream_rq_2xx") |
| 40 | + .build(); |
| 41 | + private final Metrics.MetricFamily adminListener = Metrics.MetricFamily.newBuilder() |
| 42 | + .setName( |
| 43 | + "listener.admin.downstream_cx_destroy") |
| 44 | + .build(); |
| 45 | + private final Metrics.MetricFamily virtualListener = Metrics.MetricFamily.newBuilder() |
| 46 | + .setName( |
| 47 | + "listener.0.0.0.0_15001.downstream_cx_active") |
| 48 | + .build(); |
| 49 | + private final Metrics.MetricFamily ca = Metrics.MetricFamily.newBuilder() |
| 50 | + .setName( |
| 51 | + "listener.0.0.0.0_15006.ssl.certificate.ROOTCA.expiration_unix_time_seconds") |
| 52 | + .build(); |
| 53 | + |
| 54 | + @BeforeEach |
| 55 | + public void setUp() { |
| 56 | + listenerMetricsAdapter = new ListenerMetricsAdapter(); |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + public void testAdaptMetricsName() { |
| 61 | + assertThat(listenerMetricsAdapter.adaptMetricsName(downstream)).isEqualTo("envoy_listener_metrics"); |
| 62 | + assertThat(listenerMetricsAdapter.adaptMetricsName(http)).isEqualTo("envoy_listener_metrics"); |
| 63 | + assertThat(listenerMetricsAdapter.adaptMetricsName(adminListener)).isEqualTo("envoy_listener_metrics"); |
| 64 | + assertThat(listenerMetricsAdapter.adaptMetricsName(virtualListener)).isEqualTo("envoy_listener_metrics"); |
| 65 | + assertThat(listenerMetricsAdapter.adaptMetricsName(ca)).isEqualTo("envoy_listener_metrics"); |
| 66 | + } |
| 67 | + |
| 68 | + @Test |
| 69 | + public void testAdaptLabels() { |
| 70 | + assertThat( |
| 71 | + listenerMetricsAdapter.adaptLabels(downstream, new HashMap<>()).toString() |
| 72 | + ).isEqualTo("{metrics_name=" + downstream.getName() + "}"); |
| 73 | + |
| 74 | + assertThat( |
| 75 | + listenerMetricsAdapter.adaptLabels(http, new HashMap<>()).toString() |
| 76 | + ).isEqualTo("{metrics_name=" + http.getName() + "}"); |
| 77 | + |
| 78 | + assertThat( |
| 79 | + listenerMetricsAdapter.adaptLabels(adminListener, new HashMap<>()).toString() |
| 80 | + ).isEqualTo("{metrics_name=" + adminListener.getName() + "}"); |
| 81 | + |
| 82 | + assertThat( |
| 83 | + listenerMetricsAdapter.adaptLabels(virtualListener, new HashMap<>()).toString() |
| 84 | + ).isEqualTo("{metrics_name=" + virtualListener.getName() + "}"); |
| 85 | + assertThat( |
| 86 | + listenerMetricsAdapter.adaptLabels(ca, new HashMap<>()).toString() |
| 87 | + ).isEqualTo("{metrics_name=" + ca.getName() + "}"); |
| 88 | + } |
| 89 | +} |
0 commit comments