Skip to content

Commit

Permalink
robot: unexport metrics field
Browse files Browse the repository at this point in the history
  • Loading branch information
zephyrtronium committed Jan 1, 2025
1 parent 0bc2085 commit e9a2c1f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
12 changes: 6 additions & 6 deletions privmsg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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))
}

Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions robot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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(),
}
}

Expand All @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions tmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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.
Expand All @@ -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) {
Expand Down

0 comments on commit e9a2c1f

Please sign in to comment.