1
- // Copyright (c) 2023, Oracle and/or its affiliates.
1
+ // Copyright (c) 2023, 2024, Oracle and/or its affiliates.
2
2
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3
3
4
4
package oracle .weblogic .kubernetes ;
20
20
import com .gargoylesoftware .htmlunit .html .HtmlSubmitInput ;
21
21
import io .kubernetes .client .openapi .ApiException ;
22
22
import oracle .weblogic .kubernetes .actions .impl .GrafanaParams ;
23
- import oracle .weblogic .kubernetes .actions .impl .NginxParams ;
24
23
import oracle .weblogic .kubernetes .actions .impl .PrometheusParams ;
24
+ import oracle .weblogic .kubernetes .actions .impl .TraefikParams ;
25
+ import oracle .weblogic .kubernetes .actions .impl .primitive .HelmParams ;
25
26
import oracle .weblogic .kubernetes .annotations .IntegrationTest ;
26
27
import oracle .weblogic .kubernetes .annotations .Namespaces ;
27
28
import oracle .weblogic .kubernetes .logging .LoggingFacade ;
37
38
import static oracle .weblogic .kubernetes .TestConstants .GRAFANA_CHART_VERSION ;
38
39
import static oracle .weblogic .kubernetes .TestConstants .K8S_NODEPORT_HOST ;
39
40
import static oracle .weblogic .kubernetes .TestConstants .OKD ;
41
+ import static oracle .weblogic .kubernetes .TestConstants .OKE_CLUSTER_PRIVATEIP ;
40
42
import static oracle .weblogic .kubernetes .TestConstants .PROMETHEUS_CHART_VERSION ;
41
43
import static oracle .weblogic .kubernetes .TestConstants .RESULTS_ROOT ;
42
44
import static oracle .weblogic .kubernetes .actions .ActionConstants .MODEL_DIR ;
45
47
import static oracle .weblogic .kubernetes .actions .TestActions .deletePersistentVolume ;
46
48
import static oracle .weblogic .kubernetes .actions .TestActions .deletePersistentVolumeClaim ;
47
49
import static oracle .weblogic .kubernetes .actions .TestActions .getServiceNodePort ;
48
- import static oracle .weblogic .kubernetes .actions .TestActions .uninstallNginx ;
50
+ import static oracle .weblogic .kubernetes .actions .TestActions .uninstallTraefik ;
49
51
import static oracle .weblogic .kubernetes .actions .impl .primitive .Kubernetes .deleteNamespace ;
50
- import static oracle .weblogic .kubernetes .utils .LoadBalancerUtils .createIngressForDomainAndVerify ;
51
- import static oracle .weblogic .kubernetes .utils .LoadBalancerUtils .installAndVerifyNginx ;
52
+ import static oracle .weblogic .kubernetes .utils .ApplicationUtils .callWebAppAndWaitTillReady ;
53
+ import static oracle .weblogic .kubernetes .utils .CommonTestUtils .createIngressPathRouting ;
54
+ import static oracle .weblogic .kubernetes .utils .CommonTestUtils .getServiceExtIPAddrtOke ;
55
+ import static oracle .weblogic .kubernetes .utils .LoadBalancerUtils .installAndVerifyTraefik ;
52
56
import static oracle .weblogic .kubernetes .utils .MonitoringUtils .checkMetricsViaPrometheus ;
53
57
import static oracle .weblogic .kubernetes .utils .MonitoringUtils .cleanupPromGrafanaClusterRoles ;
54
58
import static oracle .weblogic .kubernetes .utils .MonitoringUtils .createAndVerifyDomain ;
55
59
import static oracle .weblogic .kubernetes .utils .MonitoringUtils .deleteMonitoringExporterTempDir ;
56
- import static oracle .weblogic .kubernetes .utils .MonitoringUtils .editPrometheusCM ;
57
60
import static oracle .weblogic .kubernetes .utils .MonitoringUtils .installAndVerifyGrafana ;
58
61
import static oracle .weblogic .kubernetes .utils .MonitoringUtils .installAndVerifyPrometheus ;
59
62
import static oracle .weblogic .kubernetes .utils .MonitoringUtils .installMonitoringExporter ;
60
63
import static oracle .weblogic .kubernetes .utils .MonitoringUtils .uninstallPrometheusGrafana ;
61
64
import static oracle .weblogic .kubernetes .utils .MonitoringUtils .verifyMonExpAppAccess ;
62
- import static oracle .weblogic .kubernetes .utils .MonitoringUtils .verifyMonExpAppAccessThroughNginx ;
63
65
import static oracle .weblogic .kubernetes .utils .OKDUtils .createRouteForOKD ;
64
66
import static oracle .weblogic .kubernetes .utils .OperatorUtils .installAndVerifyOperator ;
65
67
import static oracle .weblogic .kubernetes .utils .PersistentVolumeUtils .createPvAndPvc ;
76
78
@ DisplayName ("Verify WebLogic Metric is processed and filtered as expected by MonitoringExporter" )
77
79
@ IntegrationTest
78
80
@ Tag ("olcne-mrg" )
79
- @ Tag ("oke-sequential " )
81
+ @ Tag ("oke-gate " )
80
82
@ Tag ("kind-sequential" )
81
83
@ Tag ("okd-wls-mrg" )
82
84
class ItMonitoringExporterMetricsFiltering {
83
85
84
86
// domain constants
85
87
private static String domain1Namespace = null ;
86
88
private static String domain1Uid = "monexp-domain-4" ;
87
- private static NginxParams nginxHelmParams = null ;
88
89
private static int nodeportshttp = 0 ;
89
- private static int nodeportshttps = 0 ;
90
+ private static String host = null ;
91
+ private static String ingressIP = null ;
90
92
private static List <String > ingressHost1List = null ;
91
93
92
94
private static String monitoringNS = null ;
95
+ private static String traefikNamespace = null ;
96
+ private static HelmParams traefikHelmParams = null ;
97
+ private static TraefikParams traefikParams ;
98
+ private static String ingressClassName ;
93
99
static PrometheusParams promHelmParams = null ;
94
100
GrafanaParams grafanaHelmParams = null ;
95
101
private static String monitoringExporterEndToEndDir = null ;
@@ -120,7 +126,7 @@ class ItMonitoringExporterMetricsFiltering {
120
126
121
127
122
128
/**
123
- * Install operator and NGINX . Create model in image domain with multiple clusters.
129
+ * Install operator . Create model in image domain with multiple clusters.
124
130
* Create ingress for the domain.
125
131
*
126
132
* @param namespaces list of namespaces created by the IntegrationTestWatcher by the
@@ -144,9 +150,9 @@ public void initAll(@Namespaces(4) List<String> namespaces) {
144
150
assertNotNull (namespaces .get (1 ), "Namespace list is null" );
145
151
monitoringNS = namespaces .get (1 );
146
152
147
- logger .info ("Get a unique namespace for NGINX " );
153
+ logger .info ("Get a unique namespace for Traefik " );
148
154
assertNotNull (namespaces .get (2 ), "Namespace list is null" );
149
- final String nginxNamespace = namespaces .get (2 );
155
+ traefikNamespace = namespaces .get (2 );
150
156
151
157
152
158
logger .info ("Get a unique namespace for domain1" );
@@ -166,27 +172,30 @@ public void initAll(@Namespaces(4) List<String> namespaces) {
166
172
modelList .add (MODEL_DIR + "/" + JDBC_MODEL_FILE );
167
173
miiImage = MonitoringUtils .createAndVerifyMiiImage (monitoringExporterAppDir , modelList ,
168
174
STICKYSESS_APP_NAME , SESSMIGR_APP_NAME , MONEXP_IMAGE_NAME );
175
+ host = K8S_NODEPORT_HOST ;
176
+ if (host .contains (":" )) {
177
+ host = "[" + host + "]" ;
178
+ }
169
179
if (!OKD ) {
170
- // install and verify NGINX
171
- nginxHelmParams = installAndVerifyNginx (nginxNamespace , 0 , 0 );
172
-
173
- String nginxServiceName = nginxHelmParams .getHelmParams ().getReleaseName () + "-ingress-nginx-controller" ;
174
- logger .info ("NGINX service name: {0}" , nginxServiceName );
175
- nodeportshttp = getServiceNodePort (nginxNamespace , nginxServiceName , "http" );
176
- nodeportshttps = getServiceNodePort (nginxNamespace , nginxServiceName , "https" );
180
+ // install and verify Traefik
181
+ // install Traefik ingress controller for all test cases using Traefik
182
+ installTraefikIngressController ();
177
183
}
178
- logger .info ("NGINX http node port: {0}" , nodeportshttp );
179
- logger .info ("NGINX https node port: {0}" , nodeportshttps );
184
+
180
185
clusterNameMsPortMap = new HashMap <>();
181
186
clusterNameMsPortMap .put (cluster1Name , managedServerPort );
182
187
clusterNameMsPortMap .put (cluster2Name , managedServerPort );
183
188
clusterNames .add (cluster1Name );
184
189
clusterNames .add (cluster2Name );
185
- String host = K8S_NODEPORT_HOST ;
186
- if (host .contains (":" )) {
187
- host = "[" + host + "]" ;
188
- }
190
+ nodeportshttp = getTraefikLbNodePort (false );
189
191
exporterUrl = String .format ("http://%s:%s/wls-exporter/" , host , nodeportshttp );
192
+ logger .info ("exporter url: " + exporterUrl );
193
+ if (OKE_CLUSTER_PRIVATEIP ) {
194
+ String ingressServiceName = traefikHelmParams .getReleaseName ();
195
+ ingressIP = getServiceExtIPAddrtOke (ingressServiceName , traefikNamespace ) != null
196
+ ? getServiceExtIPAddrtOke (ingressServiceName , traefikNamespace ) : K8S_NODEPORT_HOST ;
197
+ exporterUrl = String .format ("http://%s/wls-exporter" , ingressIP );
198
+ }
190
199
HashMap <String , String > labels = new HashMap <>();
191
200
labels .put ("app" , "monitoring" );
192
201
labels .put ("weblogic.domainUid" , "test" );
@@ -468,14 +477,9 @@ private void setupDomainAndMonitoringTools(String domainNamespace, String domain
468
477
logger .info ("Creating ingress for domain {0} in namespace {1}" , domainUid , domainNamespace );
469
478
String adminServerPodName = domainUid + "-admin-server" ;
470
479
String clusterService = domainUid + "-cluster-cluster-1" ;
471
- if (!OKD ) {
472
- String ingressClassName = nginxHelmParams .getIngressClassName ();
473
- ingressHost1List
474
- = createIngressForDomainAndVerify (domainUid , domainNamespace , 0 , clusterNameMsPortMap ,
475
- false , ingressClassName , false , 0 );
476
- verifyMonExpAppAccessThroughNginx (ingressHost1List .get (0 ), 1 , nodeportshttp );
477
- // Need to expose the admin server external service to access the console in OKD cluster only
478
- } else {
480
+
481
+ // Need to expose the admin server external service to access the console in OKD cluster only
482
+ if (OKD ) {
479
483
String hostName = createRouteForOKD (clusterService , domainNamespace );
480
484
logger .info ("hostName = {0} " , hostName );
481
485
verifyMonExpAppAccess (1 ,hostName );
@@ -486,6 +490,14 @@ private void setupDomainAndMonitoringTools(String domainNamespace, String domain
486
490
domainNamespace ,
487
491
domainUid );
488
492
}
493
+
494
+ createIngressPathRouting (domainNamespace , "/wls-exporter" ,
495
+ domainUid + "-cluster-cluster-1" , 8001 , ingressClassName );
496
+ String curlCmd = "curl -g --silent --show-error --noproxy '*' " + exporterUrl
497
+ + " --write-out %{http_code} -o /dev/null" ;
498
+ getLogger ().info ("Executing curl command {0}" , curlCmd );
499
+ assertTrue (callWebAppAndWaitTillReady (curlCmd , 60 ));
500
+
489
501
}
490
502
491
503
/**
@@ -507,25 +519,18 @@ private void installPrometheusGrafana(String promChartVersion,
507
519
promChartVersion ,
508
520
prometheusRegexValue , promHelmValuesFileDir );
509
521
assertNotNull (promHelmParams , " Failed to install prometheus" );
510
- prometheusDomainRegexValue = prometheusRegexValue ;
511
522
nodeportPrometheus = promHelmParams .getNodePortServer ();
512
523
String host = K8S_NODEPORT_HOST ;
513
524
if (host .contains (":" )) {
514
525
host = "[" + host + "]" ;
515
526
}
516
527
hostPortPrometheus = host + ":" + nodeportPrometheus ;
517
- if ( OKD ) {
518
- hostPortPrometheus = createRouteForOKD ( "prometheus" + releaseSuffix
519
- + "-service" , monitoringNS ) + ":" + nodeportPrometheus ;
528
+
529
+ if ( OKE_CLUSTER_PRIVATEIP ) {
530
+ hostPortPrometheus = ingressIP ;
520
531
}
521
532
}
522
- //if prometheus already installed change CM for specified domain
523
- if (!prometheusRegexValue .equals (prometheusDomainRegexValue )) {
524
- logger .info ("update prometheus Config Map with domain info" );
525
- editPrometheusCM (prometheusDomainRegexValue , prometheusRegexValue , monitoringNS ,
526
- prometheusReleaseName + "-server" );
527
- prometheusDomainRegexValue = prometheusRegexValue ;
528
- }
533
+
529
534
logger .info ("Prometheus is running" );
530
535
if (grafanaHelmParams == null ) {
531
536
String grafanaHelmValuesFileDir = Paths .get (RESULTS_ROOT , this .getClass ().getSimpleName (),
@@ -535,28 +540,43 @@ private void installPrometheusGrafana(String promChartVersion,
535
540
grafanaHelmValuesFileDir ,
536
541
grafanaChartVersion );
537
542
assertNotNull (grafanaHelmParams , "Grafana failed to install" );
538
- String host = K8S_NODEPORT_HOST ;
539
- if (host .contains (":" )) {
540
- host = "[" + host + "]" ;
541
- }
542
- String hostPortGrafana = host + ":" + grafanaHelmParams .getNodePort ();
543
- if (OKD ) {
544
- hostPortGrafana = createRouteForOKD (grafanaReleaseName , monitoringNS ) + ":" + grafanaHelmParams .getNodePort ();
545
- }
543
+
546
544
}
547
545
logger .info ("Grafana is running" );
546
+ // create ingress rules with non-tls host routing, tls host routing and path routing for Traefik
547
+ /*
548
+ createTraefikIngressRoutingRulesForMonitoring(monitoringNS, prometheusReleaseName + "-server",
549
+ "traefik/traefik-ingress-rules-monitoring.yaml");
550
+
551
+ */
552
+
553
+ createIngressPathRouting (monitoringNS , "/api" ,
554
+ prometheusReleaseName + "-server" , 80 , ingressClassName );
555
+
548
556
}
549
557
550
558
551
559
@ AfterAll
552
560
public void tearDownAll () {
553
561
554
- // uninstall NGINX release
555
- logger .info ("Uninstalling NGINX" );
556
- if (nginxHelmParams != null ) {
557
- assertThat (uninstallNginx (nginxHelmParams .getHelmParams ()))
558
- .as ("Test uninstallNginx1 returns true" )
559
- .withFailMessage ("uninstallNginx() did not return true" )
562
+ // uninstall Traefik release
563
+
564
+ if (traefikHelmParams != null ) {
565
+ logger .info ("Uninstalling Traefik" );
566
+ /*
567
+ Path dstFileProm = Paths.get(TestConstants.RESULTS_ROOT,
568
+ monitoringNS,
569
+ prometheusReleaseName + "-server",
570
+ "traefik", "traefik-ingress-rules-monitoring.yaml");
571
+ deleteTraefikIngressRoutingRules(dstFileProm);
572
+ Path dstFileDomain = Paths.get(TestConstants.RESULTS_ROOT,
573
+ domain1Namespace, domain1Uid, "traefik-ingress-rules-exporter.yaml");
574
+ deleteTraefikIngressRoutingRules(dstFileDomain);
575
+
576
+ */
577
+ assertThat (uninstallTraefik (traefikHelmParams ))
578
+ .as ("Test uninstall traefik returns true" )
579
+ .withFailMessage ("uninstallTraefik() did not return true" )
560
580
.isTrue ();
561
581
}
562
582
// delete mii domain images created
@@ -589,11 +609,16 @@ private HtmlPage submitConfigureForm(String exporterUrl, String effect, String c
589
609
private HtmlPage submitConfigureForm (
590
610
String exporterUrl , String effect , String configFile , WebClient webClient ) throws Exception {
591
611
// Get the first page
612
+ logger .info ("exporterULR " + exporterUrl );
613
+
592
614
HtmlPage page1 = webClient .getPage (exporterUrl );
615
+
593
616
if (page1 == null ) {
594
617
//try again
595
618
page1 = webClient .getPage (exporterUrl );
596
619
}
620
+ logger .info ("exporter page " + page1 .asNormalizedText ());
621
+
597
622
assertNotNull (page1 , "can't retrieve exporter dashboard page" );
598
623
assertTrue ((page1 .asNormalizedText ()).contains ("Oracle WebLogic Monitoring Exporter" ));
599
624
@@ -725,5 +750,21 @@ private void appendConfiguration(String configFile) throws Exception {
725
750
assertTrue (page .asNormalizedText ().contains ("Unable to Update Configuration" ),
726
751
"Page does not contain expected Unable to Update Configuration" );
727
752
}
753
+
754
+
755
+ private static void installTraefikIngressController () {
756
+ // install and verify Traefik
757
+ logger .info ("Installing Traefik controller using helm" );
758
+ traefikParams = installAndVerifyTraefik (traefikNamespace , 0 , 0 );
759
+ traefikHelmParams = traefikParams .getHelmParams ();
760
+ ingressClassName = traefikParams .getIngressClassName ();
761
+ }
762
+
763
+ private int getTraefikLbNodePort (boolean isHttps ) {
764
+ logger .info ("Getting web node port for Traefik loadbalancer {0}" , traefikHelmParams .getReleaseName ());
765
+ return assertDoesNotThrow (() ->
766
+ getServiceNodePort (traefikNamespace , traefikHelmParams .getReleaseName (), isHttps ? "websecure" : "web" ),
767
+ "Getting web node port for Traefik loadbalancer failed" );
768
+ }
728
769
}
729
770
0 commit comments