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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
// Copyright 2020 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.server.metrics;
import com.yahoo.config.ConfigInstance;
import com.yahoo.config.FileReference;
import com.yahoo.config.model.api.FileDistribution;
import com.yahoo.config.model.api.HostInfo;
import com.yahoo.config.model.api.Model;
import com.yahoo.config.model.api.ServiceInfo;
import com.yahoo.config.provision.AllocatedHosts;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.vespa.config.ConfigKey;
import com.yahoo.vespa.config.ConfigPayload;
import com.yahoo.vespa.config.buildergen.ConfigDefinition;
import com.yahoo.vespa.config.server.application.Application;
import org.junit.Test;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static org.junit.Assert.assertEquals;
/**
* @author olaa
*/
public class DeploymentMetricsRetrieverTest {
@Test
public void getMetrics() {
MockModel mockModel = new MockModel(mockHosts());
MockDeploymentMetricsRetriever mockMetricsRetriever = new MockDeploymentMetricsRetriever();
Application application = new Application(mockModel, null, 0, false,
null, null, ApplicationId.fromSerializedForm("tenant:app:instance"));
DeploymentMetricsRetriever clusterMetricsRetriever = new DeploymentMetricsRetriever(mockMetricsRetriever);
clusterMetricsRetriever.getMetrics(application);
assertEquals(2, mockMetricsRetriever.hosts.size()); // Verify that logserver was ignored
}
private Collection<HostInfo> mockHosts() {
HostInfo hostInfo1 = new HostInfo("host1",
List.of(new ServiceInfo("content", "searchnode", null, null, "", "host1"))
);
HostInfo hostInfo2 = new HostInfo("host2",
List.of(new ServiceInfo("default", "container", null, null, "", "host2"))
);
HostInfo hostInfo3 = new HostInfo("host3",
List.of(new ServiceInfo("default", "logserver", null, null, "", "host3"))
);
return List.of(hostInfo1, hostInfo2, hostInfo3);
}
static class MockDeploymentMetricsRetriever extends ClusterDeploymentMetricsRetriever {
Collection<URI> hosts = new ArrayList<>();
@Override
public Map<ClusterInfo, DeploymentMetricsAggregator> requestMetricsGroupedByCluster(Collection<URI> hosts) {
this.hosts = hosts;
return Map.of(
new ClusterInfo("content_cluster_id", "content"),
new DeploymentMetricsAggregator().addDocumentCount(1000),
new ClusterInfo("container_cluster_id", "container"),
new DeploymentMetricsAggregator().addContainerLatency(123, 5)
);
}
}
static class MockModel implements Model {
final Collection<HostInfo> hosts;
MockModel(Collection<HostInfo> hosts) {
this.hosts = hosts;
}
@Override
@SuppressWarnings("deprecation")
public ConfigPayload getConfig(ConfigKey<?> configKey, ConfigDefinition targetDef) {
throw new UnsupportedOperationException();
}
@Override
public ConfigInstance.Builder getConfigInstance(ConfigKey<?> configKey, ConfigDefinition targetDef) {
throw new UnsupportedOperationException();
}
@Override
public Set<ConfigKey<?>> allConfigsProduced() {
throw new UnsupportedOperationException();
}
@Override
public Collection<HostInfo> getHosts() {
return hosts;
}
@Override
public Set<String> allConfigIds() {
throw new UnsupportedOperationException();
}
@Override
public void distributeFiles(FileDistribution fileDistribution) {
throw new UnsupportedOperationException();
}
@Override
public Set<FileReference> fileReferences() { return new HashSet<>(); }
@Override
public AllocatedHosts allocatedHosts() {
throw new UnsupportedOperationException();
}
}
}
|