Skip to content

Commit

Permalink
Migrated to opendistro 1.0.0-rc1
Browse files Browse the repository at this point in the history
  • Loading branch information
aparo committed Jun 24, 2021
1 parent ff86a44 commit dbd13a1
Show file tree
Hide file tree
Showing 22 changed files with 166 additions and 228 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ gradle-wrapper.properties

# Mac
.DS_Store
.metals/
.vscode/
94 changes: 15 additions & 79 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
![CI](https://github.com/vvanholl/elasticsearch-prometheus-exporter/workflows/CI/badge.svg?branch=master)
# Prometheus Exporter Plugin for OpenSearch

# Prometheus Exporter Plugin for Elasticsearch

This is a builtin exporter from Elasticsearch to Prometheus.
It collects all relevant metrics and makes them available to Prometheus via the Elasticsearch REST API.
This is a builtin exporter from OpenSearch to Prometheus based on the code of Vincent Van Hollebeke and others at https://github.com/vvanholl/elasticsearch-prometheus-exporter .
It collects all relevant metrics and makes them available to Prometheus via the OpenSearch REST API.

**Currently, the available metrics are:**

Expand All @@ -19,54 +17,19 @@ It collects all relevant metrics and makes them available to Prometheus via the
- File System
- Circuit Breaker
- Indices status
- Cluster settings (selected [disk allocation settings](https://www.elastic.co/guide/en/elasticsearch/reference/master/disk-allocator.html) only)
- Cluster settings

## Compatibility matrix

### Version 7.X

| Elasticsearch | Plugin | Release date |
| -------------- | -------------- | ------------ |
| 7.13.2 | 7.13.2.0 | Jun 15, 2021 |
| 7.13.1 | 7.13.1.0 | Jun 12, 2021 |
| 7.13.0 | 7.13.0.0 | May 27, 2021 |
| 7.12.1 | 7.12.1.0 | May 01, 2021 |
| 7.12.0 | 7.12.0.0 | Apr 04, 2021 |
| 7.11.2 | 7.11.2.0 | Mar 20, 2021 |
| 7.11.1 | 7.11.1.0 | Feb 22, 2021 |
| 7.10.2 | 7.10.2.0 | Jan 24, 2021 |
| 7.10.1 | 7.10.1.0 | Dec 13, 2020 |
| 7.10.0 | 7.10.0.0 | Nov 15, 2020 |
| 7.9.3 | 7.9.3.0 | Oct 22, 2020 |
| 7.9.2 | 7.9.2.0 | Oct 04, 2020 |
| 7.9.1 | 7.9.1.0 | Sep 06, 2020 |
| 7.9.0 | 7.9.0.0 | Aug 18, 2020 |
| 7.8.1 | 7.8.1.0 | Aug 10, 2020 |
| 7.8.0 | 7.8.0.0 | Jun 22, 2020 |
| 7.7.1 | 7.7.1.0 | Jun 04, 2020 |
| 7.7.0 | 7.7.0.0 | May 14, 2020 |
| 7.6.2 | 7.6.2.0 | Apr 6, 2020 |
| 7.6.1 | 7.6.1.0 | Mar 30, 2020 |
| 7.6.0 | 7.6.0.0 | Feb 12, 2020 |
| 7.5.2 | 7.5.2.0 | Jan 25, 2020 |
| 7.5.1 | 7.5.1.0 | Jan 21, 2020 |
| 7.5.0 | 7.5.0.0 | Jan 16, 2020 |
| 7.4.2 | 7.4.2.0 | Jan 13, 2020 |
| 7.4.1 | 7.4.1.0 | Jan 13, 2020 |
| 7.4.0 | 7.4.0.0 | Jan 07, 2020 |
| 7.3.2 | 7.3.2.0 | Oct 05, 2019 |
| 7.3.1 | 7.3.1.0 | Sep 18, 2019 |
| 7.3.0 | 7.3.0.0 | Sep 17, 2019 |
| 7.2.1 | 7.2.1.0 | Jul 31, 2019 |
| 7.2.0 | 7.2.0.0 | Jul 12, 2019 |
| 7.1.1 | 7.1.1.0 | May 31, 2019 |
| 7.1.0 | 7.1.0.0 | May 23, 2019 |
| 7.0.1 | 7.0.1.0 | May 08, 2019 |
| 7.0.0 | 7.0.0.0 | Apr 11, 2019 |
### Versions

| OpenSearch | Plugin | Release date |
| ----------- | -------------- | ------------ |
| 1.0.0-RC1 | 1.0.0-RC1 | Jun 24, 2021 |

## Install

`./bin/elasticsearch-plugin install -b https://github.com/vvanholl/elasticsearch-prometheus-exporter/releases/download/7.13.2.0/prometheus-exporter-7.13.2.0.zip`
`./bin/opensearch-plugin install -b https://github.com/aparo/opensearch-prometheus-exporter/releases/download/1.0.0-RC1/prometheus-exporter-1.0.0-RC1.zip`

**Do not forget to restart the node after the installation!**

Expand All @@ -87,19 +50,19 @@ To disable exporting cluster settings use:
prometheus.cluster.settings: false
```

These settings can be also [updated dynamically](https://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-update-settings.html).
These settings can be also [updated dynamically](https://www.elastic.co/guide/en/opensearch/reference/master/cluster-update-settings.html).

## Uninstall

`./bin/elasticsearch-plugin remove prometheus-exporter`
`./bin/opensearch-plugin remove prometheus-exporter`

Do not forget to restart the node after installation!

## Usage

Metrics are directly available at:

http://<your-elasticsearch-host>:9200/_prometheus/metrics
http://<your-opensearch-host>:9200/_prometheus/metrics

As a sample result, you get:

Expand Down Expand Up @@ -134,7 +97,7 @@ On your Prometheus servers, configure a new job as usual.
For example, if you have a cluster of 3 nodes:

```YAML
- job_name: elasticsearch
- job_name: opensearch
scrape_interval: 10s
metrics_path: "/_prometheus/metrics"
static_configs:
Expand All @@ -148,34 +111,7 @@ Of course, you could use the service discovery service instead of a static confi
Just keep in mind that `metrics_path` must be `/_prometheus/metrics`, otherwise Prometheus will find no metric.

## Project sources

The Maven project site is available at [GitHub](https://github.com/vvanholl/elasticsearch-prometheus-exporter).

## Testing

Project contains [integration tests](src/test/resources/rest-api-spec) implemented using
[rest layer](https://github.com/elastic/elasticsearch/blob/master/TESTING.asciidoc#testing-the-rest-layer)
framework.

To run everything similar to the GitHub Actions pipeline you can do:
```
docker run -v $(pwd):/home/gradle gradle:7.0.2-jdk16 su gradle -c 'gradle check'
```
NOTE: Please keep version in sync with .github/workflows/ci.yml


Complete test suite is run using:
```
gradle clean check
```

To run individual test file use:
```
gradle :integTest \
-Dtests.class=org.elasticsearch.rest.PrometheusRestHandlerClientYamlTestSuiteIT \
-Dtests.method="test {yaml=resthandler/20_metrics/Prometheus metrics can be pulled}"
```
If you enable security in OpenSearch, remember to set up the credentials also in Prometheus configuration.

## Credits

Expand Down
18 changes: 9 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ buildscript {
}

dependencies {
classpath "org.elasticsearch.gradle:build-tools:${es_version}"
classpath "org.opensearch.gradle:build-tools:${es_version}"
classpath group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.0'
classpath group: 'com.sun.xml.bind', name: 'jaxb-core', version: '2.3.0'
classpath group: 'com.sun.xml.bind', name: 'jaxb-impl', version: '2.3.0'
Expand All @@ -27,9 +27,9 @@ plugins {

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'elasticsearch.esplugin'
apply plugin: 'elasticsearch.rest-resources'
apply plugin: 'elasticsearch.testclusters'
apply plugin: 'opensearch.opensearchplugin'
apply plugin: 'opensearch.rest-resources'
apply plugin: 'opensearch.testclusters'

// Uncomment if you want to use: System.out.println("Emergency!");
// Logs are found in build/testcluster/integTest-*/logs/ folder.
Expand All @@ -43,7 +43,7 @@ licenseFile = rootProject.file('LICENSE.txt')
noticeFile = rootProject.file('NOTICE.txt')

// POM validation can be enabled
validateElasticPom.enabled = false
validatePom.enabled = false

// No unit tests in this plugin
test.enabled = false
Expand All @@ -60,7 +60,7 @@ repositories {

ext {
versions = [
"elasticsearch": es_version,
"opensearch": es_version,
"prometheus" : "0.8.0",
"log4j" : "2.11.1",
"junit" : "4.12"
Expand All @@ -71,14 +71,14 @@ configurations {
runtime
releaseJars {
extendsFrom runtime
exclude group: "org.elasticsearch"
exclude group: "org.opensearch"
exclude group: "com.fasterxml.jackson.core", module: "jackson-core"
exclude group: "org.apache.logging.log4j"
}
}

dependencies {
api "org.elasticsearch:elasticsearch:${versions.elasticsearch}"
api "org.opensearch:opensearch:${versions.opensearch}"
api "io.prometheus:simpleclient:${versions.prometheus}"
api "io.prometheus:simpleclient_common:${versions.prometheus}"
api "org.apache.logging.log4j:log4j-api:${versions.log4j}"
Expand All @@ -92,7 +92,7 @@ tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked,deprecation"
}

esplugin {
opensearchplugin {
licenseFile rootProject.file('LICENSE.txt')
noticeFile rootProject.file('NOTICE.txt')
name pluginName
Expand Down
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
group = org.elasticsearch.plugin.prometheus
group = org.opensearch.plugin.prometheus

version = 7.13.2.1-SNAPSHOT
version = 1.0.0-rc1

pluginName = prometheus-exporter
pluginClassname = org.elasticsearch.plugin.prometheus.PrometheusExporterPlugin
pluginDescription = Export Elasticsearch metrics to Prometheus
pluginClassname = org.opensearch.plugin.prometheus.PrometheusExporterPlugin
pluginDescription = Export OpenSearch metrics to Prometheus

github_token = secret
github_owner = vvanholl
github_repo = elasticsearch-prometheus-exporter
github_owner = aparo
github_repo = opensearch-prometheus-exporter
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.rest.prometheus.RestPrometheusMetricsAction;
import org.opensearch.rest.prometheus.RestPrometheusMetricsAction;

import java.io.IOException;
import java.io.StringWriter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,26 @@

package org.compuscene.metrics.prometheus;

import org.elasticsearch.action.ClusterStatsData;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.cluster.node.stats.NodeStats;
import org.elasticsearch.action.admin.indices.stats.CommonStats;
import org.elasticsearch.action.admin.indices.stats.IndexStats;
import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
import org.elasticsearch.cluster.health.ClusterIndexHealth;
import org.elasticsearch.cluster.node.DiscoveryNodeRole;
import org.elasticsearch.http.HttpStats;
import org.elasticsearch.indices.NodeIndicesStats;
import org.elasticsearch.indices.breaker.AllCircuitBreakerStats;
import org.elasticsearch.indices.breaker.CircuitBreakerStats;
import org.elasticsearch.ingest.IngestStats;
import org.elasticsearch.monitor.fs.FsInfo;
import org.elasticsearch.monitor.jvm.JvmStats;
import org.elasticsearch.monitor.os.OsStats;
import org.elasticsearch.monitor.process.ProcessStats;
import org.elasticsearch.script.ScriptStats;
import org.elasticsearch.threadpool.ThreadPoolStats;
import org.elasticsearch.transport.TransportStats;
import org.opensearch.action.ClusterStatsData;
import org.opensearch.action.admin.cluster.health.ClusterHealthResponse;
import org.opensearch.action.admin.cluster.node.stats.NodeStats;
import org.opensearch.action.admin.indices.stats.CommonStats;
import org.opensearch.action.admin.indices.stats.IndexStats;
import org.opensearch.action.admin.indices.stats.IndicesStatsResponse;
import org.opensearch.cluster.health.ClusterIndexHealth;
import org.opensearch.cluster.node.DiscoveryNodeRole;
import org.opensearch.http.HttpStats;
import org.opensearch.indices.NodeIndicesStats;
import org.opensearch.indices.breaker.AllCircuitBreakerStats;
import org.opensearch.indices.breaker.CircuitBreakerStats;
import org.opensearch.ingest.IngestStats;
import org.opensearch.monitor.fs.FsInfo;
import org.opensearch.monitor.jvm.JvmStats;
import org.opensearch.monitor.os.OsStats;
import org.opensearch.monitor.process.ProcessStats;
import org.opensearch.script.ScriptStats;
import org.opensearch.threadpool.ThreadPoolStats;
import org.opensearch.transport.TransportStats;

import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -130,7 +130,7 @@ private void registerNodeMetrics() {
private void updateNodeMetrics(NodeStats ns) {
if (ns != null) {

// Plugins can introduce custom node roles from 7.3.0: https://github.com/elastic/elasticsearch/pull/43175
// Plugins can introduce custom node roles from 7.3.0: https://github.com/elastic/opensearch/pull/43175
// TODO(lukas-vlcek): List of node roles can not be static but needs to be created dynamically.
Map<String, Integer> roles = new HashMap<>();

Expand Down Expand Up @@ -413,7 +413,7 @@ private void registerPerIndexMetrics() {
catalog.registerClusterGauge("index_fielddata_evictions_count", "Count of evictions in field data cache", "index", "context");

// Percolator cache was removed in ES 5.x
// See https://github.com/elastic/elasticsearch/commit/80fee8666ff5dd61ba29b175857cf42ce3b9eab9
// See https://github.com/elastic/opensearch/commit/80fee8666ff5dd61ba29b175857cf42ce3b9eab9

catalog.registerClusterGauge("index_completion_size_bytes", "Size of completion suggest statistics", "index", "context");

Expand Down Expand Up @@ -530,7 +530,7 @@ private void updatePerIndexContextMetrics(String indexName, String context, Comm
catalog.setClusterGauge("index_fielddata_evictions_count", idx.getFieldData().getEvictions(), indexName, context);

// Percolator cache was removed in ES 5.x
// See https://github.com/elastic/elasticsearch/commit/80fee8666ff5dd61ba29b175857cf42ce3b9eab9
// See https://github.com/elastic/opensearch/commit/80fee8666ff5dd61ba29b175857cf42ce3b9eab9

catalog.setClusterGauge("index_completion_size_bytes", idx.getCompletion().getSizeInBytes(), indexName, context);

Expand Down Expand Up @@ -902,8 +902,8 @@ private void registerESSettings() {
private void updateESSettings(ClusterStatsData stats) {
if (stats != null) {
catalog.setClusterGauge("cluster_routing_allocation_disk_threshold_enabled", Boolean.TRUE.equals(stats.getThresholdEnabled()) ? 1 : 0);
// According to Elasticsearch documentation the following settings must be set either in pct or bytes size.
// Mixing is not allowed. We rely on Elasticsearch to do all necessary checks and we simply
// According to OpenSearch documentation the following settings must be set either in pct or bytes size.
// Mixing is not allowed. We rely on OpenSearch to do all necessary checks and we simply
// output all those metrics that are not null. If this will lead to mixed metric then we do not
// consider it our fault.
if (stats.getDiskLowInBytes() != null) { catalog.setClusterGauge("cluster_routing_allocation_disk_watermark_low_bytes", stats.getDiskLowInBytes()); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@

package org.compuscene.metrics.prometheus;

import org.elasticsearch.common.settings.ClusterSettings;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import org.opensearch.common.settings.ClusterSettings;
import org.opensearch.common.settings.Setting;
import org.opensearch.common.settings.Settings;

/**
* A container to keep settings for prometheus up to date with cluster setting changes.
*
* In order to make the settings dynamically updatable we took some inspiration from implementation
* and use of DiskThresholdSettings class in Elasticsearch.
* and use of DiskThresholdSettings class in OpenSearch.
*/
public class PrometheusSettings {

// These settings become part of cluster state available via HTTP at
// curl <elasticsearch>/_cluster/settings?include_defaults=true&filter_path=defaults.prometheus
// curl <opensearch>/_cluster/settings?include_defaults=true&filter_path=defaults.prometheus
// It is important to keep it under reasonable namespace to avoid collision with
// other plugins or future/commercial parts of Elastic Stack itself.
// Namespace "prometheus" sounds like safe bet for now.
Expand Down
Loading

0 comments on commit dbd13a1

Please sign in to comment.