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

Cherry-pick #14143 to 7.5: [Metricbeat] Add FailOnRequired when applying schema #14202

Merged
merged 2 commits into from
Oct 23, 2019
Merged

Cherry-pick #14143 to 7.5: [Metricbeat] Add FailOnRequired when applying schema #14202

merged 2 commits into from
Oct 23, 2019

Conversation

kaiyan-sheng
Copy link
Contributor

Cherry-pick of PR #14143 to 7.5 branch. Original message:

Original problem reported is when running metricbeat mongodb module, metrics metricset failled with:

Error fetching data for metricset mongodb.metrics: failed to apply schema: 5 errors: key `metrics.repl.apply.attemptsToBecomeSecondary` not found; key `metrics.repl.initialSync` not found; key `metrics.repl.executor` not found; key `metrics.commands` not found; key `metrics.operation.writeConflicts` not found

I was able to reproduce it and turned out this error message changes with different keys not found when I reproduced it.
This error should be fixed by adding schema.FailOnRequired when applying the schema.

Second problem is after adding schema.FailOnRequired, a warning showed up when trying to run metrics metricset:

...
"reason":"failed to parse field [mongodb.metrics.query_executor.scanned_indexes] of type [long] in document...

I believe some metrics in metrics metricset are missing .count suffix, like mongodb.metrics.query_executor.scanned_indexes.

How to test this:

Please start mongodb locally and start Metricbeat with mongodb module enabled. Make sure metrics are flowing with no error above. You might see some error/warning message at INFO level indicating permission error but that's not related to this.

* Add FailOnRequired when applying schema

(cherry picked from commit 09bc35a)
@@ -68,7 +68,7 @@ func (m *MetricSet) Fetch(reporter mb.ReporterV2) error {
return errors.Wrap(err, "failed to retrieve serverStatus")
}

data, err := schema.Apply(result)
data, err := schemaMetrics.Apply(result, schema.FailOnRequired)
Copy link
Member

Choose a reason for hiding this comment

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

Take into account that with this what we are doing is to ignore all keys errors, because there are no fields marked as required.

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, I tried at the beginning to add c.DictOptional and s.Optional to the fields that reported in error message: 0f247c4#diff-381ff88259685023d10591351a678e8dR57
But then I realized every time in the error message, fields are different so I ended up adding a lot of c.DictOptional and s.Optional to almost all fields 😂
Do you know if there are fields that are required from metrics metricset? If so, we should add the required label in data.go.

@kaiyan-sheng kaiyan-sheng merged commit 85914f2 into elastic:7.5 Oct 23, 2019
@kaiyan-sheng kaiyan-sheng deleted the backport_14143_7.5 branch October 23, 2019 16:11
leweafan pushed a commit to leweafan/beats that referenced this pull request Apr 28, 2023
…n applying schema (elastic#14202)

* [Metricbeat] Add FailOnRequired when applying schema (elastic#14143)

* Add FailOnRequired when applying schema

(cherry picked from commit 972900f)
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.

2 participants