From 15fa34936b6f1febe896ecee0f49889a56347762 Mon Sep 17 00:00:00 2001 From: Julien Pivotto Date: Thu, 1 Sep 2022 17:05:54 +0200 Subject: [PATCH] PuppetDB SD: Add __meta_puppetdb_query label (#11238) Signed-off-by: Julien Pivotto --- discovery/puppetdb/puppetdb.go | 2 ++ discovery/puppetdb/puppetdb_test.go | 2 ++ docs/configuration/configuration.md | 1 + 3 files changed, 5 insertions(+) diff --git a/discovery/puppetdb/puppetdb.go b/discovery/puppetdb/puppetdb.go index 62449168e..f22a2e22b 100644 --- a/discovery/puppetdb/puppetdb.go +++ b/discovery/puppetdb/puppetdb.go @@ -40,6 +40,7 @@ import ( const ( pdbLabel = model.MetaLabelPrefix + "puppetdb_" + pdbLabelQuery = pdbLabel + "query" pdbLabelCertname = pdbLabel + "certname" pdbLabelResource = pdbLabel + "resource" pdbLabelType = pdbLabel + "type" @@ -215,6 +216,7 @@ func (d *Discovery) refresh(ctx context.Context) ([]*targetgroup.Group, error) { for _, resource := range resources { labels := model.LabelSet{ + pdbLabelQuery: model.LabelValue(d.query), pdbLabelCertname: model.LabelValue(resource.Certname), pdbLabelResource: model.LabelValue(resource.Resource), pdbLabelType: model.LabelValue(resource.Type), diff --git a/discovery/puppetdb/puppetdb_test.go b/discovery/puppetdb/puppetdb_test.go index 4913035ca..5514787d4 100644 --- a/discovery/puppetdb/puppetdb_test.go +++ b/discovery/puppetdb/puppetdb_test.go @@ -91,6 +91,7 @@ func TestPuppetDBRefresh(t *testing.T) { Targets: []model.LabelSet{ { model.AddressLabel: model.LabelValue("edinburgh.example.com:80"), + model.LabelName("__meta_puppetdb_query"): model.LabelValue("vhosts"), model.LabelName("__meta_puppetdb_certname"): model.LabelValue("edinburgh.example.com"), model.LabelName("__meta_puppetdb_environment"): model.LabelValue("prod"), model.LabelName("__meta_puppetdb_exported"): model.LabelValue("false"), @@ -131,6 +132,7 @@ func TestPuppetDBRefreshWithParameters(t *testing.T) { Targets: []model.LabelSet{ { model.AddressLabel: model.LabelValue("edinburgh.example.com:80"), + model.LabelName("__meta_puppetdb_query"): model.LabelValue("vhosts"), model.LabelName("__meta_puppetdb_certname"): model.LabelValue("edinburgh.example.com"), model.LabelName("__meta_puppetdb_environment"): model.LabelValue("prod"), model.LabelName("__meta_puppetdb_exported"): model.LabelValue("false"), diff --git a/docs/configuration/configuration.md b/docs/configuration/configuration.md index 527bd649e..d89bcc8ee 100644 --- a/docs/configuration/configuration.md +++ b/docs/configuration/configuration.md @@ -1184,6 +1184,7 @@ The resource address is the `certname` of the resource and can be changed during The following meta labels are available on targets during [relabeling](#relabel_config): +* `__meta_puppetdb_query`: the Puppet Query Language (PQL) query * `__meta_puppetdb_certname`: the name of the node associated with the resource * `__meta_puppetdb_resource`: a SHA-1 hash of the resource’s type, title, and parameters, for identification * `__meta_puppetdb_type`: the resource type