Skip to content

Commit d1a459b

Browse files
committed
Fix generated metricbeat so create-metricset works. (#18020)
* Fix generated metricbeat so create-metricset works. * Fix mage target add target to x-pack/metricbeat. (cherry picked from commit 77f0d20)
1 parent 6858550 commit d1a459b

6 files changed

Lines changed: 67 additions & 28 deletions

File tree

generator/_templates/metricbeat/{beat}/magefile.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ import (
1616
"github.com/elastic/beats/v7/dev-tools/mage/target/unittest"
1717
"github.com/elastic/beats/v7/generator/common/beatgen"
1818
metricbeat "github.com/elastic/beats/v7/metricbeat/scripts/mage"
19+
20+
// mage:import
21+
_ "github.com/elastic/beats/v7/metricbeat/scripts/mage/target/metricset"
1922
)
2023

2124
func init() {

metricbeat/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ ES_BEATS ?= ..
33
include $(ES_BEATS)/dev-tools/make/mage.mk
44

55
# Creates a new metricset. Requires the params MODULE and METRICSET
6-
.PHONY: create-metricset
6+
.PHONY: create-metricset
77
create-metricset:
88
mage createMetricset

metricbeat/magefile.go

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
"time"
2828

2929
"github.com/magefile/mage/mg"
30-
"github.com/magefile/mage/sh"
3130

3231
devtools "github.com/elastic/beats/v7/dev-tools/mage"
3332
metricbeat "github.com/elastic/beats/v7/metricbeat/scripts/mage"
@@ -48,6 +47,8 @@ import (
4847
"github.com/elastic/beats/v7/dev-tools/mage/target/unittest"
4948
// mage:import
5049
_ "github.com/elastic/beats/v7/dev-tools/mage/target/compose"
50+
// mage:import
51+
_ "github.com/elastic/beats/v7/metricbeat/scripts/mage/target/metricset"
5152
)
5253

5354
func init() {
@@ -197,29 +198,3 @@ func PythonIntegTest(ctx context.Context) error {
197198
return devtools.PythonNoseTest(devtools.DefaultPythonTestIntegrationArgs())
198199
})
199200
}
200-
201-
// CreateMetricset creates a new metricset.
202-
//
203-
// Required ENV variables:
204-
// * MODULE: Name of the module
205-
// * METRICSET: Name of the metricset
206-
func CreateMetricset(ctx context.Context) error {
207-
ve, err := devtools.PythonVirtualenv()
208-
if err != nil {
209-
return err
210-
}
211-
python, err := devtools.LookVirtualenvPath(ve, "python")
212-
if err != nil {
213-
return err
214-
}
215-
path, err := os.Getwd()
216-
if err != nil {
217-
return err
218-
}
219-
220-
_, err = sh.Exec(
221-
map[string]string{}, os.Stdout, os.Stderr, python, "scripts/create_metricset.py",
222-
"--path", path, "--module", os.Getenv("MODULE"), "--metricset", os.Getenv("METRICSET"),
223-
)
224-
return err
225-
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Licensed to Elasticsearch B.V. under one or more contributor
2+
// license agreements. See the NOTICE file distributed with
3+
// this work for additional information regarding copyright
4+
// ownership. Elasticsearch B.V. licenses this file to you under
5+
// the Apache License, Version 2.0 (the "License"); you may
6+
// not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package metricset
19+
20+
import (
21+
"os"
22+
"path/filepath"
23+
24+
"github.com/magefile/mage/sh"
25+
26+
devtools "github.com/elastic/beats/v7/dev-tools/mage"
27+
)
28+
29+
// CreateMetricset creates a new metricset.
30+
//
31+
// Required ENV variables:
32+
// * MODULE: Name of the module
33+
// * METRICSET: Name of the metricset
34+
func CreateMetricset() error {
35+
ve, err := devtools.PythonVirtualenv()
36+
if err != nil {
37+
return err
38+
}
39+
python, err := devtools.LookVirtualenvPath(ve, "python")
40+
if err != nil {
41+
return err
42+
}
43+
beatsDir, err := devtools.ElasticBeatsDir()
44+
if err != nil {
45+
return err
46+
}
47+
scriptPath := filepath.Join(beatsDir, "metricbeat", "scripts", "create_metricset.py")
48+
49+
_, err = sh.Exec(
50+
map[string]string{}, os.Stdout, os.Stderr, python, scriptPath,
51+
"--path", devtools.CWD(), "--module", os.Getenv("MODULE"), "--metricset", os.Getenv("METRICSET"),
52+
)
53+
return err
54+
}

x-pack/metricbeat/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
ES_BEATS ?= ../..
22

33
include $(ES_BEATS)/dev-tools/make/mage.mk
4+
5+
# Creates a new metricset. Requires the params MODULE and METRICSET
6+
.PHONY: create-metricset
7+
create-metricset:
8+
mage createMetricset

x-pack/metricbeat/magefile.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import (
2424
"github.com/elastic/beats/v7/dev-tools/mage/target/unittest"
2525
// mage:import
2626
"github.com/elastic/beats/v7/dev-tools/mage/target/test"
27+
// mage:import
28+
_ "github.com/elastic/beats/v7/metricbeat/scripts/mage/target/metricset"
2729
)
2830

2931
func init() {

0 commit comments

Comments
 (0)