Skip to content

Commit

Permalink
Merge branch 'master' into hermes_console_vue
Browse files Browse the repository at this point in the history
  • Loading branch information
szczygiel-m authored Sep 19, 2023
2 parents ba94bdc + 079f0a1 commit bd82501
Show file tree
Hide file tree
Showing 159 changed files with 3,905 additions and 1,575 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/checkstyle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
checkstyle:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: reviewdog/action-setup@v1
Expand All @@ -21,8 +21,6 @@ jobs:
with:
java-version: 17
distribution: 'temurin'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Run check style
run: ./gradlew --continue clean checkstyleMain checkstyleTest checkstyleIntegration checkstyleJmh -PmaxCheckstyleWarnings=0
- name: Run reviewdog
Expand Down
12 changes: 8 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ jobs:
fail-fast: false
name: ${{ matrix.tasks.alias }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/cache@v2
- uses: actions/cache@v3
with:
path: |
~/.gradle/caches
Expand All @@ -35,8 +35,6 @@ jobs:
with:
java-version: 17
distribution: 'temurin'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew assemble
- name: Run task with Gradle
Expand All @@ -48,3 +46,9 @@ jobs:
name: ${{ matrix.tasks.name }}-test-report
path: '**/build/test-results/**/TEST-*.xml'
retention-days: 90
- name: Generate test summary
uses: test-summary/action@v2
if: success() || failure()
with:
paths: '**/build/test-results/**/TEST-*.xml'
show: fail, skip
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Set up JDK 17
uses: actions/setup-java@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gradle-wrapper-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ jobs:
name: "Validation"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: gradle/wrapper-validation-action@v1
2 changes: 1 addition & 1 deletion .github/workflows/markdown-links-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
check-links:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: gaurav-nelson/github-action-markdown-link-check@v1
with:
use-quiet-mode: 'yes'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
environment: ci

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: gradle/wrapper-validation-action@v1
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ allprojects {
curator : '5.4.0',
dropwizard_metrics: '4.1.0',
micrometer_metrics: '1.11.1',
wiremock : '3.0.0-beta-10',
wiremock : '3.0.1',
spock : '2.4-M1-groovy-4.0',
groovy : '4.0.12',
alpn_api : '1.1.2.v20150522',
Expand Down
6 changes: 3 additions & 3 deletions docker/latest/management/management.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ kafka:
connectionTimeout: 3000
bootstrapKafkaServer: kafka:29092

metrics:
graphiteHttpUri: graphite:8082
graphite:
graphite:
client:
enabled: true
externalMonitoringUrl: graphite:8082

server:
port: 8090
Expand Down
52 changes: 14 additions & 38 deletions docs/docs/configuration/metrics.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,20 @@
# Metrics

Hermes Frontend and Consumers use [Dropwizard Metrics](https://dropwizard.github.io/metrics/3.1.0/) library to gather
and publish metrics to Metric Store.
Hermes Frontend, Consumers and Management use [Micrometer Metrics](https://github.com/micrometer-metrics/micrometer) library to gather
and expose metrics.

If you would like to preview or debug metrics, set `{modulePrefix}.metrics.consoleReporterEnabled` to `true`, so they will be printed
to stdout.
## Prometheus
By default, Hermes includes Prometheus reporter. It exposes metrics on `/status/prometheus` endpoint.
Reporter configuration can be configured using following options:

## Graphite
Option | Description | Default value
---------------------------------------------- |-------------------------------------------------------| -------------
{modulePrefix}.metrics.prometheus.step | The step size to use in computing windowed statistics | 60s
{modulePrefix}.metrics.prometheus.descriptions | If meter descriptions should be sent to Prometheus | true

By default, Hermes includes Graphite reporter, which can be configured using following options:
In order to be able to access basic metrics via Management API, it needs to be configured to reach VictoriaMetrics API:

Option | Description | Default value
---------------------------------------------- | -------------------------------------- | -------------
{modulePrefix}.metrics.graphiteReporterEnabled | enable Graphite reporter | false
{modulePrefix}.graphite.host | Graphite host | localhost
{modulePrefix}.graphite.port | Graphite port | 2003
{modulePrefix}.graphite.prefix | prefix for all metrics | stats.tech.hermes
{modulePrefix}.metrics.reportPeriod | how often to report metrics | 20s

In order to be able to access basic metrics via Management API, it needs to be configured to reach Graphite API:

Option | Description | Default value
----------------------- | ------------------------ | -------------
metrics.graphiteHttpUri | URI to Graphite HTTP API | http://localhost:80
metrics.prefix | prefix for all metrics | stats.tech.hermes

## Custom

You can register any custom reporter that is compatible with Dropwizard `MetricRegistry`.

For the Consumers and Frontend modules register the reporter as a bean, for example:

```java
@Configuration
public class CustomHermesConsumersConfiguration {

@Bean
@Primary
public MetricRegistry myMetricRegistry(MetricRegistry metricRegistry) {
return new MyMetricsReporter(metricRegistry);
}
}
```
Option | Description | Default value
------------------------------------------|-----------------------------------------------| -------------
prometheus.client.enabled | Should fetch external metrics from Prometheus | true
prometheus.client.externalMonitoringUrl | URI to VictoriaMetrics HTTP API | http://localhost:18090
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static TopicMetrics unavailable() {
}

public static class Builder {
private TopicMetrics topicMetrics;
private final TopicMetrics topicMetrics;

public Builder() {
topicMetrics = new TopicMetrics();
Expand Down
2 changes: 1 addition & 1 deletion hermes-client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies {

testImplementation group: 'org.spockframework', name: 'spock-core', version: versions.spock
testImplementation group: 'org.spockframework', name: 'spock-junit4', version: versions.spock
testImplementation group: 'com.github.tomakehurst', name: 'wiremock-standalone', version: versions.wiremock
testImplementation group: 'org.wiremock', name: 'wiremock-standalone', version: versions.wiremock
testImplementation group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0'
testImplementation group: 'com.jayway.jsonpath', name: 'json-path', version: '2.5.0'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import org.slf4j.LoggerFactory;
import pl.allegro.tech.hermes.common.metric.HermesMetrics;
import pl.allegro.tech.hermes.common.metric.MetricRegistryWithHdrHistogramReservoir;
import pl.allegro.tech.hermes.common.metric.counter.CounterStorage;
import pl.allegro.tech.hermes.common.metric.counter.zookeeper.ZookeeperCounterReporter;
import pl.allegro.tech.hermes.common.util.InstanceIdResolver;

import java.net.InetSocketAddress;
Expand All @@ -33,18 +31,15 @@ public class MetricRegistryFactory {
private static final Logger logger = LoggerFactory.getLogger(MetricRegistryFactory.class);
private final MetricRegistryParameters metricRegistryParameters;
private final GraphiteParameters graphiteParameters;
private final CounterStorage counterStorage;
private final InstanceIdResolver instanceIdResolver;
private final String moduleName;

public MetricRegistryFactory(MetricRegistryParameters metricRegistryParameters,
GraphiteParameters graphiteParameters,
CounterStorage counterStorage,
InstanceIdResolver instanceIdResolver,
@Named("moduleName") String moduleName) {
this.metricRegistryParameters = metricRegistryParameters;
this.graphiteParameters = graphiteParameters;
this.counterStorage = counterStorage;
this.instanceIdResolver = instanceIdResolver;
this.moduleName = moduleName;
}
Expand Down Expand Up @@ -73,14 +68,6 @@ public MetricRegistry provide() {
metricRegistryParameters.getReportPeriod().toSeconds(), TimeUnit.SECONDS
);
}

if (metricRegistryParameters.isZookeeperReporterEnabled()) {
new ZookeeperCounterReporter(registry, counterStorage, graphiteParameters.getPrefix()).start(
metricRegistryParameters.getReportPeriod().toSeconds(),
TimeUnit.SECONDS
);
}

registerJvmMetrics(registry);

return registry;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package pl.allegro.tech.hermes.common.di.factories;

import java.time.Duration;
import java.util.List;

public interface MicrometerRegistryParameters {
List<Double> getPercentiles();

boolean zookeeperReporterEnabled();

Duration zookeeperReportPeriod();
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,54 @@
import io.micrometer.core.instrument.distribution.DistributionStatisticConfig;
import io.micrometer.prometheus.PrometheusConfig;
import io.micrometer.prometheus.PrometheusMeterRegistry;
import pl.allegro.tech.hermes.common.metric.counter.CounterStorage;
import pl.allegro.tech.hermes.common.metric.counter.zookeeper.ZookeeperCounterReporter;

import java.util.concurrent.TimeUnit;

public class PrometheusMeterRegistryFactory {
private final MicrometerRegistryParameters parameters;
private final PrometheusConfig prometheusConfig;
private final CounterStorage counterStorage;
private final String prefix;

public PrometheusMeterRegistryFactory(MicrometerRegistryParameters parameters,
PrometheusConfig prometheusConfig,
String prefix) {
CounterStorage counterStorage, String prefix) {
this.parameters = parameters;
this.prometheusConfig = prometheusConfig;
this.counterStorage = counterStorage;
this.prefix = prefix + "_";
}

public PrometheusMeterRegistry provide() {
PrometheusMeterRegistry meterRegistry = new PrometheusMeterRegistry(prometheusConfig);
applyFilters(meterRegistry);
if (parameters.zookeeperReporterEnabled()) {
registerZookeeperReporter(meterRegistry);
}
return meterRegistry;
}

private void applyFilters(PrometheusMeterRegistry meterRegistry) {
meterRegistry.config().meterFilter(new MeterFilter() {
@Override
public Meter.Id map(Meter.Id id) {
return id.withName(prefix + id.getName());
}

@Override
public DistributionStatisticConfig configure(Meter.Id id,
DistributionStatisticConfig config) {
public DistributionStatisticConfig configure(Meter.Id id, DistributionStatisticConfig config) {
return DistributionStatisticConfig.builder()
.percentiles(parameters.getPercentiles().stream().mapToDouble(Double::doubleValue).toArray())
.build()
.merge(config);
.percentiles(parameters.getPercentiles()
.stream().mapToDouble(Double::doubleValue).toArray()
).build().merge(config);
}
});
return meterRegistry;
}

private void registerZookeeperReporter(PrometheusMeterRegistry meterRegistry) {
new ZookeeperCounterReporter(meterRegistry, counterStorage, prefix)
.start(parameters.zookeeperReportPeriod().toSeconds(), TimeUnit.SECONDS);
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,91 @@
package pl.allegro.tech.hermes.common.metric;

import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Tags;
import pl.allegro.tech.hermes.api.Subscription;
import pl.allegro.tech.hermes.metrics.HermesCounter;
import pl.allegro.tech.hermes.metrics.HermesTimer;
import pl.allegro.tech.hermes.metrics.counters.HermesCounters;

import java.util.function.ToDoubleFunction;

import static pl.allegro.tech.hermes.common.metric.Gauges.BATCH_BUFFER_AVAILABLE_BYTES;
import static pl.allegro.tech.hermes.common.metric.Gauges.BATCH_BUFFER_TOTAL_BYTES;
import static pl.allegro.tech.hermes.common.metric.Gauges.THREADS;
import static pl.allegro.tech.hermes.common.metric.SubscriptionTagsFactory.subscriptionTags;

public class ConsumerMetrics {
private final HermesMetrics hermesMetrics;
private final MeterRegistry meterRegistry;
private final GaugeRegistrar gaugeRegistrar;

public ConsumerMetrics(HermesMetrics hermesMetrics, MeterRegistry meterRegistry) {
this.hermesMetrics = hermesMetrics;
this.meterRegistry = meterRegistry;
this.gaugeRegistrar = new GaugeRegistrar(meterRegistry, hermesMetrics);
}

public <T> void registerQueueUtilizationGauge(T obj, String queueName, ToDoubleFunction<T> f) {
gaugeRegistrar.registerGauge("queue." + queueName + ".utilization", obj, f);
}

public HermesCounter queueFailuresCounter(String name) {
return HermesCounters.from(
meterRegistry.counter("queue." + name + ".failures"),
hermesMetrics.counter("queue." + name + ".failures")
);
}

public <T> void registerConsumerProcessesThreadsGauge(T obj, ToDoubleFunction<T> f) {
gaugeRegistrar.registerGauge(THREADS, "consumer-processes.threads", obj, f);
}

public <T> void registerRunningConsumerProcessesGauge(T obj, ToDoubleFunction<T> f) {
hermesMetrics.registerRunningConsumerProcessesCountGauge(() -> (int) f.applyAsDouble(obj));
meterRegistry.gauge("consumer-processes.running", obj, f);
}

public <T> void registerDyingConsumerProcessesGauge(T obj, ToDoubleFunction<T> f) {
hermesMetrics.registerDyingConsumerProcessesCountGauge(() -> (int) f.applyAsDouble(obj));
meterRegistry.gauge("consumer-processes.dying", obj, f);
}

public HermesTimer offsetCommitterDuration() {
public <T> void registerBatchBufferTotalBytesGauge(T obj, ToDoubleFunction<T> f) {
gaugeRegistrar.registerGauge(BATCH_BUFFER_TOTAL_BYTES, "batch-buffer.total-bytes", obj, f);
}

public <T> void registerBatchBufferAvailableBytesGauge(T obj, ToDoubleFunction<T> f) {
gaugeRegistrar.registerGauge(BATCH_BUFFER_AVAILABLE_BYTES, "batch-buffer.available-bytes", obj, f);
}

public HermesCounter oAuthSubscriptionTokenRequestCounter(Subscription subscription, String providerName) {
return HermesCounters.from(
meterRegistry.counter("oauth.token-requests", Tags.concat(
subscriptionTags(subscription.getQualifiedName()),
"provider", providerName
)),
hermesMetrics.oAuthSubscriptionTokenRequestMeter(subscription, providerName)
);
}

public HermesTimer oAuthProviderLatencyTimer(String providerName) {
return HermesTimer.from(
meterRegistry.timer("offset-committer.duration"),
hermesMetrics.timer("offset-committer.duration")
meterRegistry.timer("oauth.token-request-latency", Tags.of("provider", providerName)),
hermesMetrics.oAuthProviderLatencyTimer(providerName)
);
}

public HermesCounter processedSignalsCounter(String name) {
return HermesCounters.from(
meterRegistry.counter("signals.processed", Tags.of("signal", name)),
hermesMetrics.counter("supervisor.signal." + name)
);
}

public HermesCounter droppedSignalsCounter(String name) {
return HermesCounters.from(
meterRegistry.counter("signals.dropped", Tags.of("signal", name)),
hermesMetrics.counter("supervisor.signal.dropped." + name)
);
}
}
Loading

0 comments on commit bd82501

Please sign in to comment.