-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master'
- Loading branch information
Showing
11 changed files
with
448 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
src/test/java/org/hawkular/client/test/metrics/openshift/CollectionRateDetailTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* Copyright 2015 Red Hat, Inc. and/or its affiliates | ||
* and other contributors as indicated by the @author tags. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.hawkular.client.test.metrics.openshift; | ||
|
||
import java.time.Duration; | ||
import java.time.Instant; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
import org.apache.commons.lang3.ArrayUtils; | ||
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; | ||
import org.hawkular.client.metrics.model.GaugeDataPoint; | ||
import org.testng.Assert; | ||
import org.testng.Reporter; | ||
import org.testng.annotations.Test; | ||
|
||
/** | ||
*Find value=0 datapoints | ||
* @author vnguyen | ||
*/ | ||
@Test(groups={"openshift"}) | ||
public class CollectionRateDetailTest extends OpenshiftBaseTest { | ||
|
||
public CollectionRateDetailTest() throws Exception { | ||
super(); | ||
} | ||
|
||
@Test | ||
public void findZeroValuesTest() throws Exception { | ||
String project = "zproject9"; | ||
String container = "stress"; | ||
String testID = "namespace: " + project + ", container: " + container; | ||
|
||
// for easy identification in the log | ||
String metricID = super.getMetricID(project, container, METRIC_SUFFIX.CPU_USAGE); | ||
|
||
// Get a lot of data in the last few days | ||
long now = Instant.now().toEpochMilli(); | ||
long start = now - Duration.ofHours(36).toMillis(); | ||
long end = start + Duration.ofHours(36).toMillis(); | ||
|
||
Duration timeBucket = Duration.ofHours(1); | ||
getData(metricID, testID, start, end, timeBucket); | ||
|
||
// get data in the last hour | ||
start = now - Duration.ofHours(1).toMillis(); | ||
end = now; | ||
timeBucket = Duration.ofMinutes(1); | ||
getData(metricID, testID, start, end, timeBucket); | ||
} | ||
|
||
private void getData(String metricID, String testID, long start, long end, Duration timeBucket) { | ||
Reporter.log("Fetching large data set... may take a couple minutes", true); | ||
List<GaugeDataPoint> rawData = client().metrics().getGaugeData(TENANT_ID, metricID, start, end); | ||
|
||
Assert.assertNotNull(rawData, testID); | ||
Reporter.log("raw datapoints: " + rawData.size(), true); | ||
|
||
List<Long> zeroList = findZeroValues(rawData); | ||
|
||
Assert.assertTrue(zeroList == null || zeroList.size() == 0, testID); | ||
|
||
Map<Long, Integer> hist = OpenshiftBaseTest.makeHistogram(rawData, timeBucket); | ||
|
||
Double[] result = hist.entrySet().stream() | ||
.map(x -> new Double(x.getValue())) | ||
.toArray(size -> new Double[size]); | ||
|
||
double[] d = ArrayUtils.toPrimitive(result); | ||
|
||
// drop the first and last as they are usually outliers | ||
double samples[] = Arrays.copyOfRange(d,1, d.length-1); | ||
DescriptiveStatistics stats = new DescriptiveStatistics(samples); | ||
|
||
Reporter.log(hist.toString(), true); | ||
Reporter.log("size: " + stats.getN(), true); | ||
Reporter.log("min/max: " + stats.getMin() + "/" + stats.getMax(), true); | ||
Reporter.log("mean: " + stats.getMean(), true); | ||
Reporter.log("variance: " + stats.getVariance(), true); | ||
Reporter.log("stddev: " + stats.getStandardDeviation(), true); | ||
} | ||
|
||
private List<Long> findZeroValues(List<GaugeDataPoint> rawData) { | ||
List<Long> zeroList = rawData | ||
.stream() | ||
.filter(p -> !(p.getValue() != 0)) | ||
.map(p -> p.getTimestamp()) | ||
.collect(Collectors.toList()); | ||
return zeroList; | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
src/test/java/org/hawkular/client/test/metrics/openshift/MetricDefinitionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Copyright 2015 Red Hat, Inc. and/or its affiliates | ||
* and other contributors as indicated by the @author tags. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.hawkular.client.test.metrics.openshift; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import org.hawkular.client.metrics.model.MetricDefinition; | ||
import org.testng.Assert; | ||
import org.testng.Reporter; | ||
import org.testng.annotations.Test; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
|
||
/** | ||
* Verify container metric definitions<p> | ||
* Test expects 1-container pod | ||
* @author vnguyen | ||
* | ||
*/ | ||
@Test(groups={"openshift"}) | ||
public class MetricDefinitionTest extends OpenshiftBaseTest { | ||
|
||
private static final List<String> expectedMetricIDs = ImmutableList.of( | ||
"memory/page_faults", | ||
"cpu/usage", | ||
"memory/usage", | ||
"memory/major_page_faults", | ||
"memory/working_set", | ||
"cpu/limit", | ||
"uptime", | ||
"memory/limit"); | ||
|
||
public MetricDefinitionTest() throws Exception { | ||
super(); | ||
} | ||
|
||
@Test | ||
public void verifyMetricDefinitionForPod() { | ||
String project = "default"; | ||
String container = "hawkular-metrics"; | ||
|
||
String type = null; // ignore metric type | ||
String tags = "container_name:" + container + ",pod_namespace:" + project; | ||
List<MetricDefinition> defs = client().metrics().findMetricDefinitions( | ||
OpenshiftBaseTest.TENANT_ID, | ||
type, | ||
tags); | ||
Reporter.log(defs.toString(), true); | ||
|
||
Assert.assertTrue(defs != null && defs.size() == expectedMetricIDs.size()); | ||
|
||
// collect all metric IDs | ||
List<String> metricIDs = defs.stream() | ||
.map(x -> x.getId()) | ||
.collect(Collectors.toList()); | ||
|
||
Reporter.log(metricIDs.toString(), true); | ||
|
||
// pad expected metric id with container name + pod id | ||
String podId = defs.get(0).getTags().get("pod_id"); | ||
String idPrefix = container + "/" + podId + "/"; | ||
List<String> expectedIDs = expectedMetricIDs | ||
.stream() | ||
.map(item -> idPrefix + item) | ||
.collect(Collectors.toList()); | ||
Collections.sort(metricIDs); | ||
Collections.sort(expectedIDs); | ||
|
||
Assert.assertEquals(metricIDs, expectedIDs); | ||
} | ||
|
||
@Test | ||
public void verifyTags() { | ||
//TBD | ||
} | ||
} |
Oops, something went wrong.