Add few more metrics
This commit is contained in:
parent
334af033b8
commit
1d25842b78
5 changed files with 77 additions and 13 deletions
|
@ -187,6 +187,8 @@ func escapeNullCharForPostgres(b []byte) []byte {
|
|||
func (c *Consumer) processMessage(ctx context.Context, typ string, r io.Reader, first bool) error {
|
||||
log := zerolog.Ctx(ctx)
|
||||
|
||||
eventCounter.WithLabelValues(c.remote.Host, typ).Inc()
|
||||
|
||||
switch typ {
|
||||
case "#commit":
|
||||
payload := &comatproto.SyncSubscribeRepos_Commit{}
|
||||
|
@ -194,6 +196,8 @@ func (c *Consumer) processMessage(ctx context.Context, typ string, r io.Reader,
|
|||
return fmt.Errorf("failed to unmarshal commit: %w", err)
|
||||
}
|
||||
|
||||
exportEventTimestamp(ctx, c.remote.Host, payload.Time)
|
||||
|
||||
if c.remote.FirstCursorSinceReset == 0 {
|
||||
if err := c.resetCursor(ctx, payload.Seq); err != nil {
|
||||
return fmt.Errorf("handling cursor reset: %w", err)
|
||||
|
@ -205,7 +209,7 @@ func (c *Consumer) processMessage(ctx context.Context, typ string, r io.Reader,
|
|||
}
|
||||
}
|
||||
|
||||
repoInfo, err := repo.EnsureExists(ctx, c.db, payload.Repo)
|
||||
repoInfo, created, err := repo.EnsureExists(ctx, c.db, payload.Repo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("repo.EnsureExists(%q): %w", payload.Repo, err)
|
||||
}
|
||||
|
@ -214,6 +218,9 @@ func (c *Consumer) processMessage(ctx context.Context, typ string, r io.Reader,
|
|||
Msgf("Commit from an incorrect PDS, skipping")
|
||||
return nil
|
||||
}
|
||||
if created {
|
||||
reposDiscovered.WithLabelValues(c.remote.Host).Inc()
|
||||
}
|
||||
|
||||
// TODO: verify signature
|
||||
|
||||
|
@ -320,6 +327,8 @@ func (c *Consumer) processMessage(ctx context.Context, typ string, r io.Reader,
|
|||
return fmt.Errorf("failed to unmarshal commit: %w", err)
|
||||
}
|
||||
|
||||
exportEventTimestamp(ctx, c.remote.Host, payload.Time)
|
||||
|
||||
if c.remote.FirstCursorSinceReset == 0 {
|
||||
if err := c.resetCursor(ctx, payload.Seq); err != nil {
|
||||
return fmt.Errorf("handling cursor reset: %w", err)
|
||||
|
@ -340,6 +349,8 @@ func (c *Consumer) processMessage(ctx context.Context, typ string, r io.Reader,
|
|||
return fmt.Errorf("failed to unmarshal commit: %w", err)
|
||||
}
|
||||
|
||||
exportEventTimestamp(ctx, c.remote.Host, payload.Time)
|
||||
|
||||
if c.remote.FirstCursorSinceReset == 0 {
|
||||
if err := c.resetCursor(ctx, payload.Seq); err != nil {
|
||||
return fmt.Errorf("handling cursor reset: %w", err)
|
||||
|
@ -362,6 +373,8 @@ func (c *Consumer) processMessage(ctx context.Context, typ string, r io.Reader,
|
|||
return fmt.Errorf("failed to unmarshal commit: %w", err)
|
||||
}
|
||||
|
||||
exportEventTimestamp(ctx, c.remote.Host, payload.Time)
|
||||
|
||||
if c.remote.FirstCursorSinceReset == 0 {
|
||||
if err := c.resetCursor(ctx, payload.Seq); err != nil {
|
||||
return fmt.Errorf("handling cursor reset: %w", err)
|
||||
|
@ -448,3 +461,11 @@ func parseError(node datamodel.Node) (xrpc.XRPCError, error) {
|
|||
|
||||
return r, nil
|
||||
}
|
||||
|
||||
func exportEventTimestamp(ctx context.Context, remote string, timestamp string) {
|
||||
if t, err := time.Parse(time.RFC3339, timestamp); err != nil {
|
||||
zerolog.Ctx(ctx).Error().Err(err).Str("pds", remote).Msgf("Failed to parse %q as a timestamp: %s", timestamp, err)
|
||||
} else {
|
||||
lastEventTimestamp.WithLabelValues(remote).Set(float64(t.Unix()))
|
||||
}
|
||||
}
|
||||
|
|
21
cmd/consumer/metrics.go
Normal file
21
cmd/consumer/metrics.go
Normal file
|
@ -0,0 +1,21 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
)
|
||||
|
||||
var lastEventTimestamp = promauto.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Name: "repo_commit_received_timestamp",
|
||||
Help: "Timestamp of the last event received from firehose.",
|
||||
}, []string{"remote"})
|
||||
|
||||
var eventCounter = promauto.NewCounterVec(prometheus.CounterOpts{
|
||||
Name: "repo_commits_received_counter",
|
||||
Help: "Counter of events received from each remote.",
|
||||
}, []string{"remote", "type"})
|
||||
|
||||
var reposDiscovered = promauto.NewCounterVec(prometheus.CounterOpts{
|
||||
Name: "repo_discovered_counter",
|
||||
Help: "Counter of newly discovered repos",
|
||||
}, []string{"remote"})
|
|
@ -91,10 +91,13 @@ func (l *Lister) run(ctx context.Context) {
|
|||
break
|
||||
}
|
||||
log.Info().Msgf("Received %d DIDs from %q", len(dids), remote.Host)
|
||||
reposListed.WithLabelValues(remote.Host).Add(float64(len(dids)))
|
||||
|
||||
for _, did := range dids {
|
||||
if _, err := repo.EnsureExists(ctx, l.db, did); err != nil {
|
||||
if _, created, err := repo.EnsureExists(ctx, l.db, did); err != nil {
|
||||
log.Error().Err(err).Msgf("Failed to ensure that we have a record for the repo %q: %s", did, err)
|
||||
} else if created {
|
||||
reposDiscovered.WithLabelValues(remote.Host).Inc()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
16
cmd/lister/metrics.go
Normal file
16
cmd/lister/metrics.go
Normal file
|
@ -0,0 +1,16 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
)
|
||||
|
||||
var reposDiscovered = promauto.NewCounterVec(prometheus.CounterOpts{
|
||||
Name: "repo_discovered_counter",
|
||||
Help: "Counter of newly discovered repos",
|
||||
}, []string{"remote"})
|
||||
|
||||
var reposListed = promauto.NewCounterVec(prometheus.CounterOpts{
|
||||
Name: "repo_listed_counter",
|
||||
Help: "Counter of repos received by listing PDSs.",
|
||||
}, []string{"remote"})
|
Loading…
Add table
Add a link
Reference in a new issue