Fix view in migration. Add by lang metric to consumer.

This commit is contained in:
mathan 2024-02-22 18:54:29 -08:00
parent 600dac7694
commit db425b1d5f
11 changed files with 101 additions and 33 deletions

View file

@ -295,6 +295,14 @@ func (c *Consumer) processMessage(ctx context.Context, typ string, r io.Reader,
log.Warn().Msgf("Unexpected key format: %q", k)
continue
}
langs, _, err := repo.GetLang(ctx, v)
if err == nil {
lang := ""
if len(langs) != 0 {
lang = langs[0]
}
postsByLanguageIndexed.WithLabelValues(c.remote.Host, lang).Inc()
}
recs = append(recs, repo.Record{
Repo: models.ID(repoInfo.ID),
Collection: parts[0],

View file

@ -39,6 +39,25 @@ type Config struct {
var config Config
// todo figure out how to use this shit
// type LangTimestampCollector struct {
// metric *prometheus.Desc
// }
// func (c *LangTimestampCollector) Describe(ch chan<- *prometheus.Desc) {
// ch <- c.metric
// }
// func (c *LangTimestampCollector) Collect(ch chan<- prometheus.Metric) {
// // your logic should be placed here
// t := time.Date(2009, time.November, 10, 23, 0, 0, 12345678, time.UTC)
// s := prometheus.NewMetricWithTimestamp(t, prometheus.MustNewConstMetric(c.metric, prometheus.CounterValue, 123))
// ch <- s
// }
func runMain(ctx context.Context) error {
ctx = setupLogging(ctx)
log := zerolog.Ctx(ctx)
@ -69,6 +88,16 @@ func runMain(ctx context.Context) error {
}
}
// collector := &LangTimestampCollector{
// metric: prometheus.NewDesc(
// "indexer_posts_by_language_timestamp_count",
// "Language metric with custom TS",
// nil,
// nil,
// ),
// }
// prometheus.MustRegister(collector)
log.Info().Msgf("Starting HTTP listener on %q...", config.MetricsPort)
http.Handle("/metrics", promhttp.Handler())
srv := &http.Server{Addr: fmt.Sprintf(":%s", config.MetricsPort)}

View file

@ -19,3 +19,8 @@ var reposDiscovered = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "repo_discovered_counter",
Help: "Counter of newly discovered repos",
}, []string{"remote"})
var postsByLanguageIndexed = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "indexer_posts_by_language_count",
Help: "Number of posts by language",
}, []string{"remote", "lang"})