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

Add add_observer_metadata processor #11394

Merged
merged 19 commits into from
Apr 24, 2019

Conversation

andrewvc
Copy link
Contributor

@andrewvc andrewvc commented Mar 22, 2019

Resolves #11379 via addition of new add_observer_metadata processor.

In addition to creating the processor this PR extracts out the common operations between add_observer_metadata and add_host_metadata for geo and netinfo fields into a new processors/util package.

Please note that the observer ECS field does not contain the same values that host does. See the ECS Observer Spec for more info.

@andrewvc andrewvc added enhancement in progress Pull request is currently in progress. libbeat Heartbeat Team:obs-ds-hosted-services Label for the Observability Hosted Services team labels Mar 22, 2019
@andrewvc andrewvc self-assigned this Mar 22, 2019
@andrewvc andrewvc requested a review from a team as a code owner March 22, 2019 17:10
@elasticmachine
Copy link
Collaborator

Pinging @elastic/uptime

@andrewvc andrewvc requested a review from a team as a code owner March 22, 2019 21:54
@andrewvc andrewvc added review and removed in progress Pull request is currently in progress. labels Mar 22, 2019
@andrewvc andrewvc requested a review from ruflin March 25, 2019 20:53
Copy link
Member

@ruflin ruflin left a comment

Choose a reason for hiding this comment

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

argh, forgot to send my comment I made some time ago :-()

return nil, err
}

event.Fields.DeepUpdate(p.data.Get().Clone())
Copy link
Member

Choose a reason for hiding this comment

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

Not directly related to this PR but something in general I would like to see for the add_metadata_processors is that data is only added when no observer.* fields exist. If someone wants to overwrite these fields, overwrite: true has to best se. We already hit the issue in cloud and host.

It does not exist yet in other processors but as this one is new, we can introduce it from day one.

Copy link
Contributor Author

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.

Added in the latest commits

@ruflin
Copy link
Member

ruflin commented Mar 27, 2019

@elastic/apm-server Would be great to get your feedback on this one and if it would be useful for you too.

