|
1 | 1 | package io.prometheus.wls.rest.domain;
|
2 | 2 | /*
|
3 |
| - * Copyright (c) 2017, 2019, Oracle Corporation and/or its affiliates. All rights reserved. |
| 3 | + * Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. All rights reserved. |
4 | 4 | *
|
5 | 5 | * Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
|
6 | 6 | */
|
7 | 7 |
|
| 8 | +import java.util.Arrays; |
| 9 | +import java.util.HashMap; |
| 10 | +import java.util.Map; |
| 11 | + |
8 | 12 | import com.google.gson.JsonObject;
|
9 | 13 | import com.google.gson.JsonParser;
|
10 | 14 | import org.hamcrest.Description;
|
11 | 15 | import org.hamcrest.TypeSafeDiagnosingMatcher;
|
12 | 16 | import org.junit.Test;
|
13 | 17 | import org.yaml.snakeyaml.Yaml;
|
14 | 18 |
|
15 |
| -import java.util.HashMap; |
16 |
| -import java.util.Map; |
17 |
| - |
18 | 19 | import static io.prometheus.wls.rest.domain.ExporterConfigTest.QueryHierarchyMatcher.hasQueryFor;
|
19 | 20 | import static io.prometheus.wls.rest.domain.MetricMatcher.hasMetric;
|
20 | 21 | import static org.hamcrest.MatcherAssert.assertThat;
|
21 |
| -import static org.hamcrest.Matchers.*; |
| 22 | +import static org.hamcrest.Matchers.arrayWithSize; |
| 23 | +import static org.hamcrest.Matchers.containsString; |
| 24 | +import static org.hamcrest.Matchers.emptyArray; |
| 25 | +import static org.hamcrest.Matchers.equalTo; |
| 26 | +import static org.hamcrest.Matchers.equalToIgnoringWhiteSpace; |
| 27 | +import static org.hamcrest.Matchers.is; |
| 28 | +import static org.hamcrest.Matchers.not; |
| 29 | +import static org.hamcrest.Matchers.notNullValue; |
| 30 | +import static org.hamcrest.Matchers.nullValue; |
| 31 | +import static org.hamcrest.Matchers.sameInstance; |
22 | 32 |
|
23 | 33 | /**
|
24 | 34 | * @author Russell Gold
|
@@ -500,15 +510,32 @@ public void afterScrapingServerConfig_hasDomainName() {
|
500 | 510 | public void afterScrapingMetricsIncludeDomainNameQualifier() {
|
501 | 511 | ExporterConfig exporterConfig = loadFromString(DOMAIN_QUALIFIER_CONFIG);
|
502 | 512 |
|
503 |
| - Map<String, Object> metrics = new HashMap<>(); |
504 |
| - metrics.putAll(exporterConfig.scrapeMetrics(exporterConfig.getEffectiveQueries()[0], getJsonResponse(CONFIG_RESPONSE))); |
505 |
| - metrics.putAll(exporterConfig.scrapeMetrics(exporterConfig.getEffectiveQueries()[1], getJsonResponse(WORK_MANAGER_RESPONSE))); |
| 513 | + Map<String, Object> metrics = getMetrics(exporterConfig); |
506 | 514 |
|
507 | 515 | assertThat(metrics, hasMetric("workmanager_pendingRequests{domain=\"mydomain\",applicationName=\"thisOne\"}", 2));
|
508 | 516 | assertThat(metrics, hasMetric("workmanager_completedRequests{domain=\"mydomain\",applicationName=\"thisOne\"}", 15));
|
509 | 517 | assertThat(metrics, hasMetric("workmanager_stuckThreadCount{domain=\"mydomain\",applicationName=\"thisOne\"}", 3));
|
510 | 518 | }
|
511 | 519 |
|
| 520 | + private Map<String, Object> getMetrics(ExporterConfig exporterConfig) { |
| 521 | + Map<String, Object> metrics = new HashMap<>(); |
| 522 | + Arrays.stream(exporterConfig.getEffectiveQueries()) |
| 523 | + .forEach(q -> metrics.putAll(exporterConfig.scrapeMetrics(q, getJsonResponse(getResponse(q))))); |
| 524 | + return metrics; |
| 525 | + } |
| 526 | + |
| 527 | + private String getResponse(MBeanSelector selector) { |
| 528 | + return selector.acceptsStrings() ? CONFIG_RESPONSE : WORK_MANAGER_RESPONSE; |
| 529 | + } |
| 530 | + |
| 531 | + @Test |
| 532 | + public void secondScrapeWithDomainQualifierDoesNotAddStringMetric() { |
| 533 | + ExporterConfig exporterConfig = loadFromString(DOMAIN_QUALIFIER_CONFIG); |
| 534 | + getMetrics(exporterConfig); |
| 535 | + |
| 536 | + assertThat(getMetrics(exporterConfig).values().stream().anyMatch(v -> v instanceof String), is(false)); |
| 537 | + } |
| 538 | + |
512 | 539 | private static final String DOMAIN_QUALIFIER_CONFIG =
|
513 | 540 | ExporterConfig.DOMAIN_QUALIFIER + ": true\n" +
|
514 | 541 | "queries:\n" +
|
|
0 commit comments