-
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
Add add_observer_metadata processor
#11394
Conversation
Pinging @elastic/uptime |
4fa10fb
to
cf3d1ae
Compare
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.
argh, forgot to send my comment I made some time ago :-()
return nil, err | ||
} | ||
|
||
event.Fields.DeepUpdate(p.data.Get().Clone()) |
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.
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.
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.
++
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.
Added in the latest commits
@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", |
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.
should be the beat.Info.Beat
?
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.
Yes! Good catch
The APM UI requires that docs have some specific fields in |
@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. |
We've added a few non-standard fields under observer, |
@graphaelli @ruflin I've removed the 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. |
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: |
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.
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", | ||
], |
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.
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()) |
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.
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.
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.
I agree, overwrite should not extend, I'll patch this to delete first.
return nil, err | ||
} | ||
|
||
keyExists, _ := event.Fields.HasKey("observer") |
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.
We should check if HasKey
also works in case an event has observer.foo
instead observer: {foo: ...}
as the data.
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.
Looking at the source that appears to be the case.
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.
@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() |
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.
In the case of CacheTTL <= 0 I would argue the lastUpdate.Time should still be updated.
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 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?
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.
++
|
||
func TestOverwriteFalse(t *testing.T) { | ||
event := &beat.Event{ | ||
Fields: common.MapStr{"observer": common.MapStr{"foo": "bar"}}, |
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.
Can you check here with observer.foo
if it still works?
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.
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.
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.
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 |
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.
How is this change related?
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.
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.
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.
LGTM.
libbeat/processors/script/javascript/module/processor/processor.go
Outdated
Show resolved
Hide resolved
} | ||
|
||
// GeoConfigToMap converts `geo` sections to a `common.MapStr`. | ||
func GeoConfigToMap(config GeoConfig) (common.MapStr, error) { |
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.
I assume this code stayed the same from before.
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.
Yes
b6927fa
to
3ac15ef
Compare
@ruflin I believe I've incorporated all PR feedback here, except for one small thing about extra debugging info. |
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.
LGTM except for the changelog entry.
return nil, err | ||
} | ||
|
||
keyExists, _ := event.Fields.HasKey("observer") |
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.
@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() |
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.
++
|
||
func TestOverwriteFalse(t *testing.T) { | ||
event := &beat.Event{ | ||
Fields: common.MapStr{"observer": common.MapStr{"foo": "bar"}}, |
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.
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 |
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.
LGTM.
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package util |
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 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.
a9a63c4
to
83035e2
Compare
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)
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
andadd_host_metadata
forgeo
andnetinfo
fields into a newprocessors/util
package.Please note that the
observer
ECS field does not contain the same values thathost
does. See the ECS Observer Spec for more info.