-
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
[Metricbeat] Migrate HTTP json Metricset to use ReporterV2 interface #10960
[Metricbeat] Migrate HTTP json Metricset to use ReporterV2 interface #10960
Conversation
b183a40
to
ca973ca
Compare
@@ -24,6 +24,8 @@ import ( | |||
"strconv" | |||
"strings" | |||
|
|||
"github.com/elastic/beats/libbeat/logp" | |||
|
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: newline.
metricbeat/module/http/json/json.go
Outdated
} | ||
defer response.Body.Close() | ||
|
||
var jsonBody common.MapStr | ||
var jsonBodyArr []common.MapStr | ||
var events []common.MapStr | ||
//var events []common.MapStr |
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.
Leftover?
metricbeat/module/http/json/json.go
Outdated
} | ||
|
||
return events, nil | ||
return |
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 be removed.
metricbeat/tests/system/test_http.py
Outdated
@@ -33,10 +33,11 @@ def test_json(self): | |||
self.assertEqual(len(output), 1) | |||
evt = output[0] | |||
|
|||
assert evt["http"]["test"]["hello"] == "world" | |||
assert evt["http"]["json"]["hello"] == "world" |
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.
As the namespace
is set to test
, this should stay under test. Seems like your change does not respect this config anymore but should.
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.
Will this pass? Shouldn't this be under test
?
metricbeat/module/http/json/json.go
Outdated
} | ||
|
||
for _, obj := range jsonBodyArr { | ||
event := m.processBody(response, obj) | ||
events = append(events, event) | ||
reporter.Event(mb.Event{MetricSetFields: event}) |
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.
you need to report here the event under the configured namespace. Same below.
I set this to |
Waiting for #11660 to be merged to rebase |
ca973ca
to
7f9fcbb
Compare
4918fc3
to
a22fa8c
Compare
var event common.MapStr | ||
|
||
if m.deDotEnabled { | ||
event = common.DeDotJSON(jsonBody).(common.MapStr) |
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 part of this PR so we should follow up but afterwards but I wonder if this type conversion is safe or if we should check it. Also 2 lines below.
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.
Do you want me to open a follow up PR to discuss it or better to leave it in an issue to discuss?
|
||
return mb.Event{ | ||
MetricSetFields: event, | ||
Namespace: "http." + m.namespace, |
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.
Just a thought (not related to this PR): We should probably rename this to dataset
instead of namespace
as that is what it is in the event in the end.
metricbeat/module/http/json/json.go
Outdated
events = append(events, event) | ||
|
||
if reported := reporter.Event(event); !reported { | ||
return errors.New("error reporting event") |
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 related to the discussion we need to have in #11666
In general I don't think we should report an error here as it normally means the metricset or beat was stopped on purpose (which is not an error).
metricbeat/module/http/json/json.go
Outdated
for _, h := range v { | ||
value += h + " ," | ||
if reported := reporter.Event(event); !reported { | ||
return errors.Errorf("error reporting event: %#v", event) |
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.
See above.
metricbeat/tests/system/test_http.py
Outdated
@@ -33,10 +33,11 @@ def test_json(self): | |||
self.assertEqual(len(output), 1) | |||
evt = output[0] | |||
|
|||
assert evt["http"]["test"]["hello"] == "world" | |||
assert evt["http"]["json"]["hello"] == "world" |
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.
Will this pass? Shouldn't this be under test
?
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, assuming tests pass ;-)
Refer to #10774 for more info
In this case, a slight change in system tests was needed. I'm not sure of what it was originally doing.