Skip to content

Commit

Permalink
Improve logging of prometheus-to-sd.
Browse files Browse the repository at this point in the history
Add component names to logs, replace some warning log messages with
info and update verbosity level for some of them.
  • Loading branch information
loburm committed Aug 14, 2017
1 parent 2a7cf30 commit 2ff2cc4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
5 changes: 3 additions & 2 deletions prometheus-to-sd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ func readAndPushDataToStackdriver(stackdriverService *v3.Service, gceConf *confi
metricDescriptorCache.Refresh()
if useWhitelistedMetricsAutodiscovery {
sourceConfig.UpdateWhitelistedMetrics(metricDescriptorCache.GetMetricNames())
glog.V(2).Infof("Autodiscovered whitelisted metrics for component %v: %v", commonConfig.ComponentName, sourceConfig.Whitelisted)
}
signal = time.After(*metricDescriptorsResolution)
default:
Expand All @@ -143,7 +144,7 @@ func readAndPushDataToStackdriver(stackdriverService *v3.Service, gceConf *confi
}
metrics, err := translator.GetPrometheusMetrics(sourceConfig.Host, sourceConfig.Port)
if err != nil {
glog.Warningf("Error while getting Prometheus metrics %v", err)
glog.V(2).Infof("Error while getting Prometheus metrics %v for component %v", err, sourceConfig.Component)
continue
}
if *omitComponentName {
Expand All @@ -153,6 +154,6 @@ func readAndPushDataToStackdriver(stackdriverService *v3.Service, gceConf *confi
metricDescriptorCache.UpdateMetricDescriptors(metrics, sourceConfig.Whitelisted)
}
ts := translator.TranslatePrometheusToStackdriver(commonConfig, sourceConfig.Whitelisted, metrics, metricDescriptorCache)
translator.SendToStackdriver(stackdriverService, gceConf, ts)
translator.SendToStackdriver(stackdriverService, commonConfig, ts)
}
}
2 changes: 1 addition & 1 deletion prometheus-to-sd/translator/metric_descriptor_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (cache *MetricDescriptorCache) updateMetricDescriptorIfStale(metricFamily *
func (cache *MetricDescriptorCache) getMetricDescriptor(metric string) *v3.MetricDescriptor {
value, ok := cache.descriptors[metric]
if !ok {
glog.Warningf("Metric %s was not found in the cache.", metric)
glog.V(4).Infof("Metric %s was not found in the cache for component %v", metric, cache.component)
}
return value
}
Expand Down
8 changes: 4 additions & 4 deletions prometheus-to-sd/translator/stackdriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ const (
)

// SendToStackdriver sends http request to Stackdriver to create the given timeserieses.
func SendToStackdriver(service *v3.Service, config *config.GceConfig, ts []*v3.TimeSeries) {
func SendToStackdriver(service *v3.Service, config *config.CommonConfig, ts []*v3.TimeSeries) {
if len(ts) == 0 {
glog.Warningf("No metrics to send to Stackdriver")
glog.V(3).Infof("No metrics to send to Stackdriver for component %v", config.ComponentName)
return
}

proj := createProjectName(config)
proj := createProjectName(config.GceConfig)

var wg sync.WaitGroup
var failedTs uint32
Expand All @@ -60,7 +60,7 @@ func SendToStackdriver(service *v3.Service, config *config.GceConfig, ts []*v3.T
}(i, end)
}
wg.Wait()
glog.V(4).Infof("Successfully sent %v timeserieses to Stackdriver", uint32(len(ts))-failedTs)
glog.V(4).Infof("Successfully sent %v timeserieses to Stackdriver for component %v", uint32(len(ts))-failedTs, config.ComponentName)
}

func getMetricDescriptors(service *v3.Service, config *config.GceConfig, component string) (map[string]*v3.MetricDescriptor, error) {
Expand Down
4 changes: 2 additions & 2 deletions prometheus-to-sd/translator/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func filterWhitelisted(allMetrics map[string]*dto.MetricFamily, whitelisted []st
if family, found := allMetrics[w]; found {
res[w] = family
} else {
glog.V(4).Infof("Whitelisted metric %s not present in Prometheus endpoint.", w)
glog.V(3).Infof("Whitelisted metric %s not present in Prometheus endpoint.", w)
}
}
return res
Expand All @@ -114,7 +114,7 @@ func translateFamily(config *config.CommonConfig,
startTime time.Time,
cache *MetricDescriptorCache) ([]*v3.TimeSeries, error) {

glog.V(4).Infof("Translating metric family %v", family.GetName())
glog.V(3).Infof("Translating metric family %v from component", family.GetName(), config.ComponentName)
var ts []*v3.TimeSeries
if _, found := supportedMetricTypes[family.GetType()]; !found {
return ts, fmt.Errorf("Metric type %v of family %s not supported", family.GetType(), family.GetName())
Expand Down

0 comments on commit 2ff2cc4

Please sign in to comment.