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

Fix generated metricbeat so create-metricset works. #18020

Merged
merged 2 commits into from
Apr 28, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
3 changes: 3 additions & 0 deletions generator/_templates/metricbeat/{beat}/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import (
"github.com/elastic/beats/v7/dev-tools/mage/target/unittest"
"github.com/elastic/beats/v7/generator/common/beatgen"
metricbeat "github.com/elastic/beats/v7/metricbeat/scripts/mage"

// mage:import
_ "github.com/elastic/beats/v7/metricbeat/scripts/mage/target/metricset"
)

func init() {
Expand Down
29 changes: 2 additions & 27 deletions metricbeat/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"time"

"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"

devtools "github.com/elastic/beats/v7/dev-tools/mage"
metricbeat "github.com/elastic/beats/v7/metricbeat/scripts/mage"
Expand All @@ -48,6 +47,8 @@ import (
"github.com/elastic/beats/v7/dev-tools/mage/target/unittest"
// mage:import
_ "github.com/elastic/beats/v7/dev-tools/mage/target/compose"
// mage:import
_ "github.com/elastic/beats/v7/metricbeat/scripts/mage/target/metricset"
blakerouse marked this conversation as resolved.
Show resolved Hide resolved
)

func init() {
Expand Down Expand Up @@ -197,29 +198,3 @@ func PythonIntegTest(ctx context.Context) error {
return devtools.PythonNoseTest(devtools.DefaultPythonTestIntegrationArgs())
}, devtools.ListMatchingEnvVars("NOSE_")...)
}

// CreateMetricset creates a new metricset.
//
// Required ENV variables:
// * MODULE: Name of the module
// * METRICSET: Name of the metricset
func CreateMetricset(ctx context.Context) error {
ve, err := devtools.PythonVirtualenv()
if err != nil {
return err
}
python, err := devtools.LookVirtualenvPath(ve, "python")
if err != nil {
return err
}
path, err := os.Getwd()
if err != nil {
return err
}

_, err = sh.Exec(
map[string]string{}, os.Stdout, os.Stderr, python, "scripts/create_metricset.py",
"--path", path, "--module", os.Getenv("MODULE"), "--metricset", os.Getenv("METRICSET"),
)
return err
}
58 changes: 58 additions & 0 deletions metricbeat/scripts/mage/target/metricset/metricset.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// 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 metricset

import (
"os"
"path/filepath"

"github.com/magefile/mage/sh"

devtools "github.com/elastic/beats/v7/dev-tools/mage"
)

// CreateMetricset creates a new metricset.
//
// Required ENV variables:
// * MODULE: Name of the module
// * METRICSET: Name of the metricset
func CreateMetricset() error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency with other targets' functions, how about taking a context.Context here as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Being that it's not using it, I removed it. Should we have it there even if its not being used?

Copy link
Contributor

@ycombinator ycombinator Apr 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I could go either way over here. I see that other targets have it and it's not being used in them as well.

Personally, I'd prefer to leave it out if it's not being used (so 👍 to what you've done here) but perhaps we should also do that everywhere else in a follow up PR.

ve, err := devtools.PythonVirtualenv()
if err != nil {
return err
}
python, err := devtools.LookVirtualenvPath(ve, "python")
if err != nil {
return err
}
scriptPath := "scripts/create_metricset.py"
beatsBase := os.Getenv("ES_BEATS")
blakerouse marked this conversation as resolved.
Show resolved Hide resolved
if beatsBase != "" {
scriptPath = filepath.Join(beatsBase, scriptPath)
}
path, err := os.Getwd()
blakerouse marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}

_, err = sh.Exec(
map[string]string{}, os.Stdout, os.Stderr, python, scriptPath,
"--path", path, "--module", os.Getenv("MODULE"), "--metricset", os.Getenv("METRICSET"),
)
return err
}