Add hookshot_ prefix on hookshot specific metrics (#701)

* Add hookshot_ prefix on all metrics

* Only add prefix to hookshot specific metrics

* Add old metric names as deprecated

* Fix feeds metrics names

* Update metrics docs

---------

Co-authored-by: Will Hunt <will@half-shot.uk>
This commit is contained in:
Justin Carlson 2023-04-11 12:58:51 -04:00 committed by GitHub
parent 6345ad2347
commit cafe05b0a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 13 deletions

1
changelog.d/701.misc Normal file
View File

@ -0,0 +1 @@
Ensure all Hookshot specific metrics have a `hookshot_` prefix.

View File

@ -1369,7 +1369,7 @@
}, },
"editorMode": "builder", "editorMode": "builder",
"exemplar": false, "exemplar": false,
"expr": "feed_count", "expr": "hookshot_feeds_count",
"instant": false, "instant": false,
"legendFormat": "{{__name__}}", "legendFormat": "{{__name__}}",
"range": true, "range": true,
@ -1462,7 +1462,7 @@
"uid": "${datasource}" "uid": "${datasource}"
}, },
"editorMode": "builder", "editorMode": "builder",
"expr": "feed_fetch_ms", "expr": "hookshot_feeds_fetch_ms",
"legendFormat": "{{__name__}}", "legendFormat": "{{__name__}}",
"range": true, "range": true,
"refId": "A" "refId": "A"

View File

@ -31,6 +31,9 @@ Below is the generated list of Prometheus metrics for Hookshot.
| hookshot_notifications_push | Number of notifications pushed | service | | hookshot_notifications_push | Number of notifications pushed | service |
| hookshot_notifications_service_up | Is the notification service up or down | service | | hookshot_notifications_service_up | Is the notification service up or down | service |
| hookshot_notifications_watchers | Number of notifications watchers running | 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 ## matrix
| Metric | Help | Labels | | Metric | Help | Labels |
|--------|------|--------| |--------|------|--------|
@ -41,9 +44,9 @@ Below is the generated list of Prometheus metrics for Hookshot.
## feed ## feed
| Metric | Help | Labels | | Metric | Help | Labels |
|--------|------|--------| |--------|------|--------|
| feed_count | The number of RSS feeds that hookshot is subscribed to | | | feed_count | (Deprecated) The number of RSS feeds that hookshot is subscribed to | |
| feed_fetch_ms | The time taken for hookshot to fetch all feeds | | | feed_fetch_ms | (Deprecated) The time taken for hookshot to fetch all feeds | |
| feed_failing | The number of RSS feeds that hookshot is failing to read | reason | | feed_failing | (Deprecated) The number of RSS feeds that hookshot is failing to read | reason |
## process ## process
| Metric | Help | Labels | | Metric | Help | Labels |
|--------|------|--------| |--------|------|--------|

View File

@ -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 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 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 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: "feed_fetch_ms", help: "The time taken for hookshot to fetch all feeds", 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: "feed_failing", help: "The number of RSS feeds that hookshot is failing to read", labelNames: ["reason"], 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) { constructor(private registry: Registry = register) {
this.expressRouter.get('/metrics', this.metricsFunc.bind(this)); this.expressRouter.get('/metrics', this.metricsFunc.bind(this));
collectDefaultMetrics({ collectDefaultMetrics({
register: this.registry register: this.registry,
}) })
} }

View File

@ -170,7 +170,7 @@ export class FeedReader {
private seenEntries: Map<string, string[]> = new Map(); private seenEntries: Map<string, string[]> = new Map();
// A set of last modified times for each url. // A set of last modified times for each url.
private cacheTimes: Map<string, { etag?: string, lastModified?: string}> = new Map(); private cacheTimes: Map<string, { etag?: string, lastModified?: string}> = new Map();
// Reason failures to url map. // Reason failures to url map.
private feedsFailingHttp = new Set(); private feedsFailingHttp = new Set();
private feedsFailingParsing = new Set(); private feedsFailingParsing = new Set();
@ -232,6 +232,7 @@ export class FeedReader {
this.feedQueue = shuffle([...this.observedFeedUrls.values()]); this.feedQueue = shuffle([...this.observedFeedUrls.values()]);
Metrics.feedsCount.set(this.observedFeedUrls.size); Metrics.feedsCount.set(this.observedFeedUrls.size);
Metrics.feedsCountDeprecated.set(this.observedFeedUrls.size);
} }
private async loadSeenEntries(): Promise<void> { private async loadSeenEntries(): Promise<void> {
@ -268,7 +269,7 @@ export class FeedReader {
* Poll a given feed URL for data, pushing any entries found into the message queue. * 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 * We also check the `cacheTimes` cache to see if the feed has recent entries that we can
* filter out. * filter out.
* *
* @param url The URL to be polled. * @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. * @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.config.pollTimeoutSeconds * 1000,
this.parser, this.parser,
); );
// Store any entity tags/cache times. // Store any entity tags/cache times.
if (response.headers.ETag) { if (response.headers.ETag) {
this.cacheTimes.set(url, { etag: 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 // 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 // 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 // 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 // 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 maxGuids = Math.min(Math.max(2 * newGuids.length, seenGuids.length), 10_000);
const newSeenItems = Array.from(new Set([ ...newGuids, ...seenGuids ]).values()).slice(0, maxGuids); 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: "http" }, this.feedsFailingHttp.size );
Metrics.feedsFailing.set({ reason: "parsing" }, this.feedsFailingParsing.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; const elapsed = Date.now() - fetchingStarted;
Metrics.feedFetchMs.set(elapsed); Metrics.feedFetchMs.set(elapsed);
Metrics.feedsFetchMsDeprecated.set(elapsed);
const sleepFor = Math.max(this.sleepingInterval - elapsed, 0); const sleepFor = Math.max(this.sleepingInterval - elapsed, 0);
log.debug(`Feed fetching took ${elapsed / 1000}s, sleeping for ${sleepFor / 1000}s`); log.debug(`Feed fetching took ${elapsed / 1000}s, sleeping for ${sleepFor / 1000}s`);