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 fields generation #21874

Merged
merged 15 commits into from
Dec 10, 2020
Merged

Conversation

andrewvc
Copy link
Contributor

@andrewvc andrewvc commented Oct 16, 2020

Fields generation seems to have broken at some time in the past, but we never noticed, because we didn't add fields for quite a while. This fixes this. I had to centralize all field definitions in the top level _meta folder, but I'm fine with this change, in many ways this is actually easier.

Fields generation seems to have broken at some time in the past, but we
never noticed, because we didn't add fields for quite a while. This
fixes this.
@andrewvc andrewvc requested a review from a team as a code owner October 16, 2020 00:48
@andrewvc andrewvc self-assigned this Oct 16, 2020
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Oct 16, 2020
@elasticmachine
Copy link
Collaborator

elasticmachine commented Oct 16, 2020

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview

Expand to view the summary

Build stats

  • Build Cause: Pull request #21874 updated

  • Start Time: 2020-12-10T18:08:18.810+0000

  • Duration: 27 min 37 sec

Test stats 🧪

Test Results
Failed 0
Passed 932
Skipped 13
Total 945

💚 Flaky test report

Tests succeeded.

Expand to view the summary

Test stats 🧪

Test Results
Failed 0
Passed 932
Skipped 13
Total 945

@andresrc andresrc added the Team:obs-ds-hosted-services Label for the Observability Hosted Services team label Oct 16, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/uptime (Team:Uptime)

@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Oct 16, 2020
@andrewvc
Copy link
Contributor Author

andrewvc commented Dec 4, 2020

/test please

Copy link
Member

@andrewkroh andrewkroh left a comment

Choose a reason for hiding this comment

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

Summarizing the setup here:

  • Only OSS heartbeat declares fields.
  • All fields are contained in OSS heartbeat/_meta
  • Each build (OSS and X-Pack) generates a fields.yml to include in packages for reference. It's not used by the beat software for anything.
  • There is a include/fields.go file generated from the all-in-one fields.yml file to embed the fields data into the beat.
  • Any fields.go files are imported somewhere to ensure they are included in the binary.

@@ -25,12 +25,15 @@ import (
// include all heartbeat specific autodiscovery builders
_ "github.com/elastic/beats/v7/heartbeat/autodiscover/builder/hints"

// register default heartbeat monitors
_ "github.com/elastic/beats/v7/heartbeat/monitors/defaults"
Copy link
Member

Choose a reason for hiding this comment

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

This package looks broken. In the OSS magefile.go there is a generator for it. It looks like it's supposed to be creating imports for each monitor. I'd remove the package and the generation code if it's unused.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The weird thing is this used to work, and somehow broke at some point. Now, when I run mage update these lines just get deleted. That said, probably easier to just remove it and make it manual since we don't add monitor types frequently.

if err != nil {
return err
}
return devtools.GenerateAllInOneFieldsGo()
Copy link
Member

Choose a reason for hiding this comment

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

When this is run from x-pack/heartbeat it will create x-pack/heartbeat/include/fields.go, but since there are no new fields being introduced we can skip this part. We'd only want to introduce an x-pack/heartbeat/include/fields.go file if X-Pack heartbeat added new fields. And if this file was added we'd only want it to include the new fields (not any of the libbeat or OSS heartbeat fields) since they are already included on the OSS side an inherited by x-pack.

You could use some license based conditionals like in Winlogbeat

https://github.com/elastic/beats/blob/c2272c192f2a19c4b3412dfea21e25c1ca180934/winlogbeat/scripts/mage/fields.go

or do the same work in both OSS and X-Pack but write the output to OSS only

devtools.GenerateFieldsGo("fields.yml", devtools.OSSBeatDir("include/fields.go"))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will generate new fields when the synthetics stuff is merged in #21436 , and in fact this PR is a bit of a blocker for that one. That said, if it's easier, I'd rather just include all the fields (including x-pack fields) in the OSS heartbeat and keep things simple. Does that work for you?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I went with the latter approach you suggested. Thanks for the tips!

@@ -9570,7 +9570,7 @@ type: long

--

[[exported-fields-socks5]]
[[exported-fields-socks6]]
Copy link
Member

Choose a reason for hiding this comment

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

socks6? Where did that change come from?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, fixed!

@@ -13,8 +13,7 @@ collect: imports kibana
# Generate imports for all monitors
.PHONY: imports
imports:
Copy link
Member

Choose a reason for hiding this comment

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

I think it's only used by heartbeat's own collect target so it can be removed if you want.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, removed

@andrewvc andrewvc merged commit 5d07b87 into elastic:master Dec 10, 2020
@andrewvc andrewvc deleted the fix-fields-generation branch December 10, 2020 18:44
andrewvc added a commit to andrewvc/beats that referenced this pull request Dec 10, 2020
* [Heartbeat] Fix fields generation

Fields generation seems to have broken at some time in the past, but we
never noticed, because we didn't add fields for quite a while. This
fixes this.

(cherry picked from commit 5d07b87)
andrewvc added a commit that referenced this pull request Dec 10, 2020
* [Heartbeat] Fix fields generation

Fields generation seems to have broken at some time in the past, but we
never noticed, because we didn't add fields for quite a while. This
fixes this.

(cherry picked from commit 5d07b87)
@jsoriano jsoriano mentioned this pull request Dec 12, 2020
6 tasks
@jsoriano
Copy link
Member

jsoriano commented Dec 12, 2020

I think that this change affects the packaging build, failures like the following one can be reproduced in master now when building x-pack heartbeat packages:

Error: failed building heartbeat type=docker for platform=linux/amd64: failed to copy from fields.yml to build/package/heartbeat/heartbeat-linux-amd64.docker/docker-build/beat/fields.yml: copy failed: cannot stat source file fields.yml: stat fields.yml: no such file or directory

Seen in #22883

andrewvc added a commit to andrewvc/beats that referenced this pull request Dec 14, 2020
Fixes a bug introduced in elastic#21874
where fields.yml generation in x-pack stopped happening.
andrewvc added a commit that referenced this pull request Dec 14, 2020
Fixes a bug introduced in #21874
where fields.yml generation in x-pack stopped happening.
andrewvc added a commit to andrewvc/beats that referenced this pull request Dec 14, 2020
Fixes a bug introduced in elastic#21874
where fields.yml generation in x-pack stopped happening.

(cherry picked from commit 78a8625)
andrewvc added a commit that referenced this pull request Dec 14, 2020
…3122)

Fixes a bug introduced in #21874
where fields.yml generation in x-pack stopped happening.

(cherry picked from commit 78a8625)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Heartbeat Team:obs-ds-hosted-services Label for the Observability Hosted Services team v7.11.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants