Skip to content

Commit

Permalink
fix: crash when --api is not set (#79)
Browse files Browse the repository at this point in the history
Prometheus was always expecting to be there but API is not always set when crawls are ran. This resolves that issue.
  • Loading branch information
NGTmeaty authored and CorentinB committed Jul 15, 2024
1 parent a1f0efd commit de41b1d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,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 {
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/crawl/capture.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (c *Crawl) executeGET(item *queue.Item, req *http.Request, isRedirection bo
)

defer func() {
if c.API {
if c.PrometheusMetrics != nil {
c.PrometheusMetrics.DownloadedURI.Inc()
}

Expand Down

0 comments on commit de41b1d

Please sign in to comment.