@@ -47,13 +47,15 @@ public class ITMonitoringExporter extends BaseTest {
47
47
48
48
private static int number = 5 ;
49
49
private static Operator operator = null ;
50
+ private static Operator operator1 = null ;
50
51
private static Domain domain = null ;
51
52
private static String myhost = "" ;
52
53
private static String monitoringExporterDir = "" ;
53
54
private static String resourceExporterDir = "" ;
54
55
private static String exporterUrl = "" ;
55
56
private static String configPath = "" ;
56
57
private static String metricsUrl = "" ;
58
+ private static String prometheusPort = "32000" ;
57
59
// "heap_free_current{name="managed-server1"}[15s]" search for results for last 15secs
58
60
private static String prometheusSearchKey1 =
59
61
"heap_free_current%7Bname%3D%22managed-server1%22%7D%5B15s%5D" ;
@@ -93,6 +95,7 @@ public static void staticPrepare() throws Exception {
93
95
resourceExporterDir =
94
96
BaseTest .getProjectRoot () + "/integration-tests/src/test/resources/exporter" ;
95
97
configPath = resourceExporterDir ;
98
+
96
99
upgradeTraefikHostName ();
97
100
deployRunMonitoringExporter (domain , operator );
98
101
buildDeployWebServiceApp (domain , TESTWSAPP , TESTWSSERVICE );
@@ -116,7 +119,7 @@ public static void staticUnPrepare() throws Exception {
116
119
if (operator != null ) {
117
120
operator .destroy ();
118
121
}
119
- deletePrometheusGrafana ();
122
+ // deletePrometheusGrafana();
120
123
tearDown (new Object () {}.getClass ().getEnclosingClass ().getSimpleName ());
121
124
logger .info ("SUCCESS" );
122
125
}
@@ -553,6 +556,44 @@ public void test18_ChangeConfigEmptyPass() throws Exception {
553
556
logger .info ("SUCCESS - " + testMethodName );
554
557
}
555
558
559
+ /**
560
+ * Test End to End example from MonitoringExporter github project
561
+ *
562
+ * @throws Exception
563
+ */
564
+ @ Test
565
+ public void test19_EndToEndViaChart () throws Exception {
566
+ Assume .assumeFalse (QUICKTEST );
567
+ String monitoringExporterEndToEndDir =
568
+ monitoringExporterDir + "/src/samples/kubernetes/end2end/" ;
569
+ String testMethodName = new Object () {}.getClass ().getEnclosingMethod ().getName ();
570
+ logTestBegin (testMethodName );
571
+ boolean testCompletedSuccessfully = false ;
572
+ try {
573
+ setupPVMYSQL ();
574
+ createWLSImageAndDeploy ();
575
+ installPrometheusGrafanaViaChart ();
576
+ } finally {
577
+ uninstallMySQL ();
578
+ uninstallPrometheusGrafanaViaChart ();
579
+ String crdCmd =
580
+ " kubectl delete -f " + monitoringExporterEndToEndDir + "/demo-domains/domain1.yaml" ;
581
+ ExecCommand .exec (crdCmd );
582
+ crdCmd = "kubectl delete secret domain1-weblogic-credentials" ;
583
+ ExecCommand .exec (crdCmd );
584
+ operator1 .destroy ();
585
+ crdCmd =
586
+ "cd "
587
+ + monitoringExporterEndToEndDir
588
+ + " && docker run --rm -v "
589
+ + monitoringExporterEndToEndDir
590
+ + "pvDir:/tt -v $PWD/util:/util nginx /util/clean-pv.sh" ;
591
+ ExecCommand .exec (crdCmd );
592
+ }
593
+ testCompletedSuccessfully = true ;
594
+ logger .info ("SUCCESS - " + testMethodName );
595
+ }
596
+
556
597
private void changeConfigNegative (String effect , String configFile , String expectedErrorMsg )
557
598
throws Exception {
558
599
final WebClient webClient = new WebClient ();
@@ -629,6 +670,262 @@ private HtmlPage submitConfigureForm(
629
670
return page2 ;
630
671
}
631
672
673
+ /**
674
+ * Remove monitoring exporter directory if exists and clone latest from github for monitoring
675
+ * exporter code
676
+ *
677
+ * @throws Exception if could not run the command successfully to clone from github
678
+ */
679
+ private static void setupPVMYSQL () throws Exception {
680
+
681
+ String monitoringExporterEndToEndDir =
682
+ monitoringExporterDir + "/src/samples/kubernetes/end2end/" ;
683
+ String pvDir = monitoringExporterEndToEndDir + "pvDir" ;
684
+ if (new File (pvDir ).exists ()) {
685
+ logger .info (" PV dir already exists , cleaning " );
686
+ if (!pvDir .isEmpty ()) {
687
+ StringBuffer removeDir = new StringBuffer ();
688
+ logger .info ("Cleaning PV dir " + pvDir );
689
+
690
+ removeDir .append ("rm -rf " ).append (pvDir ).append (" && " );
691
+ }
692
+ } else {
693
+ Files .createDirectories (Paths .get (pvDir ));
694
+ }
695
+ replaceStringInFile (
696
+ monitoringExporterEndToEndDir + "/mysql/persistence.yaml" , "%PV_ROOT%" , pvDir );
697
+ replaceStringInFile (
698
+ monitoringExporterEndToEndDir + "/prometheus/persistence.yaml" , "%PV_ROOT%" , pvDir );
699
+ replaceStringInFile (
700
+ monitoringExporterEndToEndDir + "/grafana/persistence.yaml" , "%PV_ROOT%" , pvDir );
701
+ // deploy PV and PVC
702
+ String crdCmd =
703
+ " kubectl apply -f " + monitoringExporterEndToEndDir + "/mysql/persistence.yaml" ;
704
+ TestUtils .exec (crdCmd );
705
+ crdCmd = " kubectl apply -f " + monitoringExporterEndToEndDir + "/mysql/mysql.yaml" ;
706
+ TestUtils .exec (crdCmd );
707
+
708
+ StringBuffer cmd = new StringBuffer ();
709
+ cmd .append ("kubectl get pod -l app=mysql -o jsonpath=\" {.items[0].metadata.name} \" " );
710
+ logger .fine ("getSQL pod name cmd =" + cmd );
711
+ ExecResult result = ExecCommand .exec (cmd .toString ());
712
+ String sqlPod = null ;
713
+ if (result .exitValue () == 0 ) {
714
+ sqlPod = result .stdout ().trim ();
715
+ }
716
+ assertNotNull ("DataBase was not created, can't find running pod" , sqlPod );
717
+ TestUtils .checkPodReady (sqlPod , "default" );
718
+ result =
719
+ TestUtils .kubectlexecNoCheck (
720
+ sqlPod , "default" , " -- mysql -p123456 -e \" CREATE DATABASE domain1;\" " );
721
+ if (result .exitValue () != 0 ) {
722
+ throw new RuntimeException (
723
+ "FAILURE: command to create database domain1 "
724
+ + sqlPod
725
+ + " in the pod failed, returned "
726
+ + result .stderr ()
727
+ + " "
728
+ + result .stdout ());
729
+ }
730
+ result =
731
+ TestUtils .kubectlexecNoCheck (
732
+ sqlPod ,
733
+ "default" ,
734
+ " -- mysql -p123456 -e \" CREATE USER 'wluser1' IDENTIFIED BY 'wlpwd123';\" " );
735
+ if (result .exitValue () != 0 ) {
736
+ throw new RuntimeException (
737
+ "FAILURE: command to create user wluser1 "
738
+ + sqlPod
739
+ + " in the pod failed, returned "
740
+ + result .stderr ()
741
+ + " "
742
+ + result .stdout ());
743
+ }
744
+ result =
745
+ TestUtils .kubectlexecNoCheck (
746
+ sqlPod , "default" , " -- mysql -p123456 -e \" GRANT ALL ON domain1.* TO 'wluser1';\" " );
747
+ if (result .exitValue () != 0 ) {
748
+ throw new RuntimeException (
749
+ "FAILURE: command to grant all to user wluser1 "
750
+ + sqlPod
751
+ + " in the pod failed, returned "
752
+ + result .stderr ()
753
+ + " "
754
+ + result .stdout ());
755
+ }
756
+ // verify all
757
+ result =
758
+ TestUtils .kubectlexecNoCheck (
759
+ sqlPod , "default" , " -- mysql -u wluser1 -pwlpwd123 -D domain1 -e \" show tables;\" " );
760
+ if (result .exitValue () != 0 ) {
761
+ throw new RuntimeException (
762
+ "FAILURE: failed to setup user and database "
763
+ + " in the pod failed, returned "
764
+ + result .stderr ()
765
+ + " "
766
+ + result .stdout ());
767
+ }
768
+ }
769
+ /**
770
+ * Install wls image tool and update wls pods
771
+ *
772
+ * @throws Exception if could not run the command successfully to clone from github
773
+ */
774
+ private static void createWLSImageAndDeploy () throws Exception {
775
+ // monitoringExporterDir = "/scratch/opc/wl_k8s_test_results/acceptance_test_tmp/monitoring/";
776
+ String monitoringExporterEndToEndDir =
777
+ monitoringExporterDir + "/src/samples/kubernetes/end2end/" ;
778
+ operator1 = TestUtils .createOperator (OPERATOR1_YAML );
779
+
780
+ String command =
781
+ "cd "
782
+ + monitoringExporterEndToEndDir
783
+ + "/demo-domains/domainBuilder/ && ./build.sh domain1 weblogic welcome1 wluser1 wlpwd123" ;
784
+ TestUtils .exec (command );
785
+ String newImage = "domain1-image:1.0" ;
786
+ command =
787
+ "kubectl -n default create secret generic domain1-weblogic-credentials "
788
+ + " --from-literal=username=weblogic "
789
+ + " --from-literal=password=welcome1" ;
790
+ TestUtils .exec (command );
791
+ // apply new domain yaml and verify pod restart
792
+ String crdCmd =
793
+ " kubectl apply -f " + monitoringExporterEndToEndDir + "/demo-domains/domain1.yaml" ;
794
+ TestUtils .exec (crdCmd );
795
+
796
+ TestUtils .checkPodReady ("domain1-admin-server" , "default" );
797
+ TestUtils .checkPodReady ("domain1-managed-server-1" , "default" );
798
+ TestUtils .checkPodReady ("domain1-managed-server-2" , "default" );
799
+ /*
800
+ domain.verifyDomainServerPodRestart(
801
+ "\"" + getWeblogicImageName() + ":" + getWeblogicImageTag() + "\""
802
+ "\"" + newImage + "\"");
803
+
804
+ */
805
+ // apply curl to the pod
806
+ crdCmd = " kubectl apply -f " + monitoringExporterEndToEndDir + "/util/curl.yaml" ;
807
+ TestUtils .exec (crdCmd );
808
+
809
+ TestUtils .checkPodReady ("curl" , "default" );
810
+ // access metrics
811
+ crdCmd =
812
+ "kubectl exec curl -- curl http://weblogic:welcome1@domain1-managed-server-1:8001/wls-exporter/metrics" ;
813
+ ExecResult result = TestUtils .exec (crdCmd );
814
+ assertTrue ((result .stdout ().contains ("wls_servlet_execution_time_average" )));
815
+ crdCmd =
816
+ "kubectl exec curl -- curl http://weblogic:welcome1@domain1-managed-server-2:8001/wls-exporter/metrics" ;
817
+ result = TestUtils .exec (crdCmd );
818
+ assertTrue ((result .stdout ().contains ("wls_servlet_execution_time_average" )));
819
+ }
820
+
821
+ /**
822
+ * Install Prometheus and Grafana using helm chart
823
+ *
824
+ * @throws Exception if could not run the command successfully to clone from github
825
+ */
826
+ private static void installPrometheusGrafanaViaChart () throws Exception {
827
+ String monitoringExporterEndToEndDir =
828
+ monitoringExporterDir + "/src/samples/kubernetes/end2end/" ;
829
+ // delete any running pods
830
+ deletePrometheusGrafana ();
831
+ prometheusPort = "30000" ;
832
+ String crdCmd = "kubectl create ns monitoring" ;
833
+ TestUtils .exec (crdCmd );
834
+ crdCmd = "kubectl apply -f " + monitoringExporterEndToEndDir + "/prometheus/persistence.yaml" ;
835
+ TestUtils .exec (crdCmd );
836
+ // install prometheus
837
+ crdCmd =
838
+ "helm install --wait --name prometheus --namespace monitoring --values "
839
+ + monitoringExporterEndToEndDir
840
+ + "/prometheus/values.yaml stable/prometheus" ;
841
+ TestUtils .exec (crdCmd );
842
+
843
+ // install grafana
844
+ crdCmd = "kubectl apply -f " + monitoringExporterEndToEndDir + "/grafana/persistence.yaml" ;
845
+ TestUtils .exec (crdCmd );
846
+ crdCmd =
847
+ "kubectl --namespace monitoring create secret generic grafana-secret --from-literal=username=admin --from-literal=password=12345678" ;
848
+ TestUtils .exec (crdCmd );
849
+ logger .info ("calling helm install for grafana" );
850
+ crdCmd =
851
+ "helm install --wait --name grafana --namespace monitoring --values "
852
+ + monitoringExporterEndToEndDir
853
+ + "/grafana/values.yaml stable/grafana" ;
854
+ // TestUtils.exec(crdCmd);
855
+ ExecResult result = ExecCommand .exec (crdCmd );
856
+ Thread .sleep (10000 );
857
+
858
+ logger .info ("installing grafana dashboard" );
859
+
860
+ crdCmd =
861
+ " cd "
862
+ + monitoringExporterEndToEndDir
863
+ + " && curl -v -H 'Content-Type: application/json' -H \" Content-Type: application/json\" "
864
+ + " -X POST http://admin:12345678@$HOSTNAME:31000/api/datasources/"
865
+ + " --data-binary @grafana/datasource.json" ;
866
+ TestUtils .exec (crdCmd );
867
+
868
+ crdCmd =
869
+ " cd "
870
+ + monitoringExporterEndToEndDir
871
+ + " && curl -v -H 'Content-Type: application/json' -H \" Content-Type: application/json\" "
872
+ + " -X POST http://admin:12345678@$HOSTNAME:31000/api/dashboards/db/"
873
+ + " --data-binary @grafana/dashboard.json" ;
874
+ TestUtils .exec (crdCmd );
875
+
876
+ assertTrue (checkMetricsViaPrometheus ("wls_servlet_execution_time_average" , "testwebapp" ));
877
+ }
878
+
879
+ /**
880
+ * Uninstall Prometheus and Grafana using helm chart
881
+ *
882
+ * @throws Exception if could not run the command successfully to clone from github
883
+ */
884
+ private static void uninstallPrometheusGrafanaViaChart () throws Exception {
885
+ String monitoringExporterEndToEndDir =
886
+ monitoringExporterDir + "/src/samples/kubernetes/end2end/" ;
887
+ // uninstall grafana
888
+ String crdCmd = "helm delete --purge grafana" ;
889
+ ExecCommand .exec (crdCmd );
890
+ crdCmd = "kubectl -n monitoring delete secret grafana-secret" ;
891
+ ExecCommand .exec (crdCmd );
892
+ crdCmd = "kubectl delete -f " + monitoringExporterEndToEndDir + "/grafana/persistence.yaml" ;
893
+ ExecCommand .exec (crdCmd );
894
+
895
+ // uninstall prometheus
896
+ crdCmd = "helm delete --purge prometheus" ;
897
+ ExecCommand .exec (crdCmd );
898
+ crdCmd = "kubectl delete -f " + monitoringExporterEndToEndDir + "/prometheus/persistence.yaml" ;
899
+ ExecCommand .exec (crdCmd );
900
+
901
+ crdCmd = "kubectl delete namespace monitoring" ;
902
+ TestUtils .exec (crdCmd );
903
+ }
904
+
905
+ /**
906
+ * Unnstall MYSQL
907
+ *
908
+ * @throws Exception if could not run the command successfully to clone from github
909
+ */
910
+ private static void uninstallMySQL () throws Exception {
911
+ String monitoringExporterEndToEndDir =
912
+ monitoringExporterDir + "/src/samples/kubernetes/end2end/" ;
913
+ // unnstall mysql
914
+
915
+ String crdCmd = " kubectl delete -f " + monitoringExporterEndToEndDir + "mysql/mysql.yaml" ;
916
+ ExecCommand .exec (crdCmd );
917
+
918
+ crdCmd = " kubectl delete -f " + monitoringExporterEndToEndDir + "mysql/persistence.yaml" ;
919
+ ExecCommand .exec (crdCmd );
920
+ crdCmd =
921
+ "cd "
922
+ + monitoringExporterEndToEndDir
923
+ + " && docker run --rm -v "
924
+ + monitoringExporterEndToEndDir
925
+ + "pvDir:/tt -v $PWD/util:/util nginx /util/clean-pv.sh" ;
926
+ ExecCommand .exec (crdCmd );
927
+ }
928
+
632
929
/**
633
930
* Remove monitoring exporter directory if exists and clone latest from github for monitoring
634
931
* exporter code
@@ -793,6 +1090,22 @@ private static void createCoordinatorFile(String domainNS) throws IOException {
793
1090
}
794
1091
}
795
1092
1093
+ /**
1094
+ * A utility method to sed files
1095
+ *
1096
+ * @throws IOException when copying files from source location to staging area fails
1097
+ */
1098
+ private static void replaceStringInFile (String filePath , String oldValue , String newValue )
1099
+ throws IOException {
1100
+ Path src = Paths .get (filePath );
1101
+ logger .log (Level .INFO , "Copying {0}" , src .toString ());
1102
+ Charset charset = StandardCharsets .UTF_8 ;
1103
+ String content = new String (Files .readAllBytes (src ), charset );
1104
+ content = content .replaceAll (oldValue , newValue );
1105
+ logger .log (Level .INFO , "to {0}" , src .toString ());
1106
+ Files .write (src , content .getBytes (charset ));
1107
+ }
1108
+
796
1109
/**
797
1110
* A utility method to copy Cross Namespaces RBAC yaml template file replacing the DOMAIN_NS,
798
1111
* OPERATOR_NS
@@ -901,12 +1214,14 @@ private void scaleCluster(int replicas) throws Exception {
901
1214
* @param expectedVal - expected metrics to search
902
1215
* @throws Exception
903
1216
*/
904
- private boolean checkMetricsViaPrometheus (String searchKey , String expectedVal ) throws Exception {
1217
+ private static boolean checkMetricsViaPrometheus (String searchKey , String expectedVal )
1218
+ throws Exception {
905
1219
// sleep 20 secs to allow to scrap new metrics
906
1220
Thread .sleep (20 * 1000 );
907
1221
// url
908
1222
StringBuffer testAppUrl = new StringBuffer ("http://" );
909
- testAppUrl .append (myhost ).append (":" ).append ("32000" ).append ("/api/v1/query?query=" );
1223
+ // testAppUrl.append(myhost).append(":").append(prometheusPort).append("/api/v1/query?query=");
1224
+ testAppUrl .append (myhost ).append (":" ).append (prometheusPort ).append ("/api/v1/query?query=" );
910
1225
911
1226
testAppUrl .append (searchKey );
912
1227
// curl cmd to call webapp
0 commit comments