Plugin dnstap: add support for "extra" field in payload#6226
Conversation
Signed-off-by: chenyuheng <chenyuheng99@qq.com>
Signed-off-by: chenyuheng <chenyuheng99@qq.com>
Signed-off-by: chenyuheng <chenyuheng99@qq.com>
Signed-off-by: chenyuheng <chenyuheng99@qq.com>
|
This comment shows the result of manually testting for this change. Note that the current dnstap command line tool won't output "extra" field, so I tested this change with my edited dnstap command line tool, I will try to make another PR to update the change to the golang-dnstap repository later. With Corefile: The dnstap command line tool will have: |
| Message: m, | ||
| Identity: h.Identity, | ||
| Version: h.Version, | ||
| Extra: h.Extra, |
There was a problem hiding this comment.
what you implemented here is assigning a preconfigured text to Extra (which can be useful as well), whereas #6092 suggests extracting and assigning value of preconfigured metadata label.
The metadata value is normally created by other plugin, e.g. if you specify label "forward/upstream", it is expected that plugin 'forward' should provide this value. The plugin which provides metadata can generate different values for different queries, and this is the key difference from what you have implemented.
Please get familiar with plugin metadata https://github.com/coredns/coredns/tree/master/plugin/metadata as well as the package https://github.com/coredns/coredns/tree/master/plugin/pkg/replacer which can make your work easier
I also recommend to look at plugins 'rewrite' and 'log' as examples of plugins which read metadata from other plugins.
There was a problem hiding this comment.
Thanks for your kind review! I have introduced the replacer package in my new commits.
Since the replacer requires context, status (request.Request) and rr (*dnstest.Recorder), I have added a new function called TapMessageWithMetadata to receive these context objects and process the metadata replacement accordingly.
The old function TapMessage has not been removed, as external plugins may have dependencies on it.
Signed-off-by: chenyuheng <chenyuheng99@qq.com>
Signed-off-by: chenyuheng <chenyuheng99@qq.com>
rdrozhdzh
left a comment
There was a problem hiding this comment.
Please add also more unit tests to make sure the new functionality works as expected
|
|
||
| // TapMessageWithMetadata sends the message m to the dnstap interface, with "Extra" field being interpreted by the provided metadata context. | ||
| func (h Dnstap) TapMessageWithMetadata(m *tap.Message, ctx context.Context, state *request.Request, rr *dnstest.Recorder) { | ||
| func (h Dnstap) TapMessageWithMetadata(m *tap.Message, ctx context.Context, state request.Request, rr *dnstest.Recorder) { |
There was a problem hiding this comment.
I would suggest to remove the rr *dnstest.Recorder at all, and always pass nil to Replacer. I believe this parameter creates more inconveniences than benefits.
The recorder parameter is needed only for handling several standard labels like
coredns/plugin/pkg/replacer/replacer.go
Lines 87 to 111 in b95bc0a
This code can safely work with nil, i.e. it will not panic.
The reason why it's not so important to support these DNS response labels (as well as other DNS labels) is because DNSTAP already provides an alternative standardized way for transferring this data.
Regarding parameter state, this is more commonly used data type, and we can keep it. This should not be a big problem for developers of other plugins to provide it. However, if we decide to not support the standard DNS labels (as explained above), we can eliminate this parameter as well. You can pass empty Request{} to the replacer (this needs to be tested with all standard labels to avoid panics)
The only important parameter here is Context, which provides access to metadata.
I would appreciate a feedback from community regarding support of standard DNS labels (do we really need them?) for DNSTAP extra section, i.e.
coredns/plugin/pkg/replacer/replacer.go
Lines 37 to 57 in b95bc0a
There was a problem hiding this comment.
Thanks! I have updated these codes in my new commits. I will update the unit tests tomorrow.
For the state parameter, maybe we can just keep the function as:
func (h Dnstap) TapMessageWithMetadata(ctx context.Context, m *tap.Message, state request.Request) Leave the choice to plugin developers, if they think their plugins does not need to support these standard labels, they simply just pass the empty State{}
Signed-off-by: chenyuheng <chenyuheng99@qq.com>
Signed-off-by: chenyuheng <chenyuheng99@qq.com>
Signed-off-by: chenyuheng <chenyuheng99@qq.com>
Signed-off-by: chenyuheng <chenyuheng99@qq.com>
Signed-off-by: chenyuheng <chenyuheng99@qq.com>
rdrozhdzh
left a comment
There was a problem hiding this comment.
In general looks good, see minor comments
Signed-off-by: chenyuheng <chenyuheng99@qq.com>
Codecov Report
@@ Coverage Diff @@
## master #6226 +/- ##
==========================================
+ Coverage 55.70% 58.37% +2.67%
==========================================
Files 224 251 +27
Lines 10016 16418 +6402
==========================================
+ Hits 5579 9584 +4005
- Misses 3978 6247 +2269
- Partials 459 587 +128
... and 168 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Signed-off-by: chenyuheng <chenyuheng99@qq.com>
Signed-off-by: chenyuheng <chenyuheng99@qq.com>
|
@chenyuheng FYI the DNS-collector tool supports the extra field, any contributions will be appreciated. |

1. Why is this pull request needed and what does it do?
As proposed in #6092 , this PR adds supports to customize "extra" field in dnstap payload, the field could be set in the config file.
The "extra" field in defined in dnstap.proto.
2. Which issues (if any) are related?
#6092
3. Which documentation changes (if any) need to be made?
The plugin README: https://github.com/coredns/coredns/blob/master/plugin/dnstap/README.md
4. Does this introduce a backward incompatible change or deprecation?
No