Skip to content
This repository has been archived by the owner on Dec 29, 2020. It is now read-only.

Commit

Permalink
feat(metrics): report new and skipped labels (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Nov 27, 2019
1 parent cfd4c4b commit 0db40f2
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions postgres/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,29 @@ var (
)
lenLabelCache = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "used_current",
Name: "cache_current",
Namespace: "adapter",
Subsystem: "cache",
Subsystem: "labels",
Help: "Current number of cached label sets.",
},
[]string{"remote"},
)
totalNewLabels = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "new_total",
Namespace: "adapter",
Subsystem: "labels",
},
[]string{"remote"},
)
totalSkipLabels = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "skip_total",
Namespace: "adapter",
Subsystem: "labels",
},
[]string{"remote"},
)

labels_nothing = "INSERT INTO metric_labels(lid, time, labels) VALUES ( $1, $2, $3 ) ON CONFLICT (lid) DO NOTHING"
labels_update = "INSERT INTO metric_labels(lid, time, labels) VALUES ( $1, $2, $3 ) ON CONFLICT (lid) DO UPDATE SET time = EXCLUDED.time"
Expand All @@ -96,6 +112,8 @@ func init() {
prometheus.MustRegister(curOpenConns)
prometheus.MustRegister(maxOpenConns)
prometheus.MustRegister(lenLabelCache)
prometheus.MustRegister(totalNewLabels)
prometheus.MustRegister(totalSkipLabels)
}

// NewClient creates a new Client.
Expand Down Expand Up @@ -169,9 +187,13 @@ func (c *Client) WriteLabels(samples model.Samples, txn *sql.Tx) error {
}
defer stmt.Close()

newLabels := 0
skipLabels := 0

for _, s := range samples {
l := s.Metric.String()
if c.cache.Contains(l) {
skipLabels++
level.Debug(c.logger).Log("msg", "skipping duplicate labels", "labels", l)
continue
}
Expand All @@ -194,8 +216,12 @@ func (c *Client) WriteLabels(samples model.Samples, txn *sql.Tx) error {
}

c.cache.Add(l, lid)
newLabels++
}

totalNewLabels.WithLabelValues(c.Name()).Add(float64(newLabels))
totalSkipLabels.WithLabelValues(c.Name()).Add(float64(skipLabels))

return nil
}

Expand Down

0 comments on commit 0db40f2

Please sign in to comment.