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()))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue