Skip to content

Commit

Permalink
Add metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
jacksontj committed Mar 16, 2023
1 parent 4a32f75 commit 803bed1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
31 changes: 29 additions & 2 deletions pkg/promclient/labelfilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,31 @@ import (
"time"

v1 "github.com/prometheus/client_golang/api/prometheus/v1"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/promql/parser"
"github.com/sirupsen/logrus"
)

// Metrics
var (
syncCount = prometheus.NewCounterVec(prometheus.CounterOpts{
Name: "promxy_label_filter_sync_count_total",
Help: "How many syncs completed from a promxy label_filter, partitioned by success",
}, []string{"status"})
syncSummary = prometheus.NewSummaryVec(prometheus.SummaryOpts{
Name: "promxy_label_filter_sync_duration_seconds",
Help: "Latency of sync process from a promxy label_fitler",
}, []string{"status"})
)

func init() {
prometheus.MustRegister(
syncCount,
syncSummary,
)
}

type LabelFilterConfig struct {
LabelsToFilter []string `yaml:"labels_to_filter"`
SyncInterval time.Duration `yaml:"sync_interval"`
Expand Down Expand Up @@ -58,10 +78,17 @@ func NewLabelFilterClient(ctx context.Context, a API, cfg *LabelFilterConfig) (*
for {
select {
case <-ticker.C:
// TODO: metric on sync status
if err := c.Sync(ctx); err != nil {
start := time.Now()
err := c.Sync(ctx)
took := time.Since(start)
status := "success"
if err != nil {
logrus.Errorf("error syncing in label_filter from downstream: %#v", err)
status = "error"
}
syncCount.WithLabelValues(status).Inc()
syncSummary.WithLabelValues(status).Observe(took.Seconds())

case <-ctx.Done():
ticker.Stop()
return
Expand Down
2 changes: 1 addition & 1 deletion pkg/servergroup/servergroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func (s *ServerGroup) loadTargetGroupMap(targetGroupMap map[string][]*targetgrou
apiClient = &promclient.DebugAPI{apiClient, u.String()}
}

// Add LabelFilter if configured
// Add LabelFilter if configured
if s.Cfg.LabelFilterConfig != nil {
apiClient, err = promclient.NewLabelFilterClient(ctx, apiClient, s.Cfg.LabelFilterConfig)
if err != nil {
Expand Down

0 comments on commit 803bed1

Please sign in to comment.