Skip to content

Commit

Permalink
Cherry-pick #26561 to 7.x: Move openmetrics module to oss (#26639)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrsMark authored Jul 1, 2021
1 parent ed539d2 commit 4b6b03c
Show file tree
Hide file tree
Showing 26 changed files with 136 additions and 82 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Collect linked account information in AWS billing. {pull}26285[26285]
- Add total CPU to vSphere virtual machine metrics. {pull}26167[26167]
- Add AWS Kinesis metricset. {pull}25989[25989]
- Move openmetrics module to oss. {pull}26561[26561]

*Packetbeat*

Expand Down
3 changes: 3 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,9 @@ def getCommonModuleInTheChangeSet(String directory) {
def exclude = "^(${directoryExclussion}|((?!\\/module\\/).)*\$|.*\\.asciidoc|.*\\.png)"
dir("${env.BASE_DIR}") {
module = getGitMatchingGroup(pattern: pattern, exclude: exclude)
if(!fileExists("${directory}/module/${module}")) {
module = ''
}
}
return module
}
Expand Down
1 change: 0 additions & 1 deletion metricbeat/docs/modules/openmetrics.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ This file is generated! See scripts/mage/docs_collector.go
////

[[metricbeat-module-openmetrics]]
[role="xpack"]
== Openmetrics module

beta[]
Expand Down
5 changes: 2 additions & 3 deletions metricbeat/docs/modules/openmetrics/collector.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ This file is generated! See scripts/mage/docs_collector.go
////

[[metricbeat-metricset-openmetrics-collector]]
[role="xpack"]
=== Openmetrics collector metricset

beta[]

include::../../../../x-pack/metricbeat/module/openmetrics/collector/_meta/docs.asciidoc[]
include::../../../module/openmetrics/collector/_meta/docs.asciidoc[]


==== Fields
Expand All @@ -20,5 +19,5 @@ Here is an example document generated by this metricset:

[source,json]
----
include::../../../../x-pack/metricbeat/module/openmetrics/collector/_meta/data.json[]
include::../../../module/openmetrics/collector/_meta/data.json[]
----
2 changes: 2 additions & 0 deletions metricbeat/include/list_common.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions metricbeat/metricbeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,19 @@ metricbeat.modules:
# Path to server status. Default nginx_status
server_status_path: "nginx_status"

#----------------------------- Openmetrics Module -----------------------------
- module: openmetrics
metricsets: ['collector']
period: 10s
hosts: ['localhost:9090']

# This module uses the Prometheus collector metricset, all
# the options for this metricset are also available here.
metrics_path: /metrics
metrics_filters:
include: []
exclude: []

#------------------------------- PHP_FPM Module -------------------------------
- module: php_fpm
metricsets:
Expand Down
42 changes: 42 additions & 0 deletions metricbeat/module/openmetrics/collector/collector.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. 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 collector

import (
"github.com/elastic/beats/v7/metricbeat/mb"
"github.com/elastic/beats/v7/metricbeat/mb/parse"
"github.com/elastic/beats/v7/metricbeat/module/prometheus/collector"
)

const (
defaultScheme = "http"
defaultPath = "/metrics"
)

var (
hostParser = parse.URLHostParserBuilder{
DefaultScheme: defaultScheme,
DefaultPath: defaultPath,
}.Build()
)

func init() {
mb.Registry.MustAddMetricSet("openmetrics", "collector",
collector.MetricSetBuilder("openmetrics", collector.DefaultPromEventsGeneratorFactory),
mb.WithHostParser(hostParser))
}
32 changes: 32 additions & 0 deletions metricbeat/module/openmetrics/collector/collector_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. 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.

// +build !integration

package collector

import (
"testing"

mbtest "github.com/elastic/beats/v7/metricbeat/mb/testing"

_ "github.com/elastic/beats/v7/metricbeat/module/openmetrics"
)

