21
21
import java .net .Authenticator ;
22
22
import java .net .PasswordAuthentication ;
23
23
import java .net .URL ;
24
- import java .util .Arrays ;
25
24
import java .util .List ;
26
25
import java .util .Map ;
27
26
import javax .xml .bind .DatatypeConverter ;
@@ -56,22 +55,16 @@ public class ITMonitoringExporter extends BaseTest {
56
55
"weblogic_servlet_invocation_total_count{app=\" testwsapp\" ,name=\" managed-server1_/TestWSApp\" ,servletName=\" TestWSAppServlethttp\" }" ;
57
56
private static String testWSAppTotalServletInvokesSearchKey2 =
58
57
"weblogic_servlet_invocation_total_count{app=\" testwsapp\" ,name=\" managed-server2_/TestWSApp\" ,servletName=\" TestWSAppServlethttp\" }" ;
59
- private static String [] testWSAppTotalServletInvokesSearchKey = {
60
- "weblogic_servlet_invocation_total_count{app=\" testwsapp\" ,name=\" managed-server" ,
61
- "_/TestWSApp\" ,servletName=\" TestWSAppServlethttp\" }"
62
- };
63
- String oprelease = "op" + number ;
64
- private int waitTime = 5 ;
65
- private int maxIterations = 30 ;
66
58
private static String loadBalancer = "TRAEFIK" ;
67
- // private static String prometheusSearchKey1 = "curl --noproxy '*' -X GET
68
- // http://slc13kef.us.oracle.com:32000/api/v1/query?query=heap_free_current%7Bname%3D%22managed-server2%22%7D";
69
59
private static String prometheusSearchKey1 =
70
60
"heap_free_current%7Bname%3D%22managed-server1%22%7D" ;
71
61
private static String prometheusSearchKey2 =
72
62
"heap_free_current%7Bname%3D%22managed-server2%22%7D" ;
73
63
private static String testwsappPrometheusSearchKey =
74
64
"weblogic_servlet_invocation_total_count%7Bapp%3D%22testwsapp%22%7D" ;
65
+ String oprelease = "op" + number ;
66
+ private int waitTime = 5 ;
67
+ private int maxIterations = 30 ;
75
68
76
69
/**
77
70
* This method gets called only once before any of the test methods are executed. It does the
@@ -84,7 +77,6 @@ public class ITMonitoringExporter extends BaseTest {
84
77
public static void staticPrepare () throws Exception {
85
78
if (!QUICKTEST ) {
86
79
initialize (APP_PROPS_FILE );
87
-
88
80
logger .info ("Checking if operator and domain are running, if not creating" );
89
81
if (operator == null ) {
90
82
Map <String , Object > operatorMap = TestUtils .createOperatorMap (number , true );
@@ -96,7 +88,6 @@ public static void staticPrepare() throws Exception {
96
88
domain = createVerifyDomain (number , operator );
97
89
Assert .assertNotNull (domain );
98
90
}
99
-
100
91
myhost = domain .getHostNameForCurl ();
101
92
exporterUrl = "http://" + myhost + ":" + domain .getLoadBalancerWebPort () + "/wls-exporter/" ;
102
93
metricsUrl = exporterUrl + "metrics" ;
@@ -138,7 +129,6 @@ public static void staticUnPrepare() throws Exception {
138
129
*/
139
130
private static void deployRunMonitoringExporter (Domain domain , Operator operator )
140
131
throws Exception {
141
-
142
132
TestUtils .gitCloneBuildMonitoringExporter ();
143
133
logger .info ("Creating Operator & waiting for the script to complete execution" );
144
134
boolean testCompletedSuccessfully = false ;
@@ -164,37 +154,8 @@ private static Domain createVerifyDomain(int number, Operator operator) throws E
164
154
return domain ;
165
155
}
166
156
167
- /**
168
- * call webapp and verify load balancing by checking server name in the response
169
- *
170
- * @param searchKey - metric query expression
171
- * @param expectedVal - expected metrics to search
172
- * @throws Exception
173
- */
174
- public boolean checkMetricsViaPrometheus (String searchKey , String expectedVal ) throws Exception {
175
-
176
- // sleep 15 secs to scrap metrics
177
- Thread .sleep (15 * 1000 );
178
- // url
179
- StringBuffer testAppUrl = new StringBuffer ("http://" );
180
- testAppUrl .append (myhost ).append (":" ).append ("32000" ).append ("/api/v1/query?query=" );
181
-
182
- testAppUrl .append (searchKey );
183
- // curl cmd to call webapp
184
- StringBuffer curlCmd = new StringBuffer ("curl --noproxy '*' " );
185
- curlCmd .append (testAppUrl .toString ());
186
- logger .info ("Curl cmd " + curlCmd );
187
- ExecResult result = ExecCommand .exec (curlCmd .toString ());
188
- logger .info ("Prometheus application invoked successfully with curlCmd:" + curlCmd );
189
-
190
- String checkPrometheus = result .stdout ().trim ();
191
- logger .info ("Result :" + checkPrometheus );
192
- return checkPrometheus .contains (expectedVal );
193
- }
194
-
195
157
private static void startExporterPrometheusGrafana (Domain domain , Operator operator )
196
158
throws Exception {
197
-
198
159
logger .info ("deploy exporter, prometheus, grafana " );
199
160
TestUtils .deployMonitoringExporterPrometethusGrafana (
200
161
TestUtils .monitoringDir + "/apps/monitoringexporter/wls-exporter.war" , domain , operator );
@@ -214,7 +175,7 @@ private static Object getMetricsValue(BufferedReader contents, String metricKey)
214
175
return result ;
215
176
}
216
177
217
- public static boolean containsWordsIndexOf (String inputString , String [] words ) {
178
+ private static boolean containsWordsIndexOf (String inputString , String [] words ) {
218
179
boolean found = true ;
219
180
for (String word : words ) {
220
181
logger .info (" Checking inputString" + inputString + " word " + word );
@@ -272,7 +233,34 @@ private static void upgradeTraefikHostName() throws Exception {
272
233
}
273
234
274
235
/**
275
- * Replace monitoring exporter configuration and verify it was applied to both managed servers
236
+ * call webapp and verify load balancing by checking server name in the response
237
+ *
238
+ * @param searchKey - metric query expression
239
+ * @param expectedVal - expected metrics to search
240
+ * @throws Exception
241
+ */
242
+ private boolean checkMetricsViaPrometheus (String searchKey , String expectedVal ) throws Exception {
243
+ // sleep 15 secs to scrap metrics
244
+ Thread .sleep (15 * 1000 );
245
+ // url
246
+ StringBuffer testAppUrl = new StringBuffer ("http://" );
247
+ testAppUrl .append (myhost ).append (":" ).append ("32000" ).append ("/api/v1/query?query=" );
248
+
249
+ testAppUrl .append (searchKey );
250
+ // curl cmd to call webapp
251
+ StringBuffer curlCmd = new StringBuffer ("curl --noproxy '*' " );
252
+ curlCmd .append (testAppUrl .toString ());
253
+ logger .info ("Curl cmd " + curlCmd );
254
+ ExecResult result = ExecCommand .exec (curlCmd .toString ());
255
+ logger .info ("Prometheus application invoked successfully with curlCmd:" + curlCmd );
256
+
257
+ String checkPrometheus = result .stdout ().trim ();
258
+ logger .info ("Result :" + checkPrometheus );
259
+ return checkPrometheus .contains (expectedVal );
260
+ }
261
+
262
+ /**
263
+ * Check that configuration can be reviewed via Prometheus
276
264
*
277
265
* @throws Exception
278
266
*/
@@ -300,16 +288,6 @@ public void test02_ReplaceConfiguration() throws Exception {
300
288
logTestBegin (testMethodName );
301
289
boolean testCompletedSuccessfully = false ;
302
290
303
- /*
304
- exporterUrl = "http://slc13kef.us.oracle.com:" + "30305" + "/wls-exporter/";
305
- metricsUrl = exporterUrl + "metrics";
306
- configPath =
307
- "/scratch/mkogan/weblogic-kubernetes-operator/integration-tests/src/test/resources/exporter";
308
- String testWSAppTotalServletInvokesSearchKey1 =
309
- "weblogic_servlet_invocation_total_count{app=\"testwsapp\",name=\"managed-server1_/TestWSApp\",servletName=\"TestWSAppServlethttp\"}";
310
- String testWSAppTotalServletInvokesSearchKey2 =
311
- "weblogic_servlet_invocation_total_count{app=\"testwsapp\",name=\"managed-server2_/TestWSApp\",servletName=\"TestWSAppServlethttp\"}";
312
- */
313
291
HtmlPage page = submitConfigureForm (exporterUrl , "replace" , configPath + "/rest_jvm.yml" );
314
292
315
293
// check for updated metrics
@@ -357,7 +335,6 @@ public void test02_ReplaceConfiguration() throws Exception {
357
335
*/
358
336
@ Test
359
337
public void test03_AppendConfiguration () throws Exception {
360
-
361
338
Assume .assumeFalse (QUICKTEST );
362
339
String testMethodName = new Object () {}.getClass ().getEnclosingMethod ().getName ();
363
340
logTestBegin (testMethodName );
@@ -366,7 +343,7 @@ public void test03_AppendConfiguration() throws Exception {
366
343
HtmlPage page = submitConfigureForm (exporterUrl , "replace" , configPath + "/rest_jvm.yml" );
367
344
assertTrue (page .asText ().contains ("JVMRuntime" ));
368
345
assertFalse (page .asText ().contains ("WebAppComponentRuntime" ));
369
- // run append more
346
+ // run append
370
347
page = submitConfigureForm (exporterUrl , "append" , configPath + "/rest_webapp.yml" );
371
348
assertTrue (page .asText ().contains ("WebAppComponentRuntime" ));
372
349
// check previous config is there
@@ -389,7 +366,6 @@ public void test03_AppendConfiguration() throws Exception {
389
366
*/
390
367
@ Test
391
368
public void test04_ReplaceOneAttributeValueAsArrayConfiguration () throws Exception {
392
-
393
369
Assume .assumeFalse (QUICKTEST );
394
370
String testMethodName = new Object () {}.getClass ().getEnclosingMethod ().getName ();
395
371
logTestBegin (testMethodName );
@@ -412,7 +388,6 @@ public void test04_ReplaceOneAttributeValueAsArrayConfiguration() throws Excepti
412
388
@ Test
413
389
public void test05_AppendArrayWithOneExistedAndOneDifferentAttributeValueAsArrayConfiguration ()
414
390
throws Exception {
415
-
416
391
Assume .assumeFalse (QUICKTEST );
417
392
String testMethodName = new Object () {}.getClass ().getEnclosingMethod ().getName ();
418
393
logTestBegin (testMethodName );
@@ -680,7 +655,6 @@ public void test13_ReplaceMetricsNameSnakeCaseFalseConfiguration() throws Except
680
655
@ Test
681
656
public void test14_AppendMetricsNameSnakeCaseTrueToSnakeCaseFalseConfiguration ()
682
657
throws Exception {
683
-
684
658
Assume .assumeFalse (QUICKTEST );
685
659
String testMethodName = new Object () {}.getClass ().getEnclosingMethod ().getName ();
686
660
logTestBegin (testMethodName );
@@ -824,14 +798,6 @@ private void changeConfigNegativeAuth(
824
798
}
825
799
}
826
800
827
- private Object getMetricsFromPage (String testUrl , String ... args ) throws Exception {
828
- Authenticator .setDefault (new MyTestAuthenticator ());
829
- InputStream stream = new URL (testUrl ).openStream ();
830
- BufferedReader contents = new BufferedReader (new InputStreamReader (stream ));
831
- assertNotNull (contents );
832
- return getMetricsValue (contents , args );
833
- }
834
-
835
801
private Object getMetricsFromPage (String testUrl , String searchKey ) throws Exception {
836
802
Authenticator .setDefault (new MyTestAuthenticator ());
837
803
InputStream stream = new URL (testUrl ).openStream ();
@@ -858,7 +824,6 @@ private HtmlPage submitConfigureForm(String exporterUrl, String effect, String c
858
824
859
825
private HtmlPage submitConfigureForm (
860
826
String exporterUrl , String effect , String configFile , WebClient webClient ) throws Exception {
861
-
862
827
// Get the first page
863
828
final HtmlPage page1 = webClient .getPage (exporterUrl );
864
829
assertNotNull (page1 );
@@ -913,26 +878,6 @@ private boolean checkMetrics(String searchKey) throws Exception {
913
878
}
914
879
return result ;
915
880
}
916
-
917
- private boolean checkMetrics (String ... searchKeys ) throws Exception {
918
- boolean result = false ;
919
- int i = 0 ;
920
- while (i < maxIterations ) {
921
- Object searchResult = getMetricsFromPage (metricsUrl , searchKeys );
922
- if (searchResult == null ) {
923
- // check for last iteration
924
- if (i == (BaseTest .getMaxIterationsPod () - 1 )) {
925
- return false ;
926
- }
927
- i ++;
928
- } else {
929
- logger .info ("Found value for metric " + Arrays .toString (searchKeys ) + " : " + searchResult );
930
- result = true ;
931
- break ;
932
- }
933
- }
934
- return result ;
935
- }
936
881
}
937
882
938
883
class MyTestAuthenticator extends Authenticator {
0 commit comments