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

[Metricbeat] Migrate HTTP json Metricset to use ReporterV2 interface #10960

Merged
merged 5 commits into from
Apr 9, 2019

Conversation

sayden
Copy link
Contributor

@sayden sayden commented Feb 27, 2019

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.

@sayden sayden added Metricbeat Metricbeat Team:Integrations Label for the Integrations team labels Feb 27, 2019
@sayden sayden self-assigned this Feb 27, 2019
@sayden sayden requested review from a team as code owners February 27, 2019 13:12
@sayden sayden changed the title Migrate HTTP json Metricset to use ReporterV2 interface [Metricbeat] Migrate HTTP json Metricset to use ReporterV2 interface Feb 28, 2019
@sayden sayden force-pushed the migration/mb/reporterv2/http/json branch from b183a40 to ca973ca Compare March 1, 2019 11:49
@sayden sayden added the review label Mar 6, 2019
@@ -24,6 +24,8 @@ import (
"strconv"
"strings"

"github.com/elastic/beats/libbeat/logp"

Copy link
Member

Choose a reason for hiding this comment

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

Nit: newline.

}
defer response.Body.Close()

var jsonBody common.MapStr
var jsonBodyArr []common.MapStr
var events []common.MapStr
//var events []common.MapStr
Copy link
Member

Choose a reason for hiding this comment

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

Leftover?

}

return events, nil
return
Copy link
Member

Choose a reason for hiding this comment

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

Can be removed.

@@ -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"
Copy link
Member

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.

Copy link
Member

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?

}

for _, obj := range jsonBodyArr {
event := m.processBody(response, obj)
events = append(events, event)
reporter.Event(mb.Event{MetricSetFields: event})
Copy link
Member

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.

@ruflin ruflin added in progress Pull request is currently in progress. and removed review labels Mar 13, 2019
@ruflin
Copy link
Member

ruflin commented Mar 13, 2019

I set this to in progress so it does not show in my review list. Please readd the review label as soon as comments are addressed.

@sayden
Copy link
Contributor Author

sayden commented Apr 5, 2019

Waiting for #11660 to be merged to rebase

@sayden sayden force-pushed the migration/mb/reporterv2/http/json branch from ca973ca to 7f9fcbb Compare April 8, 2019 11:29
@sayden sayden force-pushed the migration/mb/reporterv2/http/json branch from 4918fc3 to a22fa8c Compare April 9, 2019 07:48
var event common.MapStr

if m.deDotEnabled {
event = common.DeDotJSON(jsonBody).(common.MapStr)
Copy link
Member

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.

Copy link
Contributor Author

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,
Copy link
Member

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.

events = append(events, event)

if reported := reporter.Event(event); !reported {
return errors.New("error reporting event")
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 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).

for _, h := range v {
value += h + " ,"
if reported := reporter.Event(event); !reported {
return errors.Errorf("error reporting event: %#v", event)
Copy link
Member

Choose a reason for hiding this comment

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

See above.

@@ -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"
Copy link
Member

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?

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, assuming tests pass ;-)

@sayden sayden merged commit a4b6e1f into elastic:master Apr 9, 2019
@sayden sayden deleted the migration/mb/reporterv2/http/json branch December 18, 2020 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in progress Pull request is currently in progress. Metricbeat Metricbeat Team:Integrations Label for the Integrations team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants