101101@ Tag ("oke-sequential" )
102102@ Tag ("kind-parallel" )
103103public 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" ;
111109 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" ;
112114 private static String adminServerPodName = String .format ("%s-%s" , domainUid , ADMIN_SERVER_NAME_BASE );
113115 private static String managedServerPrefix = String .format ("%s-%s-%s" ,
114116 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-
120117 private static LoggingFacade logger = null ;
121118 private static String monitoringExporterDir ;
122- private static String monitoringExporterSrcDir ;
123- private static String monitoringExporterAppDir ;
124119 private static NginxParams nginxHelmParams = null ;
125120 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" ;
132121 private static String monitoringNS = null ;
133- static PrometheusParams promHelmParams = null ;
122+ private static PrometheusParams promHelmParams = null ;
134123 private static String releaseSuffix = "hpatest" ;
135124 private static String prometheusReleaseName = "prometheus" + releaseSuffix ;
136125 private static String prometheusAdapterReleaseName = "prometheus-adapter" + releaseSuffix ;
137- private static String hostPortPrometheus = null ;
138126 private static String prometheusDomainRegexValue = null ;
139127 private static int nodeportPrometheus ;
140128 private Path targetHPAFile ;
@@ -150,13 +138,14 @@ public class ItHorizontalPodAutoscalerCustomMetrics {
150138 @ BeforeAll
151139 public static void initAll (@ Namespaces (4 ) List <String > namespaces ) {
152140 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 ();
157146 logger .info ("Assign a unique namespace for operator" );
158147 assertNotNull (namespaces .get (0 ), "Namespace is null" );
159- opNamespace = namespaces .get (0 );
148+ String opNamespace = namespaces .get (0 );
160149
161150 logger .info ("Assign a unique namespace for WebLogic domain" );
162151 assertNotNull (namespaces .get (1 ), "Namespace is null" );
@@ -165,13 +154,12 @@ public static void initAll(@Namespaces(4) List<String> namespaces) {
165154 assertNotNull (namespaces .get (2 ), "Namespace list is null" );
166155 monitoringNS = namespaces .get (2 );
167156
168- logger .info ("Get a unique namespace for nginx " );
157+ logger .info ("Get a unique namespace for Nginx " );
169158 assertNotNull (namespaces .get (3 ), "Namespace list is null" );
170- nginxNamespace = namespaces .get (3 );
159+ String nginxNamespace = namespaces .get (3 );
171160
172161 // set the service account name for the operator
173- opServiceAccount = opNamespace + "-sa" ;
174-
162+ String opServiceAccount = opNamespace + "-sa" ;
175163 // install and verify operator with REST API
176164 installAndVerifyOperator (opNamespace , opServiceAccount , true , 0 , domainNamespace );
177165
@@ -182,33 +170,34 @@ public static void initAll(@Namespaces(4) List<String> namespaces) {
182170
183171 // create secret for admin credentials
184172 logger .info ("Create secret for admin credentials" );
185- adminSecretName = "weblogic-credentials" ;
173+ String adminSecretName = "weblogic-credentials" ;
186174 createSecretWithUsernamePassword (adminSecretName , domainNamespace ,
187175 ADMIN_USERNAME_DEFAULT , ADMIN_PASSWORD_DEFAULT );
188176
189177 // create encryption secret
190178 logger .info ("Create encryption secret" );
191- encryptionSecretName = "encryptionsecret" ;
179+ String encryptionSecretName = "encryptionsecret" ;
192180 createSecretWithUsernamePassword (encryptionSecretName , domainNamespace ,
193181 "weblogicenc" , "weblogicenc" );
182+
194183 logger .info ("install monitoring exporter" );
195184 installMonitoringExporter (monitoringExporterDir );
185+
196186 logger .info ("create and verify WebLogic domain image using model in image with model files" );
197187 String miiImage = MonitoringUtils .createAndVerifyMiiImage (monitoringExporterAppDir ,
198188 MODEL_DIR + "/" + MONEXP_MODEL_FILE ,
199189 SESSMIGR_APP_NAME , MONEXP_IMAGE_NAME );
200190 HashMap <String , String > labels = new HashMap <>();
201191 labels .put ("app" , "monitoring" );
202192 labels .put ("weblogic.domainUid" , "test" );
203- String className = "ItMonitoringExporterWebApp" ;
204193
205194 logger .info ("create pv and pvc for monitoring" );
206195 assertDoesNotThrow (() -> createPvAndPvc (prometheusReleaseName , monitoringNS , labels , className ));
207196 assertDoesNotThrow (() -> createPvAndPvc ("alertmanager" + releaseSuffix , monitoringNS , labels , className ));
208197 cleanupPromGrafanaClusterRoles (prometheusReleaseName , null );
209198 cleanupPrometheusAdapterClusterRoles ();
210199
211- domain = createDomainResource (
200+ DomainResource domain = createDomainResource (
212201 domainUid ,
213202 domainNamespace ,
214203 miiImage ,
@@ -349,7 +338,7 @@ void testHPAWithCustomMetrics() {
349338 logger .info ("HPA scaled down managed server 2" );
350339 --numberOfManagedSvs ;
351340 } else if (!Kubernetes .doesPodExist (domainNamespace , domainUid , managedServerPrefix + 3 )
352- || Kubernetes .isPodTerminating (domainNamespace , domainUid , managedServerPrefix + 2 )) {
341+ || Kubernetes .isPodTerminating (domainNamespace , domainUid , managedServerPrefix + 3 )) {
353342 logger .info ("HPA scaled down managed server 3" );
354343 --numberOfManagedSvs ;
355344 }
@@ -384,9 +373,21 @@ private void createHPA() {
384373 CommandParams params = new CommandParams ().defaults ();
385374 params .command (KUBERNETES_CLI + " apply -f " + targetHPAFile );
386375 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 );
390391 }
391392
392393 // verify hpa is getting the metrics
@@ -396,7 +397,7 @@ private boolean verifyHPA(String namespace, String expectedOutput) {
396397
397398 ExecResult result = Command .withParams (params ).executeAndReturnResult ();
398399 logger .info (result .stdout ());
399- return result .stdout ().contains (expectedOutput );
400+ return result .stdout ().contains (expectedOutput ) && ! result . stdout (). contains ( "unknown" ) ;
400401 }
401402
402403 // verify custom metrics is exposed via prometheus adapter
@@ -426,7 +427,6 @@ private void installPrometheus(String promChartVersion,
426427 assertNotNull (promHelmParams , " Failed to install prometheus" );
427428 prometheusDomainRegexValue = prometheusRegexValue ;
428429 nodeportPrometheus = promHelmParams .getNodePortServer ();
429- hostPortPrometheus = K8S_NODEPORT_HOST + ":" + nodeportPrometheus ;
430430 }
431431 //if prometheus already installed change CM for specified domain
432432 if (!prometheusRegexValue .equals (prometheusDomainRegexValue )) {
@@ -455,8 +455,7 @@ public void tearDownAll() {
455455 CommandParams params = new CommandParams ().defaults ();
456456 params .command (KUBERNETES_CLI + " delete -f " + targetHPAFile );
457457 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 );
460459 if (prometheusAdapterHelmParams != null ) {
461460 Helm .uninstall (prometheusAdapterHelmParams );
462461 }
0 commit comments