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

[Heartbeat] Fix packaging #20566

Merged
merged 3 commits into from
Aug 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 3 additions & 2 deletions .ci/packaging.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pipeline {
'x-pack/dockerlogbeat',
'x-pack/filebeat',
'x-pack/functionbeat',
// 'x-pack/heartbeat',
'x-pack/heartbeat',
// 'x-pack/journalbeat',
'x-pack/metricbeat',
// 'x-pack/packetbeat',
Expand Down Expand Up @@ -161,7 +161,6 @@ def pushCIDockerImages(){
} else if ("${env.BEATS_FOLDER}" == "filebeat") {
tagAndPush('filebeat-oss')
} else if ("${env.BEATS_FOLDER}" == "heartbeat"){
tagAndPush('heartbeat')
tagAndPush('heartbeat-oss')
} else if ("${env.BEATS_FOLDER}" == "journalbeat"){
tagAndPush('journalbeat')
Expand All @@ -177,6 +176,8 @@ def pushCIDockerImages(){
tagAndPush('elastic-agent')
} else if ("${env.BEATS_FOLDER}" == "x-pack/filebeat"){
tagAndPush('filebeat')
} else if ("${env.BEATS_FOLDER}" == "x-pack/heartbeat"){
tagAndPush('heartbeat')
} else if ("${env.BEATS_FOLDER}" == "x-pack/metricbeat"){
tagAndPush('metricbeat')
}
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ XPACK_SUFFIX=x-pack/
# PROJECTS_XPACK_PKG is a list of Beats that have independent packaging support
# in the x-pack directory (rather than having the OSS build produce both sets
# of artifacts). This will be removed once we complete the transition.
PROJECTS_XPACK_PKG=x-pack/auditbeat x-pack/dockerlogbeat x-pack/filebeat x-pack/metricbeat x-pack/winlogbeat
PROJECTS_XPACK_PKG=x-pack/auditbeat x-pack/dockerlogbeat x-pack/filebeat x-pack/heartbeat x-pack/metricbeat x-pack/winlogbeat
# PROJECTS_XPACK_MAGE is a list of Beats whose primary build logic is based in
# Mage. For compatibility with CI testing these projects support a subset of the
# makefile targets. After all Beats converge to primarily using Mage we can
Expand Down
44 changes: 6 additions & 38 deletions heartbeat/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import (
// mage:import
"github.com/elastic/beats/v7/dev-tools/mage/target/common"
// mage:import
"github.com/elastic/beats/v7/dev-tools/mage/target/build"
// mage:import
"github.com/elastic/beats/v7/dev-tools/mage/target/unittest"
// mage:import
"github.com/elastic/beats/v7/dev-tools/mage/target/integtest"
Expand All @@ -43,48 +45,13 @@ func init() {
common.RegisterCheckDeps(Update)
unittest.RegisterPythonTestDeps(Fields)
integtest.RegisterPythonTestDeps(Fields)

devtools.BeatDescription = "Ping remote services for availability and log " +
"results to Elasticsearch or send to Logstash."
devtools.BeatServiceName = "heartbeat-elastic"
}

// VendorUpdate updates elastic/beats/v7 in the vendor dir
func VendorUpdate() error {
return beatgen.VendorUpdate()
}

// Build builds the Beat binary.
func Build() error {
return devtools.Build(devtools.DefaultBuildArgs())
}

// GolangCrossBuild build the Beat binary inside of the golang-builder.
// Do not use directly, use crossBuild instead.
func GolangCrossBuild() error {
return devtools.GolangCrossBuild(devtools.DefaultGolangCrossBuildArgs())
}

// BuildGoDaemon builds the go-daemon binary (use crossBuildGoDaemon).
func BuildGoDaemon() error {
return devtools.BuildGoDaemon()
}

// CrossBuild cross-builds the beat for all target platforms.
func CrossBuild() error {
return devtools.CrossBuild()
}

// CrossBuildXPack cross-builds the beat with XPack for all target platforms.
func CrossBuildXPack() error {
return devtools.CrossBuildXPack()
}

// CrossBuildGoDaemon cross-builds the go-daemon binary using Docker.
func CrossBuildGoDaemon() error {
return devtools.CrossBuildGoDaemon()
}

// Package packages the Beat for distribution.
// Use SNAPSHOT=true to build snapshots.
// Use PLATFORMS to control the target platforms.
Expand All @@ -93,11 +60,12 @@ func Package() {
start := time.Now()
defer func() { fmt.Println("package ran for", time.Since(start)) }()

devtools.UseElasticBeatPackaging()
devtools.UseElasticBeatOSSPackaging()
devtools.PackageKibanaDashboardsFromBuildDir()
heartbeat.CustomizePackaging()

mg.Deps(Update)
mg.Deps(CrossBuild, CrossBuildXPack, CrossBuildGoDaemon)
mg.Deps(build.CrossBuild, build.CrossBuildGoDaemon)
mg.SerialDeps(devtools.Package, TestPackages)
}

Expand All @@ -112,7 +80,7 @@ func Fields() error {

// Update updates the generated files (aka make update).
func Update() {
mg.SerialDeps(Fields, Config)
mg.SerialDeps(Fields, Config, Imports)
}

// Imports generates an include/list.go file containing
Expand Down
26 changes: 20 additions & 6 deletions heartbeat/scripts/mage/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,31 @@

package mage

import devtools "github.com/elastic/beats/v7/dev-tools/mage"
import (
"os"

const (
dirModuleGenerated = "build/package/module"
dirModulesDGenerated = "build/package/modules.d"
"github.com/magefile/mage/mg"

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

func init() {
devtools.BeatDescription = "Ping remote services for availability and log " +
"results to Elasticsearch or send to Logstash."
devtools.BeatServiceName = "heartbeat-elastic"
}

// CustomizePackaging modifies the package specs to add the modules and
// modules.d directory. You must declare a dependency on either
// PrepareModulePackagingOSS or PrepareModulePackagingXPack.
func CustomizePackaging() {
mg.Deps(dashboards)

monitorsDTarget := "monitors.d"
unixMonitorsDir := "/etc/{{.BeatName}}/monitors.d"
monitorsD := devtools.PackageFile{
Mode: 0644,
Source: "monitors.d",
Source: devtools.OSSBeatDir("monitors.d"),
}

for _, args := range devtools.Packages {
Expand All @@ -49,7 +58,12 @@ func CustomizePackaging() {
}
}

func dashboards() error {
// Heartbeat doesn't have any dashboards so just create the empty directory.
return os.MkdirAll("build/kibana", 0755)
}

// Fields generates a fields.yml for the Beat.
func Fields() error {
return devtools.GenerateFieldsYAML("monitors/active")
return devtools.GenerateFieldsYAML(devtools.OSSBeatDir("monitors/active"))
}
3 changes: 3 additions & 0 deletions x-pack/heartbeat/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ES_BEATS ?= ../..

include $(ES_BEATS)/dev-tools/make/mage.mk
32 changes: 32 additions & 0 deletions x-pack/heartbeat/heartbeat.docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Define a directory to load monitor definitions from. Definitions take the form
# of individual yaml files.
heartbeat.config.monitors:
# Directory + glob pattern to search for configuration files
path: ${path.config}/monitors.d/*.yml
# If enabled, heartbeat will periodically check the config.monitors path for changes
reload.enabled: false
# How often to check for changes
reload.period: 5s


heartbeat.monitors:
- type: http
schedule: '@every 5s'
urls:
- http://elasticsearch:9200
- http://kibana:5601

- type: icmp
schedule: '@every 5s'
hosts:
- elasticsearch
- kibana

processors:
- add_cloud_metadata: ~
- add_docker_metadata: ~

output.elasticsearch:
hosts: '${ELASTICSEARCH_HOSTS:elasticsearch:9200}'
username: '${ELASTICSEARCH_USERNAME:}'
password: '${ELASTICSEARCH_PASSWORD:}'
Loading