aboutsummaryrefslogtreecommitdiff
path: root/plugin
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2018-07-09 07:58:14 +0100
committerGravatar GitHub <noreply@github.com> 2018-07-09 07:58:14 +0100
commitb27a59c160da16ee48891d82a6fdcff7d0694fd4 (patch)
tree3f8feb6724be8bcfaee7644525055d6233777123 /plugin
parentb3a92f1622e33076e5378eeb547f07afaa1aac9b (diff)
downloadcoredns-b27a59c160da16ee48891d82a6fdcff7d0694fd4.tar.gz
coredns-b27a59c160da16ee48891d82a6fdcff7d0694fd4.tar.zst
coredns-b27a59c160da16ee48891d82a6fdcff7d0694fd4.zip
plugin/metadata: finish documentation (#1951)
* plugin/metadata: finish documentation Finish the README.md, add corner case in the IsLabel test and reword some code comments slightly. Generate the man-pages and add man/coredns-metadata.7 as well. Signed-off-by: Miek Gieben <miek@miek.nl> * Fix test Signed-off-by: Miek Gieben <miek@miek.nl>
Diffstat (limited to 'plugin')
-rw-r--r--plugin/metadata/README.md21
-rw-r--r--plugin/metadata/metadata_test.go7
-rw-r--r--plugin/metadata/provider.go2
3 files changed, 19 insertions, 11 deletions
diff --git a/plugin/metadata/README.md b/plugin/metadata/README.md
index aaf3375b1..55aa4d41b 100644
--- a/plugin/metadata/README.md
+++ b/plugin/metadata/README.md
@@ -8,15 +8,20 @@
By enabling *metadata* any plugin that implements [metadata.Provider
interface](https://godoc.org/github.com/coredns/coredns/plugin/metadata#Provider) will be called for
-each DNS query, at beginning of the process for that query, in order to add it's own Metadata to
+each DNS query, at beginning of the process for that query, in order to add it's own meta data to
context.
-The metadata collected will be available for all plugins, via the Context parameter
-provided in the ServeDNS function. The package (code) documentation has examples on how to inspect
-and retrieve metadata a plugin might be interested in.
+The meta data collected will be available for all plugins, via the Context parameter provided in the
+ServeDNS function. The package (code) documentation has examples on how to inspect and retrieve
+metadata a plugin might be interested in.
-TODO: write about naming of the keys (labels).
-TODO: write about extracting and using
+The meta data is added by setting a label with a value in the context. These labels should be named
+`plugin/NAME`, where **NAME** is something descriptive. The only hard requirement the *metadata*
+plugin enforces is that the labels contains a slash. See the documentation for
+`metadata.SetValueFunc`.
+
+The value stored is a string. The empty string signals "no meta data". See the documentation for
+`metadata.ValueFunc` on how to retrieve this.
## Syntax
@@ -28,7 +33,7 @@ metadata [ZONES... ]
## Plugins
-metadata.Provider interface needs to be implemented by each plugin willing to provide metadata
+`metadata.Provider` interface needs to be implemented by each plugin willing to provide metadata
information for other plugins. It will be called by metadata and gather the information from all
plugins in context.
@@ -36,7 +41,7 @@ Note: this method should work quickly, because it is called for every request.
## Examples
-There are currently no in tree plugins that write or use metadata.
+The *rewrite* plugin uses meta data to rewrite requests.
## Also See
diff --git a/plugin/metadata/metadata_test.go b/plugin/metadata/metadata_test.go
index 08d9b6734..be20f8770 100644
--- a/plugin/metadata/metadata_test.go
+++ b/plugin/metadata/metadata_test.go
@@ -68,20 +68,23 @@ func TestLabelFormat(t *testing.T) {
label string
isValid bool
}{
+ // ok
{"plugin/LABEL", true},
{"p/LABEL", true},
{"plugin/L", true},
+ // fails
{"LABEL", false},
{"plugin.LABEL", false},
{"/NO-PLUGIN-NOT-ACCEPTED", false},
{"ONLY-PLUGIN-NOT-ACCEPTED/", false},
{"PLUGIN/LABEL/SUB-LABEL", false},
{"/", false},
+ {"//", false},
}
for _, test := range labels {
- if IsLabel(test.label) != test.isValid {
- t.Errorf("Label %v is expected to have this validaty : %v - and has the opposite", test.label, test.isValid)
+ if x := IsLabel(test.label); x != test.isValid {
+ t.Errorf("Label %v expected %v, got: %v", test.label, test.isValid, x)
}
}
}
diff --git a/plugin/metadata/provider.go b/plugin/metadata/provider.go
index 276a44127..cdb9c878a 100644
--- a/plugin/metadata/provider.go
+++ b/plugin/metadata/provider.go
@@ -49,7 +49,7 @@ type Provider interface {
// Func is the type of function in the metadata, when called they return the value of the label.
type Func func() string
-// IsLabel check that the provided name looks like a valid label name
+// IsLabel checks that the provided name is a valid label name, i.e. two words separated by a slash.
func IsLabel(label string) bool {
p := strings.Index(label, "/")
if p <= 0 || p >= len(label)-1 {