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

[dev guide] Add docs on optional schema arguments #12371

Merged

Conversation

fearful-symmetry
Copy link
Contributor

This is a response to #7335, as it adds a great deal of functionality to the schema library and none of it seems to be documented.

This PR expands the schema.Apply example to the beats developer guide with documented usage of the various optional arguments now available in schema.Apply

There's a few undressed things here:

  • should this be a separate example, to emphasize that this functionality is optional?
  • I would like to add a code snippet for NotFoundKeys but I'm still trying to figure it out.

@fearful-symmetry fearful-symmetry added docs Team:Integrations Label for the Integrations team labels May 30, 2019
@fearful-symmetry fearful-symmetry requested review from dedemorton and a team May 30, 2019 17:13
@fearful-symmetry fearful-symmetry self-assigned this May 30, 2019
Copy link
Contributor

@kaiyan-sheng kaiyan-sheng left a comment

Choose a reason for hiding this comment

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

Thanks for adding this! Very helpful!! We also have IgnoreAllErrors option as well. It is aded by #12089

Copy link
Contributor

@dedemorton dedemorton left a comment

Choose a reason for hiding this comment

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

A few changes. Thank you for adding this!

docs/devguide/create-metricset.asciidoc Outdated Show resolved Hide resolved
}
----
<1> `Required` will explicitly mark a field as non-optional.
<2> If a field has no Schema Option set, it is equivalent to `Required`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure why "Schema Option" is capitalized here. Generally we only capitalize proper nouns. I would change this to say, "If no schema option is set, the field is 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.

More than likely, I was looking at the code, which is capitalized, and my brain just translated it to words that way, hah.

}
----
<1> `Required` will explicitly mark a field as non-optional.
<2> If a field has no Schema Option set, it is equivalent to `Required`.
<3> `Optional` You can also explicitly mark a field as not required.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
<3> `Optional` You can also explicitly mark a field as not required.
<3> Marks the field as optional.

Copy link
Contributor

Choose a reason for hiding this comment

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

I understand why you are being precise here, but I think the content is harder to read when you swap between using "non-optional" and "not required." Except in situations where it's important to know that a setting is explicit (like you do later on where you say "field explicitly marked as required"), I would simply refer to a fields as required or optional. I'll suggest edits with this notion in mind. I hope I'm understanding things correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yah, I was struggling to word that in a way that didn't seem repetitive.

docs/devguide/create-metricset.asciidoc Outdated Show resolved Hide resolved
<2> If a field has no Schema Option set, it is equivalent to `Required`.
<3> `Optional` You can also explicitly mark a field as not required.
<4> By default, `Apply` will fail and return an error if any field not marked as optional is missing. Using the optional second argument, you can specify how `Apply` handles different fields of the schema. The possible values are:
- `AllRequired` is the default behavior. Return an error if any field not marked as optional is missing.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- `AllRequired` is the default behavior. Return an error if any field not marked as optional is missing.
- `AllRequired` is the default behavior. Returns an error if any required field is missing.

Copy link
Contributor

Choose a reason for hiding this comment

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

If you want to disambiguate further, you could add "...any required field is missing, including fields that are required because no schema option is set."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yah, that's what I was trying to get across. Thanks!

<4> By default, `Apply` will fail and return an error if any field not marked as optional is missing. Using the optional second argument, you can specify how `Apply` handles different fields of the schema. The possible values are:
- `AllRequired` is the default behavior. Return an error if any field not marked as optional is missing.
- `FailOnRequired` will fail if a field explicitly marked as `required` is missing.
- `NotFoundKeys(cb func([]string))` will pass a callback function that will be called with the list of missing keys, for more fine-grained error handling.
Copy link
Contributor

Choose a reason for hiding this comment

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

This sentence was a little hard to parse on first reading. Would it be accurate to say "...will pass a callback function that returns a list of missing keys for more fine-grained error handling."

@codecov
Copy link

codecov bot commented May 31, 2019

Codecov Report

