Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: create asynq inspector #1011

Merged
merged 1 commit into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions commands/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ var LilyTracingFlags LilyTracingOpts

type LilyMetricOpts struct {
PrometheusPort string
RedisNetwork string
RedisAddr string
RedisUsername string
RedisPassword string
Expand Down Expand Up @@ -81,6 +80,25 @@ func setupLogging(flags LilyLogOpts) error {
return nil
}

func newAsynqInspector(addr string, db int, user, passwd string) (inspector *asynq.Inspector, err error) {
// Annoyingly NewInspector panics on invalid args, so we need to recover if args are invalid.
defer func() {
if r := recover(); r != nil {
inspector = nil
err = fmt.Errorf("failed to create asynq inspector: %v", r)
return
}
}()
inspector = asynq.NewInspector(asynq.RedisClientOpt{
Addr: addr,
DB: db,
Password: passwd,
Username: user,
})
err = nil
return
}

func setupMetrics(flags LilyMetricOpts) error {
// setup Prometheus
registry := prom.NewRegistry()
Expand All @@ -95,15 +113,14 @@ func setupMetrics(flags LilyMetricOpts) error {
}

metricCollectors := []prom.Collector{goCollector, procCollector}
if flags.RedisNetwork != "" {
inspector := asynq.NewInspector(asynq.RedisClientOpt{
Addr: flags.RedisAddr,
DB: flags.RedisDB,
Password: flags.RedisPassword,
Username: flags.RedisUsername,
})
if flags.RedisAddr != "" {
inspector, err := newAsynqInspector(flags.RedisAddr, flags.RedisDB, flags.RedisUsername, flags.RedisPassword)
if err != nil {
return err
}
metricCollectors = append(metricCollectors, asynqmetrics.NewQueueMetricsCollector(inspector))
}

registry.MustRegister(metricCollectors...)

// register prometheus with opencensus
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func main() {
Name: "redis-addr",
EnvVars: []string{"LILY_REDIS_ADDR"},
Usage: `Redis server address in "host:port" format`,
Value: "127.0.0.1:6379",
Value: "",
Destination: &commands.LilyMetricFlags.RedisAddr,
},

Expand Down