101
101
@ Tag ("oke-sequential" )
102
102
@ Tag ("kind-parallel" )
103
103
public class ItHorizontalPodAutoscalerCustomMetrics {
104
- private static String domainNamespace = null ;
105
- static int replicaCount = 2 ;
106
- static String wlClusterName = "cluster-1" ;
107
- static String clusterResName = "hpacustomcluster" ;
108
-
109
- private static String adminSecretName ;
110
- private static String encryptionSecretName ;
104
+ private static final String MONEXP_MODEL_FILE = "model.monexp.custommetrics.yaml" ;
105
+ private static final String MONEXP_IMAGE_NAME = "monexp-image" ;
106
+ private static final String SESSMIGR_APP_NAME = "sessmigr-app" ;
107
+ private static final String SESSMIGR_APP_WAR_NAME = "sessmigr-war" ;
108
+ private static final String SESSMIGT_APP_URL = SESSMIGR_APP_WAR_NAME + "/?getCounter" ;
111
109
private static final String domainUid = "hpacustomdomain" ;
110
+
111
+ private static String domainNamespace = null ;
112
+ private static String wlClusterName = "cluster-1" ;
113
+ private static String clusterResName = "hpacustomcluster" ;
112
114
private static String adminServerPodName = String .format ("%s-%s" , domainUid , ADMIN_SERVER_NAME_BASE );
113
115
private static String managedServerPrefix = String .format ("%s-%s-%s" ,
114
116
domainUid , wlClusterName , MANAGED_SERVER_NAME_BASE );
115
- static DomainResource domain = null ;
116
-
117
- private static String opServiceAccount = null ;
118
- private static String opNamespace = null ;
119
-
120
117
private static LoggingFacade logger = null ;
121
118
private static String monitoringExporterDir ;
122
- private static String monitoringExporterSrcDir ;
123
- private static String monitoringExporterAppDir ;
124
119
private static NginxParams nginxHelmParams = null ;
125
120
private static int nodeportshttp = 0 ;
126
- private static String nginxNamespace = null ;
127
- private static final String MONEXP_MODEL_FILE = "model.monexp.yaml" ;
128
- private static final String MONEXP_IMAGE_NAME = "monexp-image" ;
129
- private static final String SESSMIGR_APP_NAME = "sessmigr-app" ;
130
- private static final String SESSMIGR_APP_WAR_NAME = "sessmigr-war" ;
131
- private static final String SESSMIGT_APP_URL = SESSMIGR_APP_WAR_NAME + "/?getCounter" ;
132
121
private static String monitoringNS = null ;
133
- static PrometheusParams promHelmParams = null ;
122
+ private static PrometheusParams promHelmParams = null ;
134
123
private static String releaseSuffix = "hpatest" ;
135
124
private static String prometheusReleaseName = "prometheus" + releaseSuffix ;
136
125
private static String prometheusAdapterReleaseName = "prometheus-adapter" + releaseSuffix ;
137
- private static String hostPortPrometheus = null ;
138
126
private static String prometheusDomainRegexValue = null ;
139
127
private static int nodeportPrometheus ;
140
128
private Path targetHPAFile ;
@@ -150,13 +138,14 @@ public class ItHorizontalPodAutoscalerCustomMetrics {
150
138
@ BeforeAll
151
139
public static void initAll (@ Namespaces (4 ) List <String > namespaces ) {
152
140
logger = getLogger ();
153
- monitoringExporterDir = Paths .get (RESULTS_ROOT ,
154
- "ItMonitoringExporterWebApp" , "monitoringexp" ).toString ();
155
- monitoringExporterSrcDir = Paths .get (monitoringExporterDir , "srcdir" ).toString ();
156
- monitoringExporterAppDir = Paths .get (monitoringExporterDir , "apps" ).toString ();
141
+ int replicaCount = 2 ;
142
+ String className = ItHorizontalPodAutoscalerCustomMetrics .class .getSimpleName ();
143
+
144
+ monitoringExporterDir = Paths .get (RESULTS_ROOT , className , "monitoringexp" ).toString ();
145
+ String monitoringExporterAppDir = Paths .get (monitoringExporterDir , "apps" ).toString ();
157
146
logger .info ("Assign a unique namespace for operator" );
158
147
assertNotNull (namespaces .get (0 ), "Namespace is null" );
159
- opNamespace = namespaces .get (0 );
148
+ String opNamespace = namespaces .get (0 );
160
149
161
150
logger .info ("Assign a unique namespace for WebLogic domain" );
162
151
assertNotNull (namespaces .get (1 ), "Namespace is null" );
@@ -165,13 +154,12 @@ public static void initAll(@Namespaces(4) List<String> namespaces) {
165
154
assertNotNull (namespaces .get (2 ), "Namespace list is null" );
166
155
monitoringNS = namespaces .get (2 );
167
156
168
- logger .info ("Get a unique namespace for nginx " );
157
+ logger .info ("Get a unique namespace for Nginx " );
169
158
assertNotNull (namespaces .get (3 ), "Namespace list is null" );
170
- nginxNamespace = namespaces .get (3 );
159
+ String nginxNamespace = namespaces .get (3 );
171
160
172
161
// set the service account name for the operator
173
- opServiceAccount = opNamespace + "-sa" ;
174
-
162
+ String opServiceAccount = opNamespace + "-sa" ;
175
163
// install and verify operator with REST API
176
164
installAndVerifyOperator (opNamespace , opServiceAccount , true , 0 , domainNamespace );
177
165
@@ -182,33 +170,34 @@ public static void initAll(@Namespaces(4) List<String> namespaces) {
182
170
183
171
// create secret for admin credentials
184
172
logger .info ("Create secret for admin credentials" );
185
- adminSecretName = "weblogic-credentials" ;
173
+ String adminSecretName = "weblogic-credentials" ;
186
174
createSecretWithUsernamePassword (adminSecretName , domainNamespace ,
187
175
ADMIN_USERNAME_DEFAULT , ADMIN_PASSWORD_DEFAULT );
188
176
189
177
// create encryption secret
190
178
logger .info ("Create encryption secret" );
191
- encryptionSecretName = "encryptionsecret" ;
179
+ String encryptionSecretName = "encryptionsecret" ;
192
180
createSecretWithUsernamePassword (encryptionSecretName , domainNamespace ,
193
181
"weblogicenc" , "weblogicenc" );
182
+
194
183
logger .info ("install monitoring exporter" );
195
184
installMonitoringExporter (monitoringExporterDir );
185
+
196
186
logger .info ("create and verify WebLogic domain image using model in image with model files" );
197
187
String miiImage = MonitoringUtils .createAndVerifyMiiImage (monitoringExporterAppDir ,
198
188
MODEL_DIR + "/" + MONEXP_MODEL_FILE ,
199
189
SESSMIGR_APP_NAME , MONEXP_IMAGE_NAME );
200
190
HashMap <String , String > labels = new HashMap <>();
201
191
labels .put ("app" , "monitoring" );
202
192
labels .put ("weblogic.domainUid" , "test" );
203
- String className = "ItMonitoringExporterWebApp" ;
204
193
205
194
logger .info ("create pv and pvc for monitoring" );
206
195
assertDoesNotThrow (() -> createPvAndPvc (prometheusReleaseName , monitoringNS , labels , className ));
207
196
assertDoesNotThrow (() -> createPvAndPvc ("alertmanager" + releaseSuffix , monitoringNS , labels , className ));
208
197
cleanupPromGrafanaClusterRoles (prometheusReleaseName , null );
209
198
cleanupPrometheusAdapterClusterRoles ();
210
199
211
- domain = createDomainResource (
200
+ DomainResource domain = createDomainResource (
212
201
domainUid ,
213
202
domainNamespace ,
214
203
miiImage ,
@@ -349,7 +338,7 @@ void testHPAWithCustomMetrics() {
349
338
logger .info ("HPA scaled down managed server 2" );
350
339
--numberOfManagedSvs ;
351
340
} else if (!Kubernetes .doesPodExist (domainNamespace , domainUid , managedServerPrefix + 3 )
352
- || Kubernetes .isPodTerminating (domainNamespace , domainUid , managedServerPrefix + 2 )) {
341
+ || Kubernetes .isPodTerminating (domainNamespace , domainUid , managedServerPrefix + 3 )) {
353
342
logger .info ("HPA scaled down managed server 3" );
354
343
--numberOfManagedSvs ;
355
344
}
@@ -384,9 +373,21 @@ private void createHPA() {
384
373
CommandParams params = new CommandParams ().defaults ();
385
374
params .command (KUBERNETES_CLI + " apply -f " + targetHPAFile );
386
375
ExecResult result = Command .withParams (params ).executeAndReturnResult ();
387
- assertTrue (result .exitValue () == 0 ,
388
- "Failed to create hpa or autoscale, result " + result );
389
- assertTrue (verifyHPA (domainNamespace , "custommetrics-hpa" ));
376
+ assertEquals (0 , result .exitValue (), "Failed to create hpa or autoscale, result " + result );
377
+ /* check if hpa output does not contain <unknown>
378
+ * kubectl get hpa --all-namespaces
379
+ * NAMESPACE NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
380
+ * ns-qsjlcw custommetrics-hpa Cluster/hpacustomcluster 0/5 2 3 2 52s
381
+ *
382
+ * when its not ready, it looks
383
+ * NAMESPACE NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
384
+ * ns-qsjlcw custommetrics-hpa Cluster/hpacustomcluster <unknown>/5 2 4 2 18m
385
+ */
386
+ testUntil (withLongRetryPolicy ,
387
+ () -> verifyHPA (domainNamespace , "custommetrics-hpa" ),
388
+ logger ,
389
+ "hpa is ready in namespace {0}" ,
390
+ domainNamespace );
390
391
}
391
392
392
393
// verify hpa is getting the metrics
@@ -396,7 +397,7 @@ private boolean verifyHPA(String namespace, String expectedOutput) {
396
397
397
398
ExecResult result = Command .withParams (params ).executeAndReturnResult ();
398
399
logger .info (result .stdout ());
399
- return result .stdout ().contains (expectedOutput );
400
+ return result .stdout ().contains (expectedOutput ) && ! result . stdout (). contains ( "unknown" ) ;
400
401
}
401
402
402
403
// verify custom metrics is exposed via prometheus adapter
@@ -426,7 +427,6 @@ private void installPrometheus(String promChartVersion,
426
427
assertNotNull (promHelmParams , " Failed to install prometheus" );
427
428
prometheusDomainRegexValue = prometheusRegexValue ;
428
429
nodeportPrometheus = promHelmParams .getNodePortServer ();
429
- hostPortPrometheus = K8S_NODEPORT_HOST + ":" + nodeportPrometheus ;
430
430
}
431
431
//if prometheus already installed change CM for specified domain
432
432
if (!prometheusRegexValue .equals (prometheusDomainRegexValue )) {
@@ -455,8 +455,7 @@ public void tearDownAll() {
455
455
CommandParams params = new CommandParams ().defaults ();
456
456
params .command (KUBERNETES_CLI + " delete -f " + targetHPAFile );
457
457
ExecResult result = Command .withParams (params ).executeAndReturnResult ();
458
- assertTrue (result .exitValue () == 0 ,
459
- "Failed to delete hpa , result " + result );
458
+ assertEquals (0 , result .exitValue (), "Failed to delete hpa , result " + result );
460
459
if (prometheusAdapterHelmParams != null ) {
461
460
Helm .uninstall (prometheusAdapterHelmParams );
462
461
}
0 commit comments