Merging #12371 into master will decrease coverage by 0.03%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #12371      +/-   ##
==========================================
- Coverage   57.96%   57.92%   -0.04%     
==========================================
  Files         933      930       -3     
  Lines       57453    57339     -114     
==========================================
- Hits        33302    33215      -87     
+ Misses      21085    21065      -20     
+ Partials     3066     3059       -7
Impacted Files Coverage Δ
libbeat/publisher/queue/memqueue/ringbuf.go 67.88% <0%> (-5.51%) ⬇️
auditbeat/module/file_integrity/action.go 63.15% <0%> (-5.27%) ⬇️
heartbeat/scheduler/scheduler.go 71.12% <0%> (-3.21%) ⬇️
libbeat/publisher/queue/memqueue/eventloop.go 76.97% <0%> (-0.66%) ⬇️
...beat/module/file_integrity/eventreader_fsevents.go
...ditbeat/module/file_integrity/fileorigin_darwin.go
auditbeat/module/file_integrity/fileinfo_bsd.go
libbeat/publisher/queue/spool/inbroker.go 68.35% <0%> (+1.17%) ⬆️
...ditbeat/module/file_integrity/monitor/recursive.go 81.9% <0%> (+1.9%) ⬆️
...beat/module/file_integrity/eventreader_fsnotify.go 78.82% <0%> (+3.52%) ⬆️
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bf2f311...cb799a6. Read the comment docs.

@fearful-symmetry fearful-symmetry requested review from dedemorton and a team May 31, 2019 00:21
@fearful-symmetry
Copy link
Contributor Author

codecov, what are you doing

Anyways, thanks @dedemorton ! I struggle with how to grammatically format lists, hah.

Copy link
Member

@jsoriano jsoriano left a comment

Choose a reason for hiding this comment

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

Thanks for this! We could also add some godocs to the package, but this can be done in a separate PR.

}
----
<1> Marks a field as required.
<2> If a field has no schema option set, it is equivalent to `Required`.
<3> Marks the field as optional.
Copy link
Member

Choose a reason for hiding this comment

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

@odacremolbap added a new option to ignore all errors of an specific field (#12089), it may worth to mention it here too.

Copy link
Contributor

Choose a reason for hiding this comment

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

IgnoreAllErrors option, it is aded by #12089

@fearful-symmetry
Copy link
Contributor Author

Yep, @jsoriano I added a mention about the IgnoreAllErrors option after @kaiyan-sheng mentioned it.

@fearful-symmetry
Copy link
Contributor Author

Also, do you have an idea of where we should add godocs for this? Just to Apply ?

@jsoriano
Copy link
Member

Yep, @jsoriano I added a mention about the IgnoreAllErrors option after @kaiyan-sheng mentioned it.

Oh, but take into account that this is an option for the fields (like it could be in "test_string": c.Str("testString", s.IgnoreAllErrors), not for schema.Apply. From what I see here it looks like it is an option for schema.Apply.

Also, do you have an idea of where we should add godocs for this? Just to Apply ?

It could be added to the Apply godocs, or we could add some package-level godocs.
It could be also nice to document ApplyTo method, that is like a lower-ish level function than Apply. Feel free to create an issue for these pending godocs (I should have added them after #7335).

@fearful-symmetry
Copy link
Contributor Author

Okay, having IgnoreAllErrors as a field option makes way more sense, hah.

I also added a doc example for ApplyTo

@fearful-symmetry
Copy link
Contributor Author

jenkins, test this

docs/devguide/create-metricset.asciidoc Outdated Show resolved Hide resolved
docs/devguide/create-metricset.asciidoc Outdated Show resolved Hide resolved
Copy link
Member

@jsoriano jsoriano left a comment

Choose a reason for hiding this comment

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

Thanks!

@fearful-symmetry fearful-symmetry merged commit 8b237b5 into elastic:master Jun 5, 2019
andrewvc pushed a commit to andrewvc/beats that referenced this pull request Jun 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Team:Integrations Label for the Integrations team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants