Skip to content

Commit

Permalink
Move openmetrics module to oss (#26561)
Browse files Browse the repository at this point in the history
(cherry picked from commit 92143fe)
  • Loading branch information
ChrsMark committed Jul 1, 2021
1 parent fb55165 commit 836a4f5
Show file tree
Hide file tree
Showing 25 changed files with 114 additions and 60 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,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.

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 836a4f5

Please sign in to comment.