Integrating prometheus with Policy components 87/123187/13
authora.sreekumar <ajith.sreekumar@bell.ca>
Mon, 9 Aug 2021 11:01:02 +0000 (12:01 +0100)
committera.sreekumar <ajith.sreekumar@bell.ca>
Wed, 18 Aug 2021 11:18:14 +0000 (12:18 +0100)
commitecc85ec4c6af67dc1ba2ff20b7473925e6657b11
tree04023057ba609438602b88afc323048a4e6af544
parenta8590fdd6f7a5360cfaf505418880f6076c0c867
Integrating prometheus with Policy components

With this change, all PF components can export prometheus metrics
by default. The prometheus metrics servlet will be running on
/metrics servletPath..
If the metrics shouldn't be exported, just add a flag
    "promethus": false
in the restServerParameters of default configuration file.
This brings up prometheus servlet on /metrics servletPath.

Also as part of standard servlet support, "servletUriPath" and
"servletClass" are 2 other fields added to RestServerParameters
which can be used to add standard servlets. This can be revisited later
if needed.
Basically, any servlet can be added by passing these fields, for
example, to add prometheus metrics servlet on /test/metrics,
add the below to restServerParameters:
    "servletUriPath": "/test/metrics",
    "servletClass": "io.prometheus.client.exporter.MetricsServlet"

In addition, we can later go to individual components and add more
metrics, say for e.g.,
deployedPoliciesCounter/undeployedPoliciesCounter etc on PAP,
executedEvents/failedEvents etc on PDP and so on.
This will look something like below, for e.g. in policy-pap component:
 io.prometheus.client.Counter counter = Counter.build()
  .name("policies_deployed_total")
  .help("Number of policies deployed.").register()
Whenever a policy is deployed, just call
 counter.inc()

Usage of code like above in the individual component will expose
such data as well as part of the exposed metrics.

Change-Id: Id667f27b15c012398421ba657b5324cc1d82cf1f
Issue-ID: POLICY-3524
Signed-off-by: a.sreekumar <ajith.sreekumar@bell.ca>
Signed-off-by: jhh <jorge.hernandez-herrero@att.com>
Signed-off-by: a.sreekumar <ajith.sreekumar@bell.ca>
13 files changed:
policy-endpoints/pom.xml
policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/HttpServletServer.java
policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/IndexedHttpServletServerFactory.java
policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/RestServer.java
policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/internal/JettyJerseyServer.java
policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/internal/JettyServletServer.java
policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/internal/JettyStaticResourceServer.java
policy-endpoints/src/main/java/org/onap/policy/common/endpoints/parameters/RestServerParameters.java
policy-endpoints/src/main/java/org/onap/policy/common/endpoints/properties/PolicyEndPointProperties.java
policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpClientTest.java
policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpServerTest.java
policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/RestServerTest.java
policy-endpoints/src/test/resources/org/onap/policy/common/endpoints/http/server/internal/HttpServerTest.json