Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prometheus metric exporter #10412

Merged
merged 45 commits into from
Mar 9, 2021
Merged
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
ccbfbb7
prometheus-emitter
Oct 2, 2019
bb8eb39
use existing jetty server to expose prometheus collection endpoint
Oct 2, 2019
ad43466
unused variables
Oct 2, 2019
b04eaba
better variable names
Oct 2, 2019
82f408b
removed unused dependencies
Oct 2, 2019
b6750cc
more metric definitions
Oct 3, 2019
2dc2ced
reorganize
Oct 3, 2019
c2a7131
use prometheus HTTPServer instead of hooking into Jetty server
Oct 3, 2019
5a91cc0
temporary empty help string
Oct 3, 2019
a7851af
temporary non-empty help. fix incorrect dimension value in JSON (als…
Oct 3, 2019
a213638
added full help text. added metric conversion factor for timers that…
Oct 3, 2019
2ec1a9b
added documentation for prometheus emitter
Oct 3, 2019
13d3fc3
safety for invalid labelNames
Oct 4, 2019
cd392eb
fix travis checks
Oct 4, 2019
8246c3c
Unit test and better sanitization of metrics names and label values
Oct 4, 2019
8ab89f2
add precondition to check namespace against regex
Oct 4, 2019
9b4c70d
use precompiled regex
Oct 4, 2019
5221655
remove static imports. fix metric types
Oct 7, 2019
abae5c0
better docs. fix possible NPE in PrometheusEmitterConfig. Guard again…
Oct 10, 2019
fa4a985
Update regex for label-value replacements to allow internal numeric v…
Nov 27, 2019
5689f44
Adds missing license header
michaelschiff Jan 29, 2020
1c35595
fixes version in extensions-contrib/prometheus-emitter
michaelschiff Jan 29, 2020
456486a
fix style guide errors
michaelschiff Jan 29, 2020
8827fbf
update import ordering
michaelschiff Jan 29, 2020
ba4a672
add another word to website/.spelling
michaelschiff Jan 29, 2020
7aed5e1
remove unthrown declared exception
Mar 29, 2020
f079d67
remove unused import
Mar 29, 2020
76278f1
Pushgateway strategy for metrics
Apr 6, 2020
1e2e78c
typo
Apr 6, 2020
45412cc
Format fix and nullable strategy
Jun 9, 2020
6c248ce
Update pom file for prometheus-emitter
Sep 21, 2020
7d4f765
code review comments. Counter to gauge for cache metrics, periodical …
Nov 1, 2020
4d90a41
Syntax fix
Jan 5, 2021
3a7a2b6
Dimension label regex include numeric character back, fix previous co…
Jan 5, 2021
b61f1b3
bump prometheus-emitter pom dev version
Jan 16, 2021
b1b8d61
Remove scheduled task inside poen that push metrics
Jan 16, 2021
e7e9e2f
Fix checkstyle
Feb 7, 2021
bffc63d
Merge branch 'master' into feature/prometheus-metric-exporter
Feb 7, 2021
b405b55
Unit test coverage
Feb 10, 2021
a449027
Merge branch 'master' into feature/prometheus-metric-exporter
Feb 10, 2021
8f3463f
Unit test coverage
Feb 16, 2021
5cafe2f
Spelling
Feb 16, 2021
c507452
Merge branch 'master' into feature/prometheus-metric-exporter
Feb 27, 2021
42048a5
Doc fix
Mar 2, 2021
807f8dd
spelling
Mar 2, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions docs/development/extensions-contrib/prometheus.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
id: prometheus
title: "Prometheus Emitter"
---

<!--
~ Licensed to the Apache Software Foundation (ASF) under one
~ or more contributor license agreements. See the NOTICE file
~ distributed with this work for additional information
~ regarding copyright ownership. The ASF licenses this file
~ to you under the Apache License, Version 2.0 (the
~ "License"); you may not use this file except in compliance
~ with the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->


To use this Apache Druid extension, make sure to [include](../../development/extensions.md#loading-extensions) `prometheus-emitter` extension.

## Introduction

This extension exposes [Druid metrics](https://druid.apache.org/docs/latest/operations/metrics.html) for collection by a Prometheus server (https://prometheus.io/).
Emitter is enabled by setting `druid.emitter=prometheus` [configs](https://druid.apache.org/docs/latest/configuration/index.html#emitting-metrics) or include `prometheus` in the composing emitter list.

## Configuration

All the configuration parameters for the Prometheus emitter are under `druid.emitter.prometheus`.

|property|description|required?|default|
|--------|-----------|---------|-------|
|`druid.emitter.prometheus.strategy`|The strategy to expose prometheus metrics. Default strategy `exporter` would expose metrics for scraping purpose. Only peon task (short-lived jobs) need to use `pushgateway` strategy.|yes|exporter|
|`druid.emitter.prometheus.port`|The port on which to expose the prometheus HTTPServer. Required if using exporter strategy.|no|none|
|`druid.emitter.prometheus.namespace`|Optional metric namespace. Must match the regex `[a-zA-Z_:][a-zA-Z0-9_:]*`|no|"druid"|
|`druid.emitter.prometheus.dimensionMapPath`|JSON file defining the Prometheus metric type, desired dimensions, help text, and conversionFactor for every Druid metric.|no|Default mapping provided. See below.|
|`druid.emitter.prometheus.pushGatewayAddress`|Pushgateway address. Required if using Pushgateway strategy|no|none|


### Metric names

All metric names and labels are reformatted to match Prometheus standards.
- For names: all characters which are not alphanumeric, underscores, or colons (matching `[^a-zA-Z_:][^a-zA-Z0-9_:]*`) are replaced with `_`
- For labels: all characters which are not alphanumeric or underscores (matching `[^a-zA-Z0-9_][^a-zA-Z0-9_]*`) are replaced with `_`

### Metric mapping

Each metric to be collected by Prometheus must specify a type, one of `[timer, counter, guage]`. Prometheus Emitter expects this mapping to
be provided as a JSON file. Additionally, this mapping specifies which dimensions should be included for each metric. Prometheus expects
histogram timers to use Seconds as the base unit. Timers which do not use seconds as a base unit can use the `conversionFactor` to set
the base time unit. If the user does not specify their own JSON file, a default mapping is used. All
metrics are expected to be mapped. Metrics which are not mapped will not be tracked.
Prometheus metric path is organized using the following schema:
`<druid metric name> : { "dimensions" : <dimension list>, "type" : <timer|counter|gauge>, conversionFactor: <conversionFactor>, "help" : <help text>,}`
e.g.
`query/time" : { "dimensions" : ["dataSource", "type"], "conversionFactor": 1000.0, "type" : "timer", "help": "Seconds taken to complete a query."}`

For metrics which are emitted from multiple services with different dimensions, the metric name is prefixed with
the service name.
e.g.
`"coordinator-segment/count" : { "dimensions" : ["dataSource"], "type" : "gauge" },
"historical-segment/count" : { "dimensions" : ["dataSource", "tier", "priority"], "type" : "gauge" }`

For most use-cases, the default mapping is sufficient.
123 changes: 123 additions & 0 deletions extensions-contrib/prometheus-emitter/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one
~ or more contributor license agreements. See the NOTICE file
~ distributed with this work for additional information
~ regarding copyright ownership. The ASF licenses this file
~ to you under the Apache License, Version 2.0 (the
~ "License"); you may not use this file except in compliance
~ with the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>druid</artifactId>
<groupId>org.apache.druid</groupId>
<version>0.22.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<groupId>org.apache.druid.extensions.contrib</groupId>
<artifactId>prometheus-emitter</artifactId>
<name>prometheus-emitter</name>
<description>Extension support for collecting Druid metrics with Prometheus</description>

<dependencies>
<dependency>
<groupId>org.apache.druid</groupId>
<artifactId>druid-core</artifactId>
<version>${project.parent.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient</artifactId>
<version>0.7.0</version>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_httpserver</artifactId>
<version>0.7.0</version>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_pushgateway</artifactId>
<version>0.7.0</version>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>pl.pragmatists</groupId>
<artifactId>JUnitParams</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.druid</groupId>
<artifactId>druid-server</artifactId>
<version>${project.parent.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.druid</groupId>
<artifactId>druid-processing</artifactId>
<version>${project.parent.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.druid.emitter.prometheus;

import io.prometheus.client.SimpleCollector;

public class DimensionsAndCollector
{
private final String[] dimensions;
private final SimpleCollector collector;
private final double conversionFactor;

DimensionsAndCollector(String[] dimensions, SimpleCollector collector, double conversionFactor)
{
this.dimensions = dimensions;
this.collector = collector;
this.conversionFactor = conversionFactor;
}

public String[] getDimensions()
{
return dimensions;
}

public SimpleCollector getCollector()
{
return collector;
}

public double getConversionFactor()
{
return conversionFactor;
}
}
Loading