data := common.MapStr{
"observer": common.MapStr{
"hostname": hostInfo.Hostname,
"type": "heartbeat",
Copy link
Member

@graphaelli graphaelli Mar 27, 2019

Choose a reason for hiding this comment

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

should be the beat.Info.Beat?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes! Good catch

@graphaelli
Copy link
Member

The APM UI requires that docs have some specific fields in observer. so we can't use this directly due to the overwriting behavior, but the idea of observer metadata is interesting. apm-server does not currently expose or support use of processors though.

@ruflin
Copy link
Member

ruflin commented Mar 28, 2019

@graphaelli What are the fields you require which are not provided as part of the processor? Would be great if we could get this processor to a state, where it's also useful for apm-server. I think apm-server and heartbeat have quite a few similarities.

@graphaelli
Copy link
Member

graphaelli commented Mar 28, 2019

We've added a few non-standard fields under observer, major_version is required by the APM UI. To be clear, I wouldn't expect these to be added to the processor, but provide support to your comment about existing observer fields taking precedence over those added by this processor.

@andrewvc
Copy link
Contributor Author

@graphaelli @ruflin I've removed the vendor and type fields because processors don't have access to the beat name, and I'd rather not start down that path unless we can provide all the data. For now, I think the agent field suffices.

I'm glad to add that data, but that would be a refactor of the processor interface to take beat info with it, which may be beyond the scope here.

@ruflin
Copy link
Member

ruflin commented Apr 1, 2019

This will need a rebase on master to fix the CI issues.

@@ -1054,7 +1055,7 @@ It has the following settings:


The `add_host_metadata` processor annotates each event with relevant metadata from the host machine.
The fields added to the event are looking as following:
The fields added to the event are look like following:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
The fields added to the event are look like following:
The fields added to the event look like following:

],
"mac" : [
"dc:c1:02:6f:1b:ed",
],
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Looks like some indentation is off here.

keyExists, _ := event.Fields.HasKey("observer")

if p.config.Overwrite || !keyExists {
event.Fields.DeepUpdate(p.data.Get().Clone())
Copy link
Member

Choose a reason for hiding this comment

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

Now reading the code I wonder if in case we have overwrite: true if we should "extend" the object or actually completely overwrite it, meaning first delete observer. If we don't delete, we have the risk of having mixed data in the observer object.

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 agree, overwrite should not extend, I'll patch this to delete first.

return nil, err
}

keyExists, _ := event.Fields.HasKey("observer")
Copy link
Member

Choose a reason for hiding this comment

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

We should check if HasKey also works in case an event has observer.foo instead observer: {foo: ...} as the data.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looking at the source that appears to be the case.

Copy link
Member

Choose a reason for hiding this comment

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

@kaiyan-sheng I remember we had some discussions around this in an other PR related to host metadata.

if p.lastUpdate.Add(p.config.CacheTTL).After(time.Now()) {
return false
}
p.lastUpdate.Time = time.Now()
Copy link
Member

Choose a reason for hiding this comment

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

In the case of CacheTTL <= 0 I would argue the lastUpdate.Time should still be updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This logic is identical to that in add_host_metadata (indeed the code is copied). Maybe we should extract this to a new issue and patch it in both if that's a change we want to make?

Copy link
Member

Choose a reason for hiding this comment

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

++


func TestOverwriteFalse(t *testing.T) {
event := &beat.Event{
Fields: common.MapStr{"observer": common.MapStr{"foo": "bar"}},
Copy link
Member

Choose a reason for hiding this comment

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

Can you check here with observer.foo if it still works?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That does not work because the literal map syntax does the wrong thing. If you instantiate a common.MapStr then myms.Put("observer.foo", "bar") that does work.

Copy link
Member

Choose a reason for hiding this comment

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

we have the same issue in host processor and for now if I remember correctly the conclusion is: We accept that it does not work.

@@ -71,7 +71,12 @@ func New(config PluginConfig) (*Processors, error) {

gen, exists := registry.reg[actionName]
if !exists {
return nil, errors.Errorf("the processor action %s does not exist", actionName)
var validActions []string
Copy link
Member

Choose a reason for hiding this comment

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

How is this change related?

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 made a mistake in earlier versions of this and found this debugging info useful. Glad to move it to a new PR if you feel it's worthwhile.

Copy link
Member

Choose a reason for hiding this comment

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

LGTM.

}

// GeoConfigToMap converts `geo` sections to a `common.MapStr`.
func GeoConfigToMap(config GeoConfig) (common.MapStr, error) {
Copy link
Member

Choose a reason for hiding this comment

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

I assume this code stayed the same from before.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes

@andrewvc
Copy link
Contributor Author

@ruflin I believe I've incorporated all PR feedback here, except for one small thing about extra debugging info.

Copy link
Member

@ruflin ruflin left a comment

Choose a reason for hiding this comment

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

LGTM except for the changelog entry.

CHANGELOG.next.asciidoc Outdated Show resolved Hide resolved
return nil, err
}

keyExists, _ := event.Fields.HasKey("observer")
Copy link
Member

Choose a reason for hiding this comment

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

@kaiyan-sheng I remember we had some discussions around this in an other PR related to host metadata.

if p.lastUpdate.Add(p.config.CacheTTL).After(time.Now()) {
return false
}
p.lastUpdate.Time = time.Now()
Copy link
Member

Choose a reason for hiding this comment

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

++


func TestOverwriteFalse(t *testing.T) {
event := &beat.Event{
Fields: common.MapStr{"observer": common.MapStr{"foo": "bar"}},
Copy link
Member

Choose a reason for hiding this comment

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

we have the same issue in host processor and for now if I remember correctly the conclusion is: We accept that it does not work.

@@ -71,7 +71,12 @@ func New(config PluginConfig) (*Processors, error) {

gen, exists := registry.reg[actionName]
if !exists {
return nil, errors.Errorf("the processor action %s does not exist", actionName)
var validActions []string
Copy link
Member

Choose a reason for hiding this comment

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

LGTM.

// specific language governing permissions and limitations
// under the License.

package util
Copy link
Member

Choose a reason for hiding this comment

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

This is the only package inside processors which is not a processor itself. I wonder if this could cause some problems around automation like fields collection etc.

@andrewvc andrewvc merged commit 1d94462 into elastic:master Apr 24, 2019
@andrewvc andrewvc deleted the add-observer-metadata branch April 24, 2019 13:44
andrewvc added a commit to andrewvc/beats that referenced this pull request Apr 24, 2019
Resolves elastic#11379 via addition of new add_observer_metadata processor.

In addition to creating the processor this PR extracts out the common operations between add_observer_metadata and add_host_metadata for geo and netinfo fields into a new processors/util package.

Please note that the observer ECS field does not contain the same values that host does. See the ECS Observer Spec for more info.

(cherry picked from commit 1d94462)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bringing back host metadata as observer
5 participants