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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
|
// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.controller.maintenance;
import com.yahoo.component.Version;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.config.provision.Environment;
import com.yahoo.config.provision.zone.UpgradePolicy;
import com.yahoo.config.provision.zone.ZoneId;
import com.yahoo.vespa.hosted.controller.Application;
import com.yahoo.vespa.hosted.controller.Controller;
import com.yahoo.vespa.hosted.controller.ControllerTester;
import com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId;
import com.yahoo.vespa.hosted.controller.api.integration.deployment.ApplicationVersion;
import com.yahoo.vespa.hosted.controller.application.ApplicationPackage;
import com.yahoo.vespa.hosted.controller.application.SystemApplication;
import com.yahoo.vespa.hosted.controller.deployment.ApplicationPackageBuilder;
import com.yahoo.vespa.hosted.controller.deployment.DeploymentTester;
import com.yahoo.vespa.hosted.controller.deployment.InternalDeploymentTester;
import com.yahoo.vespa.hosted.controller.integration.MetricsMock;
import com.yahoo.vespa.hosted.controller.integration.ZoneApiMock;
import com.yahoo.vespa.hosted.controller.persistence.MockCuratorDb;
import org.junit.Test;
import java.time.Duration;
import java.util.List;
import java.util.Optional;
import static com.yahoo.vespa.hosted.controller.api.integration.deployment.JobType.component;
import static com.yahoo.vespa.hosted.controller.api.integration.deployment.JobType.productionUsWest1;
import static com.yahoo.vespa.hosted.controller.api.integration.deployment.JobType.stagingTest;
import static com.yahoo.vespa.hosted.controller.api.integration.deployment.JobType.systemTest;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
/**
* @author mortent
*/
public class MetricsReporterTest {
private final MetricsMock metrics = new MetricsMock();
@Test
public void test_deployment_fail_ratio() {
DeploymentTester tester = new DeploymentTester();
ApplicationPackage applicationPackage = new ApplicationPackageBuilder()
.environment(Environment.prod)
.region("us-west-1")
.build();
MetricsReporter metricsReporter = createReporter(tester.controller());
metricsReporter.maintain();
assertEquals(0.0, metrics.getMetric(MetricsReporter.DEPLOYMENT_FAIL_METRIC));
// Deploy all apps successfully
Application app1 = tester.createApplication("app1", "tenant1", 1, 11L);
Application app2 = tester.createApplication("app2", "tenant1", 2, 22L);
Application app3 = tester.createApplication("app3", "tenant1", 3, 33L);
Application app4 = tester.createApplication("app4", "tenant1", 4, 44L);
tester.deployCompletely(app1, applicationPackage);
tester.deployCompletely(app2, applicationPackage);
tester.deployCompletely(app3, applicationPackage);
tester.deployCompletely(app4, applicationPackage);
metricsReporter.maintain();
assertEquals(0.0, metrics.getMetric(MetricsReporter.DEPLOYMENT_FAIL_METRIC));
// 1 app fails system-test
tester.jobCompletion(component).application(app4).nextBuildNumber().uploadArtifact(applicationPackage).submit();
tester.deployAndNotify(app4.id().defaultInstance(), Optional.of(applicationPackage), false, systemTest);
metricsReporter.maintain();
assertEquals(25.0, metrics.getMetric(MetricsReporter.DEPLOYMENT_FAIL_METRIC));
}
@Test
public void test_deployment_average_duration() {
DeploymentTester tester = new DeploymentTester();
ApplicationPackage applicationPackage = new ApplicationPackageBuilder()
.environment(Environment.prod)
.region("us-west-1")
.build();
MetricsReporter reporter = createReporter(tester.controller());
Application app = tester.createApplication("app1", "tenant1", 1, 11L);
tester.deployCompletely(app, applicationPackage);
reporter.maintain();
assertEquals(Duration.ZERO, getAverageDeploymentDuration(app.id().defaultInstance())); // An exceptionally fast deployment :-)
// App spends 3 hours deploying
tester.jobCompletion(component).application(app).nextBuildNumber().uploadArtifact(applicationPackage).submit();
tester.clock().advance(Duration.ofHours(1));
tester.deployAndNotify(app.id().defaultInstance(), Optional.of(applicationPackage), true, systemTest);
tester.clock().advance(Duration.ofMinutes(30));
tester.deployAndNotify(app.id().defaultInstance(), Optional.of(applicationPackage), true, stagingTest);
tester.clock().advance(Duration.ofMinutes(90));
tester.deployAndNotify(app.id().defaultInstance(), Optional.of(applicationPackage), true, productionUsWest1);
reporter.maintain();
// Average time is 1 hour (system-test) + 90 minutes (staging-test runs in parallel with system-test) + 90 minutes (production) / 3 jobs
assertEquals(Duration.ofMinutes(80), getAverageDeploymentDuration(app.id().defaultInstance()));
// Another deployment starts and stalls for 12 hours
tester.jobCompletion(component).application(app).nextBuildNumber(2).uploadArtifact(applicationPackage).submit();
tester.clock().advance(Duration.ofHours(12));
reporter.maintain();
assertEquals(Duration.ofHours(12) // hanging system-test
.plus(Duration.ofHours(12)) // hanging staging-test
.plus(Duration.ofMinutes(90)) // previous production job
.dividedBy(3), // Total number of orchestrated jobs
getAverageDeploymentDuration(app.id().defaultInstance()));
}
@Test
public void test_deployments_failing_upgrade() {
DeploymentTester tester = new DeploymentTester();
ApplicationPackage applicationPackage = new ApplicationPackageBuilder()
.environment(Environment.prod)
.region("us-west-1")
.build();
MetricsReporter reporter = createReporter(tester.controller());
Application app = tester.createApplication("app1", "tenant1", 1, 11L);
// Initial deployment without failures
tester.deployCompletely(app, applicationPackage);
reporter.maintain();
assertEquals(0, getDeploymentsFailingUpgrade(app.id().defaultInstance()));
// Failing application change is not counted
tester.jobCompletion(component).application(app).nextBuildNumber().uploadArtifact(applicationPackage).submit();
tester.deployAndNotify(app.id().defaultInstance(), Optional.of(applicationPackage), false, systemTest);
reporter.maintain();
assertEquals(0, getDeploymentsFailingUpgrade(app.id().defaultInstance()));
// Application change completes
tester.deployAndNotify(app.id().defaultInstance(), Optional.of(applicationPackage), true, systemTest);
tester.deployAndNotify(app.id().defaultInstance(), Optional.of(applicationPackage), true, stagingTest);
tester.deployAndNotify(app.id().defaultInstance(), Optional.of(applicationPackage), true, productionUsWest1);
assertFalse("Change deployed", tester.controller().applications().requireApplication(app.id()).change().hasTargets());
// New versions is released and upgrade fails in test environments
Version version = Version.fromString("7.1");
tester.upgradeSystem(version);
tester.upgrader().maintain();
tester.deployAndNotify(app.id().defaultInstance(), Optional.of(applicationPackage), false, systemTest);
tester.deployAndNotify(app.id().defaultInstance(), Optional.of(applicationPackage), false, stagingTest);
reporter.maintain();
assertEquals(2, getDeploymentsFailingUpgrade(app.id().defaultInstance()));
// Test and staging pass and upgrade fails in production
tester.deployAndNotify(app.id().defaultInstance(), Optional.of(applicationPackage), true, systemTest);
tester.deployAndNotify(app.id().defaultInstance(), Optional.of(applicationPackage), true, stagingTest);
tester.deployAndNotify(app.id().defaultInstance(), Optional.of(applicationPackage), false, productionUsWest1);
reporter.maintain();
assertEquals(1, getDeploymentsFailingUpgrade(app.id().defaultInstance()));
// Upgrade eventually succeeds
tester.deployAndNotify(app.id().defaultInstance(), Optional.of(applicationPackage), true, productionUsWest1);
assertFalse("Upgrade deployed", tester.controller().applications().requireApplication(app.id()).change().hasTargets());
reporter.maintain();
assertEquals(0, getDeploymentsFailingUpgrade(app.id().defaultInstance()));
}
@Test
public void test_deployment_warnings_metric() {
DeploymentTester tester = new DeploymentTester();
ApplicationPackage applicationPackage = new ApplicationPackageBuilder()
.environment(Environment.prod)
.region("us-west-1")
.region("us-east-3")
.build();
MetricsReporter reporter = createReporter(tester.controller());
Application application = tester.createApplication("app1", "tenant1", 1, 11L);
tester.configServer().generateWarnings(new DeploymentId(application.id().defaultInstance(), ZoneId.from("prod", "us-west-1")), 3);
tester.configServer().generateWarnings(new DeploymentId(application.id().defaultInstance(), ZoneId.from("prod", "us-east-3")), 4);
tester.deployCompletely(application, applicationPackage);
reporter.maintain();
assertEquals(4, getDeploymentWarnings(application.id().defaultInstance()));
}
@Test
public void test_build_time_reporting() {
InternalDeploymentTester tester = new InternalDeploymentTester();
ApplicationVersion version = tester.deployNewSubmission();
assertEquals(1000, version.buildTime().get().toEpochMilli());
MetricsReporter reporter = createReporter(tester.tester().controller());
reporter.maintain();
assertEquals(tester.clock().instant().getEpochSecond() - 1,
getMetric(MetricsReporter.DEPLOYMENT_BUILD_AGE_SECONDS, tester.instance().id()));
}
@Test
public void test_name_service_queue_size_metric() {
DeploymentTester tester = new DeploymentTester(new ControllerTester(), false);
ApplicationPackage applicationPackage = new ApplicationPackageBuilder()
.environment(Environment.prod)
.globalServiceId("default")
.region("us-west-1")
.region("us-east-3")
.build();
MetricsReporter reporter = createReporter(tester.controller());
Application application = tester.createApplication("app1", "tenant1", 1, 11L);
reporter.maintain();
assertEquals("Queue is empty initially", 0, metrics.getMetric(MetricsReporter.NAME_SERVICE_REQUESTS_QUEUED).intValue());
tester.deployCompletely(application, applicationPackage);
reporter.maintain();
assertEquals("Deployment queues name services requests", 6, metrics.getMetric(MetricsReporter.NAME_SERVICE_REQUESTS_QUEUED).intValue());
tester.flushDnsRequests();
reporter.maintain();
assertEquals("Queue consumed", 0, metrics.getMetric(MetricsReporter.NAME_SERVICE_REQUESTS_QUEUED).intValue());
}
@Test
public void test_nodes_failing_system_upgrade() {
var tester = new DeploymentTester();
var reporter = createReporter(tester.controller());
var zone1 = ZoneApiMock.fromId("prod.eu-west-1");
tester.controllerTester().zoneRegistry().setUpgradePolicy(UpgradePolicy.create().upgrade(zone1));
var systemUpgrader = new SystemUpgrader(tester.controller(), Duration.ofDays(1),
new JobControl(tester.controllerTester().curator()));
tester.configServer().bootstrap(List.of(zone1.getId()), SystemApplication.configServer);
// System on initial version
var version0 = Version.fromString("7.0");
tester.upgradeSystem(version0);
reporter.maintain();
assertEquals(0, getNodesFailingUpgrade());
for (var version : List.of(Version.fromString("7.1"), Version.fromString("7.2"))) {
// System starts upgrading to next version
tester.upgradeController(version);
reporter.maintain();
assertEquals(0, getNodesFailingUpgrade());
systemUpgrader.maintain();
// 30 minutes pass and nothing happens
tester.clock().advance(Duration.ofMinutes(30));
tester.computeVersionStatus();
reporter.maintain();
assertEquals(0, getNodesFailingUpgrade());
// 1/3 nodes upgrade within timeout
tester.configServer().setVersion(SystemApplication.configServer.id(), zone1.getId(), version, 1);
tester.clock().advance(Duration.ofMinutes(30).plus(Duration.ofSeconds(1)));
tester.computeVersionStatus();
reporter.maintain();
assertEquals(2, getNodesFailingUpgrade());
// 3/3 nodes upgrade
tester.configServer().setVersion(SystemApplication.configServer.id(), zone1.getId(), version);
tester.computeVersionStatus();
reporter.maintain();
assertEquals(0, getNodesFailingUpgrade());
assertEquals(version, tester.controller().systemVersion());
}
}
private Duration getAverageDeploymentDuration(ApplicationId id) {
return Duration.ofSeconds(getMetric(MetricsReporter.DEPLOYMENT_AVERAGE_DURATION, id).longValue());
}
private int getDeploymentsFailingUpgrade(ApplicationId id) {
return getMetric(MetricsReporter.DEPLOYMENT_FAILING_UPGRADES, id).intValue();
}
private int getDeploymentWarnings(ApplicationId id) {
return getMetric(MetricsReporter.DEPLOYMENT_WARNINGS, id).intValue();
}
private int getNodesFailingUpgrade() {
return metrics.getMetric(MetricsReporter.NODES_FAILING_SYSTEM_UPGRADE).intValue();
}
private Number getMetric(String name, ApplicationId id) {
return metrics.getMetric((dimensions) -> id.tenant().value().equals(dimensions.get("tenant")) &&
appDimension(id).equals(dimensions.get("app")),
name)
.orElseThrow(() -> new RuntimeException("Expected metric to exist for " + id));
}
private MetricsReporter createReporter(Controller controller) {
return new MetricsReporter(controller, metrics, new JobControl(new MockCuratorDb()));
}
private static String appDimension(ApplicationId id) {
return id.application().value() + "." + id.instance().value();
}
}
|