-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Generate fields.yml using Mage #7670
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
@echo off | ||
|
||
REM Windows wrapper for Mage (https://magefile.org/) that installs it | ||
REM to %GOPATH%\bin from the Beats vendor directory. | ||
REM | ||
REM After running this once you may invoke mage.exe directly. | ||
|
||
WHERE mage | ||
IF %ERRORLEVEL% NEQ 0 go install github.com/elastic/beats/vendor/github.com/magefile/mage | ||
|
||
mage %* |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,14 @@ $env:PATH = "$env:GOPATH\bin;C:\tools\mingw64\bin;$env:PATH" | |
# each run starts from a clean slate. | ||
$env:MAGEFILE_CACHE = "$env:WORKSPACE\.magefile" | ||
|
||
exec { go install github.com/elastic/beats/vendor/github.com/magefile/mage } | ||
exec { go get -u github.com/jstemmer/go-junit-report } | ||
|
||
echo "Building libbeat fields.yml" | ||
cd libbeat | ||
exec { mage fields } | ||
cd .. | ||
|
||
if (Test-Path "$env:beat") { | ||
cd "$env:beat" | ||
} else { | ||
|
@@ -35,20 +43,11 @@ New-Item -ItemType directory -Path build\coverage | Out-Null | |
New-Item -ItemType directory -Path build\system-tests | Out-Null | ||
New-Item -ItemType directory -Path build\system-tests\run | Out-Null | ||
|
||
exec { go get -u github.com/jstemmer/go-junit-report } | ||
echo "Building fields.yml" | ||
exec { mage fields } | ||
|
||
echo "Building $env:beat" | ||
exec { go build } "Build FAILURE" | ||
|
||
# always build the libbeat fields | ||
cp ..\libbeat\_meta\fields.common.yml ..\libbeat\_meta\fields.generated.yml | ||
cat ..\libbeat\processors\*\_meta\fields.yml | Out-File -append -encoding UTF8 -filepath ..\libbeat\_meta\fields.generated.yml | ||
cp ..\libbeat\_meta\fields.generated.yml ..\libbeat\fields.yml | ||
|
||
if ($env:beat -eq "metricbeat") { | ||
cp .\_meta\fields.common.yml .\_meta\fields.generated.yml | ||
python .\scripts\fields_collector.py | out-file -append -encoding UTF8 -filepath .\_meta\fields.generated.yml | ||
} | ||
exec { mage build } "Build FAILURE" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice. This should have been simplified before already when we move to fields collection to golang. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this also mean that .\scripts\fields_collector.py should have been removed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would say yes. I remember something like we wanted to keep it around in the PR that introduced the golang for comparing the two and removing it afterwards but seems that was forgotten. |
||
|
||
echo "Unit testing $env:beat" | ||
go test -v $(go list ./... | select-string -Pattern "vendor" -NotMatch) 2>&1 | Out-File -encoding UTF8 build/TEST-go-unit.out | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// 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 mage | ||
|
||
import ( | ||
"path/filepath" | ||
|
||
"github.com/magefile/mage/sh" | ||
) | ||
|
||
// GenerateFieldsYAML generates a fields.yml file for a Beat. This will include | ||
// the common fields specified by libbeat, the common fields for the Beat, | ||
// and any additional fields.yml files you specify. | ||
// | ||
// fieldsFiles specifies additional directories to search recursively for files | ||
// named fields.yml. The contents of each fields.yml will be included in the | ||
// generated file. | ||
func GenerateFieldsYAML(fieldsFiles ...string) error { | ||
const globalFieldsCmdPath = "libbeat/scripts/cmd/global_fields/main.go" | ||
|
||
beatsDir, err := ElasticBeatsDir() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
globalFieldsCmd := sh.RunCmd("go", "run", | ||
filepath.Join(beatsDir, globalFieldsCmdPath), | ||
"-es_beats_path", beatsDir, | ||
"-beat_path", CWD(), | ||
) | ||
|
||
return globalFieldsCmd(fieldsFiles...) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
REM Batch script to build and test on Windows. You can use this in conjunction | ||
REM with the Vagrant machine. | ||
go build | ||
go test ./... | ||
go test -c -cover -covermode=count -coverpkg ./... | ||
cd tests\system | ||
nosetests | ||
@echo off | ||
|
||
REM Windows wrapper for Mage (https://magefile.org/) that installs it | ||
REM to %GOPATH%\bin from the Beats vendor directory. | ||
REM | ||
REM After running this once you may invoke mage.exe directly. | ||
|
||
WHERE mage | ||
IF %ERRORLEVEL% NEQ 0 go install github.com/elastic/beats/vendor/github.com/magefile/mage | ||
|
||
mage %* |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1 @@ | ||
override FIELDS_FILE_PATH= | ||
export FIELDS_FILE_PATH | ||
|
||
include ../common/Makefile |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
@echo off | ||
|
||
REM Windows wrapper for Mage (https://magefile.org/) that installs it | ||
REM to %GOPATH%\bin from the Beats vendor directory. | ||
REM | ||
REM After running this once you may invoke mage.exe directly. | ||
|
||
WHERE mage | ||
IF %ERRORLEVEL% NEQ 0 go install {beat_path}/vendor/github.com/magefile/mage | ||
|
||
mage %* |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,23 +11,36 @@ PREPARE_COMMAND?= | |
test: prepare-test | ||
. ${PYTHON_ENV}/bin/activate; \ | ||
export GOPATH=${PWD}/build ; \ | ||
export PATH=${PATH}:${PWD}/build/bin; \ | ||
export PATH=$${GOPATH}/bin:${PATH}; \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. It's an escape so that GOPATH is resolve in the shell command rather than by Make. If you don't do this then you get the original GOPATH value and not the one set 2 lines above. |
||
cd ${BEAT_PATH} ; \ | ||
$(MAKE) copy-vendor || exit 1 ; \ | ||
${PREPARE_COMMAND} \ | ||
$(MAKE) git-init || exit 1 ; \ | ||
$(MAKE) update || exit 1 ; \ | ||
$(MAKE) git-add || exit 1 ; \ | ||
$(MAKE) check CHECK_HEADERS_DISABLED=y || exit 1 ; \ | ||
$(MAKE) || exit 1 ; \ | ||
$(MAKE) unit | ||
|
||
.PHONY: prepare-test | ||
prepare-test:: python-env | ||
# Makes sure to use current version of beats for testing | ||
mkdir -p ${BUILD_DIR}/src/github.com/elastic/beats/ | ||
rsync -a --exclude=build ${PWD}/../../* ${BUILD_DIR}/src/github.com/elastic/beats/ | ||
rsync -a \ | ||
--include=vendor/github.com/magefile/mage/build \ | ||
--exclude=build/ \ | ||
--exclude=.git/ \ | ||
${PWD}/../../* ${BUILD_DIR}/src/github.com/elastic/beats/ | ||
|
||
mkdir -p ${BEAT_PATH} | ||
export GOPATH=${PWD}/build ; \ | ||
. ${PYTHON_ENV}/bin/activate && python ${PWD}/build/src/github.com/elastic/beats/script/generate.py --type=${BEAT_TYPE} --project_name=Testbeat --github_name=ruflin --beat_path=beatpath/testbeat --full_name="Nicolas Ruflin" | ||
. ${PYTHON_ENV}/bin/activate && \ | ||
python ${PWD}/build/src/github.com/elastic/beats/script/generate.py \ | ||
--type=${BEAT_TYPE} \ | ||
--project_name=Testbeat \ | ||
--github_name=ruflin \ | ||
--beat_path=beatpath/testbeat \ | ||
--full_name="Nicolas Ruflin" | ||
|
||
# Runs test build for the created beat | ||
.PHONY: test-build | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,14 @@ | ||
BEAT_TYPE=metricbeat | ||
PREPARE_COMMAND=MODULE=elastic METRICSET=test make create-metricset ; FIELDS_FILE_PATH=module | ||
override FIELDS_FILE_PATH= | ||
export FIELDS_FILE_PATH | ||
|
||
BEAT_TYPE = metricbeat | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the new indentation but thing I wonder is if the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm pretty sure the spaces are dropped by make (in bash they would not be). I've used this syntax before without issues (https://github.com/elastic/golang-crossbuild/blob/master/Makefile.common and several other files in this repo). |
||
PREPARE_COMMAND = MODULE=elastic METRICSET=test make create-metricset; | ||
|
||
include ../common/Makefile | ||
|
||
.PHONY: prepare-test | ||
prepare-test:: python-env | ||
|
||
mkdir -p ${BEAT_PATH}/scripts | ||
rsync -a --exclude=build ${PWD}/../../metricbeat/scripts/generate_imports_helper.py ${BEAT_PATH}/scripts | ||
|
||
# Collects all dependencies and then calls update | ||
.PHONY: collect | ||
collect: fields | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
@echo off | ||
|
||
REM Windows wrapper for Mage (https://magefile.org/) that installs it | ||
REM to %GOPATH%\bin from the Beats vendor directory. | ||
REM | ||
REM After running this once you may invoke mage.exe directly. | ||
|
||
WHERE mage | ||
IF %ERRORLEVEL% NEQ 0 go install {beat_path}/vendor/github.com/magefile/mage | ||
|
||
mage %* |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
@echo off | ||
|
||
REM Windows wrapper for Mage (https://magefile.org/) that installs it | ||
REM to %GOPATH%\bin from the Beats vendor directory. | ||
REM | ||
REM After running this once you may invoke mage.exe directly. | ||
|
||
WHERE mage | ||
IF %ERRORLEVEL% NEQ 0 go install github.com/elastic/beats/vendor/github.com/magefile/mage | ||
|
||
mage %* |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
BEAT_NAME=libbeat | ||
TEST_ENVIRONMENT?=true | ||
SYSTEM_TESTS=true | ||
FIELDS_FILE_PATH=processors | ||
|
||
include scripts/Makefile | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This command will go away once the field generation is updated to automatically get the libbeat field values.