diff --git a/changelog.d/701.misc b/changelog.d/701.misc new file mode 100644 index 00000000..28cd3054 --- /dev/null +++ b/changelog.d/701.misc @@ -0,0 +1 @@ +Ensure all Hookshot specific metrics have a `hookshot_` prefix. diff --git a/contrib/hookshot-dashboard.json b/contrib/hookshot-dashboard.json index 38df6e74..7e3f3ec4 100644 --- a/contrib/hookshot-dashboard.json +++ b/contrib/hookshot-dashboard.json @@ -1369,7 +1369,7 @@ }, "editorMode": "builder", "exemplar": false, - "expr": "feed_count", + "expr": "hookshot_feeds_count", "instant": false, "legendFormat": "{{__name__}}", "range": true, @@ -1462,7 +1462,7 @@ "uid": "${datasource}" }, "editorMode": "builder", - "expr": "feed_fetch_ms", + "expr": "hookshot_feeds_fetch_ms", "legendFormat": "{{__name__}}", "range": true, "refId": "A" diff --git a/docs/metrics.md b/docs/metrics.md index 504c00b1..68444735 100644 --- a/docs/metrics.md +++ b/docs/metrics.md @@ -31,6 +31,9 @@ Below is the generated list of Prometheus metrics for Hookshot. | hookshot_notifications_push | Number of notifications pushed | service | | hookshot_notifications_service_up | Is the notification service up or down | service | | hookshot_notifications_watchers | Number of notifications watchers running | service | +| hookshot_feeds_count | The number of RSS feeds that hookshot is subscribed to | | +| hookshot_feeds_fetch_ms | The time taken for hookshot to fetch all feeds | | +| hookshot_feeds_failing | The number of RSS feeds that hookshot is failing to read | reason | ## matrix | Metric | Help | Labels | |--------|------|--------| @@ -41,9 +44,9 @@ Below is the generated list of Prometheus metrics for Hookshot. ## feed | Metric | Help | Labels | |--------|------|--------| -| feed_count | The number of RSS feeds that hookshot is subscribed to | | -| feed_fetch_ms | The time taken for hookshot to fetch all feeds | | -| feed_failing | The number of RSS feeds that hookshot is failing to read | reason | +| feed_count | (Deprecated) The number of RSS feeds that hookshot is subscribed to | | +| feed_fetch_ms | (Deprecated) The time taken for hookshot to fetch all feeds | | +| feed_failing | (Deprecated) The number of RSS feeds that hookshot is failing to read | reason | ## process | Metric | Help | Labels | |--------|------|--------| diff --git a/src/Metrics.ts b/src/Metrics.ts index 2fec2456..8e06c69c 100644 --- a/src/Metrics.ts +++ b/src/Metrics.ts @@ -24,15 +24,18 @@ export class Metrics { public readonly matrixAppserviceEvents = new Counter({ name: "matrix_appservice_events", help: "The number of events sent over the AS API", labelNames: [], registers: [this.registry]}); public readonly matrixAppserviceDecryptionFailed = new Counter({ name: "matrix_appservice_decryption_failed", help: "The number of events sent over the AS API that failed to decrypt", registers: [this.registry]}); - public readonly feedsCount = new Gauge({ name: "feed_count", help: "The number of RSS feeds that hookshot is subscribed to", labelNames: [], registers: [this.registry]}); - public readonly feedFetchMs = new Gauge({ name: "feed_fetch_ms", help: "The time taken for hookshot to fetch all feeds", labelNames: [], registers: [this.registry]}); - public readonly feedsFailing = new Gauge({ name: "feed_failing", help: "The number of RSS feeds that hookshot is failing to read", labelNames: ["reason"], registers: [this.registry]}); + public readonly feedsCount = new Gauge({ name: "hookshot_feeds_count", help: "The number of RSS feeds that hookshot is subscribed to", labelNames: [], registers: [this.registry]}); + public readonly feedFetchMs = new Gauge({ name: "hookshot_feeds_fetch_ms", help: "The time taken for hookshot to fetch all feeds", labelNames: [], registers: [this.registry]}); + public readonly feedsFailing = new Gauge({ name: "hookshot_feeds_failing", help: "The number of RSS feeds that hookshot is failing to read", labelNames: ["reason"], registers: [this.registry]}); + public readonly feedsCountDeprecated = new Gauge({ name: "feed_count", help: "(Deprecated) The number of RSS feeds that hookshot is subscribed to", labelNames: [], registers: [this.registry]}); + public readonly feedsFetchMsDeprecated = new Gauge({ name: "feed_fetch_ms", help: "(Deprecated) The time taken for hookshot to fetch all feeds", labelNames: [], registers: [this.registry]}); + public readonly feedsFailingDeprecated = new Gauge({ name: "feed_failing", help: "(Deprecated) The number of RSS feeds that hookshot is failing to read", labelNames: ["reason"], registers: [this.registry]}); constructor(private registry: Registry = register) { this.expressRouter.get('/metrics', this.metricsFunc.bind(this)); collectDefaultMetrics({ - register: this.registry + register: this.registry, }) } diff --git a/src/feeds/FeedReader.ts b/src/feeds/FeedReader.ts index ad620692..31a07aeb 100644 --- a/src/feeds/FeedReader.ts +++ b/src/feeds/FeedReader.ts @@ -170,7 +170,7 @@ export class FeedReader { private seenEntries: Map = new Map(); // A set of last modified times for each url. private cacheTimes: Map = new Map(); - + // Reason failures to url map. private feedsFailingHttp = new Set(); private feedsFailingParsing = new Set(); @@ -232,6 +232,7 @@ export class FeedReader { this.feedQueue = shuffle([...this.observedFeedUrls.values()]); Metrics.feedsCount.set(this.observedFeedUrls.size); + Metrics.feedsCountDeprecated.set(this.observedFeedUrls.size); } private async loadSeenEntries(): Promise { @@ -268,7 +269,7 @@ export class FeedReader { * Poll a given feed URL for data, pushing any entries found into the message queue. * We also check the `cacheTimes` cache to see if the feed has recent entries that we can * filter out. - * + * * @param url The URL to be polled. * @returns A boolean that returns if we saw any changes on the feed since the last poll time. */ @@ -288,7 +289,7 @@ export class FeedReader { this.config.pollTimeoutSeconds * 1000, this.parser, ); - + // Store any entity tags/cache times. if (response.headers.ETag) { this.cacheTimes.set(url, { etag: response.headers.ETag}); @@ -354,7 +355,7 @@ export class FeedReader { // Some RSS feeds can return a very small number of items then bounce // back to their "normal" size, so we cannot just clobber the recent GUID list per request or else we'll // forget what we sent and resend it. Instead, we'll keep 2x the max number of items that we've ever - // seen from this feed, up to a max of 10,000. + // seen from this feed, up to a max of 10,000. // Adopted from https://github.com/matrix-org/go-neb/blob/babb74fa729882d7265ff507b09080e732d060ae/services/rssbot/rssbot.go#L304 const maxGuids = Math.min(Math.max(2 * newGuids.length, seenGuids.length), 10_000); const newSeenItems = Array.from(new Set([ ...newGuids, ...seenGuids ]).values()).slice(0, maxGuids); @@ -399,9 +400,12 @@ export class FeedReader { Metrics.feedsFailing.set({ reason: "http" }, this.feedsFailingHttp.size ); Metrics.feedsFailing.set({ reason: "parsing" }, this.feedsFailingParsing.size); + Metrics.feedsFailingDeprecated.set({ reason: "http" }, this.feedsFailingHttp.size ); + Metrics.feedsFailingDeprecated.set({ reason: "parsing" }, this.feedsFailingParsing.size); const elapsed = Date.now() - fetchingStarted; Metrics.feedFetchMs.set(elapsed); + Metrics.feedsFetchMsDeprecated.set(elapsed); const sleepFor = Math.max(this.sleepingInterval - elapsed, 0); log.debug(`Feed fetching took ${elapsed / 1000}s, sleeping for ${sleepFor / 1000}s`);