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
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.admin.metricsproxy;
import ai.vespa.metricsproxy.core.MonitoringConfig;
import com.yahoo.vespa.model.VespaModel;
import org.junit.jupiter.api.Test;
import static com.yahoo.vespa.model.admin.metricsproxy.MetricsProxyModelTester.CLUSTER_CONFIG_ID;
import static com.yahoo.vespa.model.admin.metricsproxy.MetricsProxyModelTester.TestMode.hosted;
import static com.yahoo.vespa.model.admin.metricsproxy.MetricsProxyModelTester.TestMode.self_hosted;
import static com.yahoo.vespa.model.admin.metricsproxy.MetricsProxyModelTester.getModel;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
/**
* @author gjoranv
*/
public class MonitoringElementTest {
@Test
void monitoring_element_is_disallowed_for_hosted_vespa() {
String services = servicesWithMonitoringElement();
try {
getModel(services, hosted);
fail();
} catch (IllegalArgumentException e) {
assertEquals("The 'monitoring' element cannot be used on hosted Vespa.", e.getMessage());
}
}
@Test
void monitoring_element_is_allowed_for_hosted_infrastructure_apps() {
String services = String.join("\n",
"<services application-type='hosted-infrastructure'>",
" <admin version='4.0'>",
" <monitoring interval='300' systemname='my-system' />",
" </admin>",
"</services>"
);
VespaModel model = getModel(services, hosted);
assertMonitoringConfig(model);
}
@Test
void monitoring_element_is_allowed_for_self_hosted_vespa() {
String services = servicesWithMonitoringElement();
VespaModel model = getModel(services, self_hosted);
assertMonitoringConfig(model);
}
private void assertMonitoringConfig(VespaModel model) {
var builder = new MonitoringConfig.Builder();
model.getConfig(builder, CLUSTER_CONFIG_ID);
MonitoringConfig config = builder.build();
assertEquals(5, config.intervalMinutes());
assertEquals("my-system", config.systemName());
}
private String servicesWithMonitoringElement() {
return String.join("\n",
"<services>",
" <admin version='4.0'>",
" <monitoring interval='300' systemname='my-system' />",
" </admin>",
"</services>"
);
}
}
|