1
+ /*
2
+ * Copyright 2015 Red Hat, Inc. and/or its affiliates
3
+ * and other contributors as indicated by the @author tags.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ package org .hawkular .client .test .metrics .openshift ;
18
+
19
+ import java .util .Collections ;
20
+ import java .util .List ;
21
+ import java .util .stream .Collectors ;
22
+
23
+ import org .hawkular .client .metrics .model .MetricDefinition ;
24
+ import org .testng .Assert ;
25
+ import org .testng .Reporter ;
26
+ import org .testng .annotations .Test ;
27
+
28
+ import com .google .common .collect .ImmutableList ;
29
+
30
+ /**
31
+ * Verify container metric definitions<p>
32
+ * Test expects 1-container pod
33
+ * @author vnguyen
34
+ *
35
+ */
36
+ @ Test (groups ={"openshift" })
37
+ public class MetricDefinitionTest extends OpenshiftBaseTest {
38
+
39
+ private static final List <String > expectedMetricIDs = ImmutableList .of (
40
+ "memory/page_faults" ,
41
+ "cpu/usage" ,
42
+ "memory/usage" ,
43
+ "memory/major_page_faults" ,
44
+ "memory/working_set" ,
45
+ "cpu/limit" ,
46
+ "uptime" ,
47
+ "memory/limit" );
48
+
49
+ public MetricDefinitionTest () throws Exception {
50
+ super ();
51
+ }
52
+
53
+ @ Test
54
+ public void verifyMetricDefinitionForPod () {
55
+ String project = "default" ;
56
+ String container = "hawkular-metrics" ;
57
+
58
+ String type = null ; // ignore metric type
59
+ String tags = "container_name:" + container + ",pod_namespace:" + project ;
60
+ List <MetricDefinition > defs = client ().metrics ().findMetricDefinitions (
61
+ OpenshiftBaseTest .TENANT_ID ,
62
+ type ,
63
+ tags );
64
+ Reporter .log (defs .toString (), true );
65
+
66
+ Assert .assertTrue (defs != null && defs .size () == expectedMetricIDs .size ());
67
+
68
+ // collect all metric IDs
69
+ List <String > metricIDs = defs .stream ()
70
+ .map (x -> x .getId ())
71
+ .collect (Collectors .toList ());
72
+
73
+ Reporter .log (metricIDs .toString (), true );
74
+
75
+ // pad expected metric id with container name + pod id
76
+ String podId = defs .get (0 ).getTags ().get ("pod_id" );
77
+ String idPrefix = container + "/" + podId + "/" ;
78
+ List <String > expectedIDs = expectedMetricIDs
79
+ .stream ()
80
+ .map (item -> idPrefix + item )
81
+ .collect (Collectors .toList ());
82
+ Collections .sort (metricIDs );
83
+ Collections .sort (expectedIDs );
84
+
85
+ Assert .assertEquals (metricIDs , expectedIDs );
86
+ }
87
+
88
+ @ Test
89
+ public void verifyTags () {
90
+ //TBD
91
+ }
92
+ }
0 commit comments