Skip to content

Commit

Permalink
Merge pull request prometheus#2966 from alkalinecoffee/consul-node-me…
Browse files Browse the repository at this point in the history
…tadata

Add support for consul's node metadata
  • Loading branch information
grobie authored Sep 2, 2017
2 parents d0a0270 + aba41c7 commit 29fff1e
Show file tree
Hide file tree
Showing 9 changed files with 282 additions and 38 deletions.
15 changes: 13 additions & 2 deletions discovery/consul/consul.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/config"
"github.com/prometheus/prometheus/util/httputil"
"github.com/prometheus/prometheus/util/strutil"
"golang.org/x/net/context"
)

Expand All @@ -38,6 +39,8 @@ const (
addressLabel = model.MetaLabelPrefix + "consul_address"
// nodeLabel is the name for the label containing a target's node name.
nodeLabel = model.MetaLabelPrefix + "consul_node"
// metaDataLabel is the prefix for the labels mapping to a target's metadata.
metaDataLabel = model.MetaLabelPrefix + "consul_metadata_"
// tagsLabel is the name of the label containing the tags assigned to the target.
tagsLabel = model.MetaLabelPrefix + "consul_tags"
// serviceLabel is the name of the label containing the service name.
Expand Down Expand Up @@ -294,15 +297,23 @@ func (srv *consulService) watch(ctx context.Context, ch chan<- []*config.TargetG
addr = net.JoinHostPort(node.Address, fmt.Sprintf("%d", node.ServicePort))
}

tgroup.Targets = append(tgroup.Targets, model.LabelSet{
labels := model.LabelSet{
model.AddressLabel: model.LabelValue(addr),
addressLabel: model.LabelValue(node.Address),
nodeLabel: model.LabelValue(node.Node),
tagsLabel: model.LabelValue(tags),
serviceAddressLabel: model.LabelValue(node.ServiceAddress),
servicePortLabel: model.LabelValue(strconv.Itoa(node.ServicePort)),
serviceIDLabel: model.LabelValue(node.ServiceID),
})
}

// Add all key/value pairs from the node's metadata as their own labels
for k, v := range node.NodeMeta {
name := strutil.SanitizeLabelName(k)
labels[metaDataLabel+model.LabelName(name)] = model.LabelValue(v)
}

tgroup.Targets = append(tgroup.Targets, labels)
}
// Check context twice to ensure we always catch cancelation.
select {
Expand Down
60 changes: 60 additions & 0 deletions vendor/github.com/hashicorp/consul/api/agent.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 39 additions & 7 deletions vendor/github.com/hashicorp/consul/api/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions vendor/github.com/hashicorp/consul/api/catalog.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 62 additions & 7 deletions vendor/github.com/hashicorp/consul/api/health.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 29fff1e

Please sign in to comment.