diff --git a/privmsg.go b/privmsg.go index cd93977..094fd19 100644 --- a/privmsg.go +++ b/privmsg.go @@ -22,7 +22,7 @@ import ( // tmiMessage processes a PRIVMSG from TMI. func (robo *Robot) tmiMessage(ctx context.Context, send chan<- *tmi.Message, msg *tmi.Message) { - robo.Metrics.TMIMsgsCount.Observe(1) + robo.metrics.TMIMsgsCount.Observe(1) ch, _ := robo.channels.Load(msg.To()) if ch == nil { // TMI gives a WHISPER for a direct message, so this is a message to a @@ -150,7 +150,7 @@ func (robo *Robot) tmiMessage(ctx context.Context, send chan<- *tmi.Message, msg } func (robo *Robot) command(ctx context.Context, log *slog.Logger, ch *channel.Channel, m *message.Received[message.User], cmd string) { - robo.Metrics.TMICommandCount.Observe(1) + robo.metrics.TMICommandCount.Observe(1) var c *twitchCommand var args map[string]string level := "any" @@ -188,7 +188,7 @@ func (robo *Robot) command(ctx context.Context, log *slog.Logger, ch *channel.Ch Spoken: robo.spoken, Owner: robo.owner, Contact: robo.ownerContact, - Metrics: robo.Metrics, + Metrics: robo.metrics, } inv := command.Invocation{ Channel: ch, @@ -238,8 +238,8 @@ func (robo *Robot) learn(ctx context.Context, log *slog.Logger, ch *channel.Chan log.ErrorContext(ctx, "failed to learn", slog.Any("err", err)) return } - robo.Metrics.LearnLatency.Observe(cost.Seconds(), ch.Learn) - robo.Metrics.LearnedCount.Observe(1) + robo.metrics.LearnLatency.Observe(cost.Seconds(), ch.Learn) + robo.metrics.LearnedCount.Observe(1) log.InfoContext(ctx, "learned", slog.Duration("cost", cost)) } @@ -262,7 +262,7 @@ func (robo *Robot) sendTMI(ctx context.Context, send chan<- *tmi.Message, msg me slog.String("in", msg.To), slog.String("text", msg.Text), ) - robo.Metrics.TMISendWait.Observe(d.Seconds()) + robo.metrics.TMISendWait.Observe(d.Seconds()) select { case <-ctx.Done(): return diff --git a/robot.go b/robot.go index 6b1708d..0481dc0 100644 --- a/robot.go +++ b/robot.go @@ -48,8 +48,8 @@ type Robot struct { tmi *client[*tmi.Message, *tmi.Message] // twitch is the Twitch API client. twitch twitch.Client - // Metrics are a collection of custom domain specific Metrics. - Metrics *metrics.Metrics + // metrics are a collection of custom domain specific metrics. + metrics *metrics.Metrics } // client is the settings for OAuth2 and related elements. @@ -79,7 +79,7 @@ func New(usersKey []byte, poolSize int) *Robot { channels: syncmap.New[string, *channel.Channel](), works: make(chan chan func(context.Context), poolSize), hashes: func() userhash.Hasher { return userhash.New(usersKey) }, - Metrics: newMetrics(), + metrics: newMetrics(), } } @@ -90,7 +90,7 @@ func (robo *Robot) Run(ctx context.Context, listen string) error { group.Go(func() error { return robo.runTwitch(ctx, group) }) } if listen != "" { - group.Go(func() error { return robo.api(ctx, listen, new(http.ServeMux), robo.Metrics.Collectors()) }) + group.Go(func() error { return robo.api(ctx, listen, new(http.ServeMux), robo.metrics.Collectors()) }) } err := group.Wait() if err == context.Canceled { diff --git a/tmi.go b/tmi.go index 2832443..3a39012 100644 --- a/tmi.go +++ b/tmi.go @@ -105,7 +105,7 @@ func (robo *Robot) clearchat(ctx context.Context, msg *tmi.Message) { slog.InfoContext(ctx, "clear all chat", slog.String("channel", msg.To()), slog.String("tag", tag)) for m := range ch.History.All() { slog.DebugContext(ctx, "forget all chat", slog.String("channel", msg.To()), slog.String("id", m.ID)) - robo.Metrics.ForgotCount.Observe(1) + robo.metrics.ForgotCount.Observe(1) err := robo.brain.Forget(ctx, tag, m.ID) if err != nil { slog.ErrorContext(ctx, "failed to forget while clearing all chat", @@ -129,7 +129,7 @@ func (robo *Robot) clearchat(ctx context.Context, msg *tmi.Message) { continue } slog.DebugContext(ctx, "forget from recent trace", slog.String("channel", msg.To()), slog.String("id", id)) - robo.Metrics.ForgotCount.Observe(1) + robo.metrics.ForgotCount.Observe(1) if err := robo.brain.Forget(ctx, tag, id); err != nil { slog.ErrorContext(ctx, "failed to forget from recent trace", slog.Any("err", err), @@ -146,7 +146,7 @@ func (robo *Robot) clearchat(ctx context.Context, msg *tmi.Message) { continue } slog.DebugContext(ctx, "forget from user", slog.String("channel", msg.To()), slog.String("id", m.ID)) - robo.Metrics.ForgotCount.Observe(1) + robo.metrics.ForgotCount.Observe(1) if err := robo.brain.Forget(ctx, ch.Learn, m.ID); err != nil { slog.ErrorContext(ctx, "failed to forget from user", slog.Any("err", err), @@ -172,7 +172,7 @@ func (robo *Robot) clearmsg(ctx context.Context, msg *tmi.Message) { if u != robo.tmi.name { // Forget a message from someone else. log.InfoContext(ctx, "forget message", slog.String("tag", ch.Learn), slog.String("id", t)) - forget(ctx, log, robo.Metrics.ForgotCount, robo.brain, ch.Learn, t) + forget(ctx, log, robo.metrics.ForgotCount, robo.brain, ch.Learn, t) return } // Forget a message from the robo. @@ -192,7 +192,7 @@ func (robo *Robot) clearmsg(ctx context.Context, msg *tmi.Message) { return } log.InfoContext(ctx, "forget trace", slog.String("tag", ch.Send), slog.Any("spoken", tm), slog.Any("trace", trace)) - forget(ctx, log, robo.Metrics.ForgotCount, robo.brain, ch.Send, trace...) + forget(ctx, log, robo.metrics.ForgotCount, robo.brain, ch.Send, trace...) } func forget(ctx context.Context, log *slog.Logger, forgetCount metrics.Observer, brain brain.Interface, tag string, trace ...string) {