func TestData(t *testing.T) {
mbtest.TestDataFiles(t, "openmetrics", "collector")
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import metricbeat
import os
import sys
import unittest
from xpack_metricbeat import XPackTest, metricbeat


class Test(XPackTest):
class Test(metricbeat.BaseTest):

COMPOSE_SERVICES = ['openmetrics-node_exporter']

Expand All @@ -19,7 +19,7 @@ def test_openmetrics(self):
"hosts": self.get_hosts(),
"period": "5s",
}])
proc = self.start_beat(home=self.beat_path)
proc = self.start_beat()
self.wait_until(lambda: self.output_lines() > 0, 60)
proc.check_kill_and_wait()
self.assert_no_logged_warnings()
Expand Down
2 changes: 0 additions & 2 deletions x-pack/metricbeat/include/list.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 22 additions & 22 deletions x-pack/metricbeat/metricbeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1144,9 +1144,11 @@ metricbeat.modules:
# Password to use when connecting to PostgreSQL. Empty by default.
#password: pass

#----------------------- Prometheus Typed Metrics Module -----------------------
#------------------------------ Prometheus Module ------------------------------
# Metrics collected from a Prometheus endpoint
- module: prometheus
period: 10s
metricsets: ["collector"]
hosts: ["localhost:9090"]
metrics_path: /metrics
#metrics_filters:
Expand All @@ -1160,12 +1162,6 @@ metricbeat.modules:
#ssl.certificate_authorities:
# - /var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt

# Use Elasticsearch histogram type to store histograms (beta, default: false)
# This will change the default layout and put metric type in the field name
#use_types: true

# Store counter rates instead of original cumulative counters (experimental, default: false)
#rate_counters: true

# Metrics sent by a Prometheus server using remote_write option
#- module: prometheus
Expand All @@ -1177,18 +1173,6 @@ metricbeat.modules:
#ssl.certificate: "/etc/pki/server/cert.pem"
#ssl.key: "/etc/pki/server/cert.key"

# Use Elasticsearch histogram type to store histograms (beta, default: false)
# This will change the default layout and put metric type in the field name
#use_types: true

# Store counter rates instead of original cumulative counters (experimental, default: false)
#rate_counters: true

# Define patterns for counter and histogram types so as to identify metrics' types according to these patterns
#types_patterns:
# counter_patterns: []
# histogram_patterns: []

# Metrics that will be collected using a PromQL
#- module: prometheus
# metricsets: ["query"]
Expand All @@ -1215,11 +1199,9 @@ metricbeat.modules:
# params:
# query: "some_value"

#------------------------------ Prometheus Module ------------------------------
# Metrics collected from a Prometheus endpoint
#----------------------- Prometheus Typed Metrics Module -----------------------
- module: prometheus
period: 10s
metricsets: ["collector"]
hosts: ["localhost:9090"]
metrics_path: /metrics
#metrics_filters:
Expand All @@ -1233,6 +1215,12 @@ metricbeat.modules:
#ssl.certificate_authorities:
# - /var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt

# Use Elasticsearch histogram type to store histograms (beta, default: false)
# This will change the default layout and put metric type in the field name
#use_types: true

# Store counter rates instead of original cumulative counters (experimental, default: false)
#rate_counters: true

# Metrics sent by a Prometheus server using remote_write option
#- module: prometheus
Expand All @@ -1244,6 +1232,18 @@ metricbeat.modules:
#ssl.certificate: "/etc/pki/server/cert.pem"
#ssl.key: "/etc/pki/server/cert.key"

# Use Elasticsearch histogram type to store histograms (beta, default: false)
# This will change the default layout and put metric type in the field name
#use_types: true

# Store counter rates instead of original cumulative counters (experimental, default: false)
#rate_counters: true

# Define patterns for counter and histogram types so as to identify metrics' types according to these patterns
#types_patterns:
# counter_patterns: []
# histogram_patterns: []

# Metrics that will be collected using a PromQL
#- module: prometheus
# metricsets: ["query"]
Expand Down
29 changes: 0 additions & 29 deletions x-pack/metricbeat/module/openmetrics/collector/collector.go

This file was deleted.

19 changes: 0 additions & 19 deletions x-pack/metricbeat/module/openmetrics/collector/collector_test.go

This file was deleted.

0 comments on commit 4b6b03c

Please sign in to comment.