From ff832d2e0306d521712975814cc693580ad70dd0 Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Tue, 19 May 2015 15:24:26 +0200 Subject: [PATCH] Attach __meta_filepath label to file SD targets. --- retrieval/discovery/file.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/retrieval/discovery/file.go b/retrieval/discovery/file.go index 7e16b5f66..a439d6874 100644 --- a/retrieval/discovery/file.go +++ b/retrieval/discovery/file.go @@ -26,8 +26,12 @@ import ( "gopkg.in/yaml.v2" "github.com/prometheus/prometheus/config" + + clientmodel "github.com/prometheus/client_golang/model" ) +const FileSDFilepathLabel = clientmodel.MetaLabelPrefix + "filepath" + // FileDiscovery provides service discovery functionality based // on files that contain target groups in JSON or YAML format. Refreshing // happens using file watches and periodic refreshes. @@ -196,7 +200,7 @@ func fileSource(filename string, i int) string { // Stop implements the TargetProvider interface. func (fd *FileDiscovery) Stop() { - glog.V(1).Info("Stopping file discovery for %s...", fd.paths) + glog.V(1).Infof("Stopping file discovery for %s...", fd.paths) fd.done <- struct{}{} // Closing the watcher will deadlock unless all events and errors are drained. @@ -215,7 +219,7 @@ func (fd *FileDiscovery) Stop() { fd.done <- struct{}{} - glog.V(1).Info("File discovery for %s stopped.", fd.paths) + glog.V(1).Infof("File discovery for %s stopped.", fd.paths) } // readFile reads a JSON or YAML list of targets groups from the file, depending on its @@ -243,6 +247,9 @@ func readFile(filename string) ([]*config.TargetGroup, error) { for i, tg := range targetGroups { tg.Source = fileSource(filename, i) + tg.Labels = clientmodel.LabelSet{ + FileSDFilepathLabel: clientmodel.LabelValue(filename), + } } return targetGroups, nil }