Skip to content

Commit

Permalink
Feature/refactor (#1)
Browse files Browse the repository at this point in the history
refactor + tests
  • Loading branch information
D1le authored Jul 8, 2019
1 parent fee32bd commit 4059d5a
Show file tree
Hide file tree
Showing 36 changed files with 1,204 additions and 1,024 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018 pegi18
Copyright (c) 2018 - present Alexey Lapin

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
14 changes: 14 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
This product depends on software developed by
Pegasystems Inc (https://www.pega.com)

This product depends on 'micrometer'
(https://github.com/micrometer-metrics/micrometer)

This product depends on 'guava'
(https://github.com/google/guava)

This product depends on 'Apache Log4J'
(http://logging.apache.org/log4j/)

This product depends on 'Apache Commons'
(https://commons.apache.org/)
161 changes: 160 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,160 @@
# micrometer-prpc
# micrometer-prpc
Pega PRPC + Micrometer = :heart:

Expose your business and technical metrics from Pega to any monitoring system.

This small library aims to simplify usage of [Micrometer](https://micrometer.io) for collecting metrics in
[Pega PRPC](https://www.pega.com/products/pega-platform) environment. Developers can use familiar concept of 'rules'
to implement metric value sources.

|version| compatibility |
|:-----:|:----------------:|
| 7.3.0 |:heavy_check_mark:|
| 8.2.1 |:heavy_check_mark:|

Java 8+ required.

### Build
#### Prerequisites
In order to build the project locally, you have to satisfy dependency prerequisites.

This project does not include any dependencies or any proprietary code.
It is intended to be used by authorized Pegasystems Inc clients in their Pega PRPC environments.

This library relies on some internal PRPC jars which usually could be found in
`<pega-distributive>.zip/archives/pegadbinstall-classes.zip/lib`.

Libs:
- prpublic
- prprivate
- prenginext
- pricu2jdk
- prbootstrap
- prbootstrap-api

The following command will help to install the required jars to a local maven repository:
```
mvn install:install-file -Dfile=<path-to-prpc-libs>/<lib>-<version.prpc>.jar -DgroupId=com.pega.prpc -DartifactId=<lib> -Dversion=<version.prpc> -Dpackaging=jar
```

#### Package
After the required jars are installed you may use the following command to build project:
```
mvn package -Dversion.prpc=<version.prpc>
```

### Install
Deploy the following jars to the PRPC instance as usual (from UI or service):
- micrometer-core-\<version.micrometer>.jar
- micrometer-registry-\<registry>-\<version.micrometer>.jar - one or multiple registry libs and its dependencies
- micrometer-prpc-\<version>.jar

### Use
Create sources:
```java
// Sql source
PrpcSource source = SqlSource.builder()
.queryString("select ... from {CLASS:Some-Data-Class}")
.groupPropName("pxPages")
.expirationDuration(2)
.expirationTimeUnit(TimeUnit.MINUTES)
.build();

// Data Page source
PrpcSource source = DataPageSource.builder()
.ruleName("D_SomeDataPage")
.accessGroupName("Some:AccessGroup")
.resultsPropName("pxResults")
.groupPropName("pxPages")
.expirationDuration(5)
.expirationTimeUnit(TimeUnit.MINUTES)
.build();

// Activity source
PrpcSource source = DataPageSource.builder()
.ruleName("SomeActivity")
.ruleClass("Some-Class")
.accessGroupName("Some:AccessGroup")
.resultsPropName("pxResults")
.groupPropName("pxPages")
.expirationDuration(10)
.expirationTimeUnit(TimeUnit.MINUTES)
.build();
```

Register metrics:
```java
// Create registry
MeterRegistry registry = ...

// Gauge - register single metric
registry.gauge("gauge.metric.name", source, PrpcCallback.strong("PropertyReference"));

// MultiGauge - register multiple metrics with unique tags
MultiGauge mg = MultiGauge.builder("gauge.metric.name").register(registry);
Iterable<MultiGauge.Row> rows = MultiMeter.rows(source, "PropertyReference");
mg.register(rows);

// Counter
registry.more().counter("counter.metric.name", Tags.empty(), source, PrpcCallback.strong("PropertyReference"));
```

For more information about micrometer features visit micrometer [docs](https://micrometer.io/docs) page.

### Prometheus example
1. Deploy libs:
- micrometer-prpc-\<LATEST>.jar
- micrometer-core-\<LATEST>.jar
- micrometer-registry-prometheus-\<LATEST>.jar
- simpleclient_common-\<LATEST>.jar
- simpleclient-\<LATEST>.jar

2. Implement startup agent:
```java
// Initialize registry and store it
MeterRegistry registry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
RegistryHolder.getInstance().put("prometheus", registry);

// Register meters which have constant tags cardinality during app lifetime
PrpcSource source = DataPageSource.builder()
.ruleName("D_pzNodeInformation")
.expirationDuration(2)
.expirationTimeUnit(TimeUnit.MINUTES)
.build();

registry.gauge("prpc.requestors", source, PrpcCallback.strong(source, "pxNumberRequestors"));
registry.gauge("prpc.agents", source, PrpcCallback.strong(source, "pxNumberAgents"));
registry.gauge("prpc.listeners", source, PrpcCallback.strong(source, "pxNumberListeners"));

registry.more().counter("prpc.requestors.initiated", Tags.of("type", "browser"), source, PrpcCallback.strong(source, "pxNumberBrowserInitiatedRequestorStarts"));
registry.more().counter("prpc.requestors.initiated", Tags.of("type", "batch"), source, PrpcCallback.strong(source, "pxNumberBatchInitiatedRequestorStarts"));
registry.more().counter("prpc.requestors.initiated", Tags.of("type", "service"), source, PrpcCallback.strong(source, "pxNumberServiceInitiatedRequestorStarts"));
```

3. Implement rest service:
```java
PrometheusMeterRegistry registry = (PrometheusMeterRegistry) RegistryHolder.getInstance().get("prometheus");
if (registry != null) {
response = registry.scrape();
}
```

The following setup results to a response which looks like:
```
# HELP prpc_requestors_initiated_total
# TYPE prpc_requestors_initiated_total counter
prpc_requestors_initiated_total{type="service",} 4.0
prpc_requestors_initiated_total{type="browser",} 1.0
prpc_requestors_initiated_total{type="batch",} 566.0
# HELP prpc_listeners
# TYPE prpc_listeners gauge
prpc_listeners 0.0
# HELP prpc_requestors
# TYPE prpc_requestors gauge
prpc_requestors 14.0
# HELP prpc_agents
# TYPE prpc_agents gauge
prpc_agents 55.0
```

4. Configure Promehtheus to scrape service URL.
100 changes: 57 additions & 43 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>ru.sbrf.pegi18</groupId>
<artifactId>micrometer-registry-prpc</artifactId>
<version>0.6</version>
<groupId>org.pega.metrics</groupId>
<artifactId>micrometer-prpc</artifactId>
<version>0.7.0</version>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
Expand All @@ -18,120 +18,134 @@
<dependencies>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<version>1.1.0</version>
<artifactId>micrometer-core</artifactId>
<version>1.1.5</version>
<scope>provided</scope>
</dependency>

<!-- Pega PRPC internal dependencies -->
<dependency>
<groupId>com.pega.prpc.pega73</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.pega.prpc.pega73</groupId>
<groupId>com.pega.prpc</groupId>
<artifactId>prpublic</artifactId>
<version>7.3</version>
<version>${version.prpc}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.pega.prpc.pega73</groupId>
<groupId>com.pega.prpc</groupId>
<artifactId>prprivate</artifactId>
<version>7.3</version>
<version>${version.prpc}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.pega.prpc.pega73</groupId>
<artifactId>prbootstrap</artifactId>
<version>7.3.0-77</version>
<groupId>com.pega.prpc</groupId>
<artifactId>prenginext</artifactId>
<version>${version.prpc}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.pega.prpc.pega73</groupId>
<artifactId>prbootstrap-api</artifactId>
<version>7.3.0-77</version>
<groupId>com.pega.prpc</groupId>
<artifactId>pricu2jdk</artifactId>
<version>${version.prpc}</version>
<scope>provided</scope>
</dependency>

<!-- Pega PRPC bundled dependencies -->
<dependency>
<groupId>com.pega.prpc.pega73</groupId>
<artifactId>pricu2jdk</artifactId>
<version>7.3</version>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.pega.prpc.pega73</groupId>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.6.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.pega.prpc.pega73</groupId>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.6.2</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.pega.prpc.pega73</groupId>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.pega.prpc.pega73</groupId>
<artifactId>prenginext</artifactId>
<version>7.3</version>
<scope>provided</scope>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.3.1</version>
<version>5.5.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.3.1</version>
<version>5.5.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>1.3.1</version>
<version>1.5.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.23.0</version>
<version>2.28.2</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.11.1</version>
<version>3.12.2</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.pega.prpc</groupId>
<artifactId>prbootstrap</artifactId>
<version>${version.prpc}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.pega.prpc</groupId>
<artifactId>prbootstrap-api</artifactId>
<version>${version.prpc}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.openjdk.jol</groupId>
<artifactId>jol-core</artifactId>
<version>0.9</version>
<scope>test</scope>
<optional>true</optional>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<version>2.22.2</version>
</plugin>

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.2</version>
<version>0.8.4</version>
<executions>
<execution>
<goals>
Expand All @@ -140,7 +154,7 @@
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package ru.sbrf.pegi18.mon;
package org.pega.metrics;

import io.micrometer.core.instrument.MeterRegistry;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
* @author lapin2-aa
* @author Alexey Lapin
*/
public class RegistryHolder {

Expand Down
Loading

0 comments on commit 4059d5a

Please sign in to comment.