Skip to content

Commit 7c4cf55

Browse files
author
Tom Barnes
committed
Issue-27: Create prometheus annotations on pods
1 parent 46d70e8 commit 7c4cf55

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

src/integration-tests/bash/run.sh

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,22 @@
1111
# -----------------
1212
#
1313
# This script runs a series of acceptance tests and archives the results
14-
# into tar.gz files upon completion.
14+
# into tar.gz files upon completion. It currently runs in three modes,
15+
# "Wercker", "Jenkins", and "standalone" Oracle Linux, where the mode
16+
# is controlled by the WERCKER and JENKINS environment variables described
17+
# below. A standalone run filters out verbose lines from the console output
18+
# while redirecting full output to the file /tmp/test_suite.out
1519
#
1620
# To cleanup after a run, see "cleanup.sh".
1721
#
18-
# The test has three levels of logging output, output that begins with:
22+
# The test has three levels of logging output. Output that begins with:
1923
#
2024
# "##TEST_INFO" is very concise (one line per test (either PASS or FAIL).
2125
# "[timestamp]" is concise.
2226
# "+" is verbose.
2327
# Anything else is semi-verbose.
2428
#
29+
#
2530
# This script accepts optional env var overrides:
2631
#
2732
# RESULT_ROOT The root directory of the test temporary files.
@@ -33,6 +38,9 @@
3338
# See "Directory Configuration and Structure" below for
3439
# defaults and a detailed description of test directies.
3540
#
41+
# QUICKTEST When set to "true", limits testing to a subset of
42+
# of the tests.
43+
#
3644
# WERCKER Set to true if invoking from Wercker, set
3745
# to false or "" if running stand-alone or from Jenkins.
3846
# Default is "".
@@ -371,6 +379,8 @@ trap ctrl_c INT
371379

372380
function ctrl_c() {
373381
declare_new_test_from_trap 1 run_aborted_with_ctrl_c
382+
# disable the trap:
383+
trap - INT
374384
fail "Trapped CTRL-C"
375385
}
376386

@@ -1449,6 +1459,8 @@ EOF
14491459
# like local, it uses the t3 channel...
14501460
run_wlst_script $1 hybrid ${pyfile_con}
14511461
else
1462+
# TODO The following has a dependency on java and WebLogic being in the path/classpath.
1463+
# We should run on 'hybrid' mode instead if java and WebLogic aren't already setup.
14521464
run_wlst_script $1 local ${pyfile_con}
14531465
fi
14541466

@@ -1470,6 +1482,11 @@ function run_wlst_script {
14701482
fail "requires at least 3 parameters: domainKey local|remote|hybrid local_pyfile optionalarg1 optionalarg2 ..."
14711483
fi
14721484

1485+
# TODO It seems possible to obtain user/pass from the secret via WLST verbs. This
1486+
# would be better than passing it to the WLST command-line in plain-text. See
1487+
# read-domain-secret.py in domain-job-template for an example of how this is done
1488+
# for WLST that runs from within a pod...
1489+
14731490
local DOM_KEY="$1"
14741491
local NAMESPACE="`dom_get $1 NAMESPACE`"
14751492
local DOMAIN_UID="`dom_get $1 DOMAIN_UID`"
@@ -2352,8 +2369,9 @@ function test_suite_init {
23522369
}
23532370

23542371
#
2355-
# TODO: Make output less verbose -- suppress REST output, etc. Move output to file and/or
2356-
# only report output on a failure and/or prefix output with a "+".
2372+
# TODO: Make output less verbose -- suppress REST, archive, and job output, etc. In general, move
2373+
# move verbose output to file and/or only report output on a failure and/or prefix output
2374+
# with a "+". Also, suppress output in the pod readiness loops to only once every 30 seconds.
23572375
#
23582376

23592377
function test_suite {

src/main/java/oracle/kubernetes/operator/helpers/AnnotationHelper.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@ public static void annotateWithDomain(V1ObjectMeta meta, Domain domain) {
2828
}
2929
}
3030

31+
32+
/**
33+
* Marks metadata with annotations that let Prometheus know how to retrieve metrics from
34+
* the wls-exporter web-app. The specified httpPort should be the listen port of the wl server
35+
* running in the pod.
36+
*/
37+
public static void annotateForPrometheus(V1ObjectMeta meta, int httpPort) {
38+
meta.putAnnotationsItem("prometheus.io/port", "" + httpPort); // should be the ListenPort of the server in the pod
39+
meta.putAnnotationsItem("prometheus.io/path", "/wls-exporter/metrics");
40+
meta.putAnnotationsItem("prometheus.io/scrape", "true");
41+
}
42+
3143
/**
3244
* Check the metadata object for the presence of an annotation matching the domain and resource version.l
3345
* @param meta The metadata object

src/main/java/oracle/kubernetes/operator/helpers/PodHelper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public NextAction apply(Packet packet) {
105105
adminPod.setMetadata(metadata);
106106

107107
AnnotationHelper.annotateWithDomain(metadata, dom);
108+
AnnotationHelper.annotateForPrometheus(metadata, spec.getAsPort());
108109

109110
Map<String, String> labels = new HashMap<>();
110111
labels.put(LabelConstants.DOMAINUID_LABEL, weblogicDomainUID);
@@ -438,6 +439,7 @@ public NextAction apply(Packet packet) {
438439
pod.setMetadata(metadata);
439440

440441
AnnotationHelper.annotateWithDomain(metadata, dom);
442+
AnnotationHelper.annotateForPrometheus(metadata, scan.getListenPort());
441443

442444
Map<String, String> labels = new HashMap<>();
443445
labels.put(LabelConstants.DOMAINUID_LABEL, weblogicDomainUID);

0 commit comments

Comments
 (0)