From 3c42e0a393f4c9e4d411a9bbc6fdfca36a4b55df Mon Sep 17 00:00:00 2001 From: Jake LaFountain Date: Mon, 15 Jul 2024 05:12:13 -0400 Subject: [PATCH] fix: crash when --api is not set Prometheus was always expecting to be there but API is not always set when crawls are ran. This resolves that issue. --- cmd/utils.go | 7 ++++--- internal/pkg/crawl/capture.go | 4 +++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/cmd/utils.go b/cmd/utils.go index c388f4e3..7696f616 100644 --- a/cmd/utils.go +++ b/cmd/utils.go @@ -145,9 +145,10 @@ func InitCrawlWithCMD(flags config.Flags) *crawl.Crawl { c.API = flags.API c.APIPort = flags.APIPort - c.PrometheusMetrics = new(crawl.PrometheusMetrics) - c.PrometheusMetrics.Prefix = flags.PrometheusPrefix - + if c.API { + c.PrometheusMetrics = new(crawl.PrometheusMetrics) + c.PrometheusMetrics.Prefix = flags.PrometheusPrefix + } if flags.UserAgent != "Zeno" { c.UserAgent = flags.UserAgent } else { diff --git a/internal/pkg/crawl/capture.go b/internal/pkg/crawl/capture.go index b178f674..f06ccb73 100644 --- a/internal/pkg/crawl/capture.go +++ b/internal/pkg/crawl/capture.go @@ -36,7 +36,9 @@ func (c *Crawl) executeGET(item *frontier.Item, req *http.Request, isRedirection ) defer func() { - c.PrometheusMetrics.DownloadedURI.Inc() + if c.PrometheusMetrics != nil { + c.PrometheusMetrics.DownloadedURI.Inc() + } c.URIsPerSecond.Incr(1)