blob: 1a0d5c3e1495da97aba978c855ae428218da5a4c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package ai.vespa.metricsproxy.metric.model.json;
import ai.vespa.metricsproxy.metric.model.MetricsPacket;
import org.junit.Test;
import java.util.List;
import java.util.Set;
import static ai.vespa.metricsproxy.core.VespaMetrics.vespaMetricsConsumerId;
import static ai.vespa.metricsproxy.http.ValuesFetcher.defaultMetricsConsumerId;
import static ai.vespa.metricsproxy.metric.model.ServiceId.toServiceId;
import static ai.vespa.metricsproxy.metric.model.json.YamasJsonUtil.YAMAS_ROUTING;
import static ai.vespa.metricsproxy.metric.model.json.YamasJsonUtil.toMetricsPackets;
import static java.util.Collections.singleton;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
/**
* @author gjoranv
*/
public class YamasJsonUtilTest {
@Test
public void json_model_gets_null_status_by_default() {
MetricsPacket packet = new MetricsPacket.Builder(toServiceId("foo"))
.build();
YamasJsonModel jsonModel = YamasJsonUtil.toYamasArray(singleton(packet)).metrics.get(0);
assertNull(jsonModel.status_code);
assertNull(jsonModel.status_msg);
}
@Test
public void status_is_included_in_json_model_when_explicitly_asked_for() {
MetricsPacket packet = new MetricsPacket.Builder(toServiceId("foo"))
.build();
YamasJsonModel jsonModel = YamasJsonUtil.toYamasArray(singleton(packet), true).metrics.get(0);
assertNotNull(jsonModel.status_code);
assertNotNull(jsonModel.status_msg);
}
@Test
public void timestamp_0_in_packet_is_translated_to_null_in_json_model() {
MetricsPacket packet = new MetricsPacket.Builder(toServiceId("foo"))
.timestamp(0L)
.build();
YamasJsonModel jsonModel = YamasJsonUtil.toYamasArray(singleton(packet)).metrics.get(0);
assertNull(jsonModel.timestamp);
}
@Test
public void empty_consumers_is_translated_to_null_routing_in_json_model() {
MetricsPacket packet = new MetricsPacket.Builder(toServiceId("foo"))
.build();
YamasJsonModel jsonModel = YamasJsonUtil.toYamasArray(singleton(packet)).metrics.get(0);
assertNull(jsonModel.routing);
}
@Test
public void default_public_consumer_is_filtered_from_yamas_routing() {
MetricsPacket packet = new MetricsPacket.Builder(toServiceId("foo"))
.addConsumers(Set.of(vespaMetricsConsumerId, defaultMetricsConsumerId))
.build();
YamasJsonModel jsonModel = YamasJsonUtil.toYamasArray(singleton(packet)).metrics.get(0);
List<String> namespaces = jsonModel.routing.get(YAMAS_ROUTING).namespaces;
assertEquals(1, namespaces.size());
assertEquals(vespaMetricsConsumerId.id, namespaces.get(0));
}
@Test
public void only_default_public_consumer_yields_null_routing_in_json_model() {
MetricsPacket packet = new MetricsPacket.Builder(toServiceId("foo"))
.addConsumers(Set.of(defaultMetricsConsumerId))
.build();
YamasJsonModel jsonModel = YamasJsonUtil.toYamasArray(singleton(packet)).metrics.get(0);
assertNull(jsonModel.routing);
}
@Test
public void empty_json_string_yields_empty_packet_list() {
List<MetricsPacket.Builder> builders = toMetricsPackets("");
assertTrue(builders.isEmpty());
}
}
|