-
-
Notifications
You must be signed in to change notification settings - Fork 400
feat(#11071): add replication failure user count to monitoring v2 #11072
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
2bfc5a6
da28f09
5ae9c3f
ecaca3b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,8 +5,10 @@ const pagination = require('../pagination'); | |
| const TYPE_PREFIX = `replication-fail-`; | ||
| const MAX_FAILURES = 50; | ||
| const REPORTING_PERIOD_FORMAT = 'YYYY-MM'; | ||
| const REPORTING_PERIOD_LENGTH = REPORTING_PERIOD_FORMAT.length; | ||
| const UNKNOWN = 'unknown'; | ||
| const MAX_PERIODS = 60; | ||
| const RECENT_PERIODS_FOR_USER_COUNT = 2; | ||
|
|
||
| const captureFailure = async (userCtx, requestId, statusCode, duration) => { | ||
| const log = await getLog(userCtx.name); | ||
|
|
@@ -151,7 +153,26 @@ const get = async ({ user, reportingPeriod, cursor = 0, limit = pagination.DEFAU | |
| return getPageByRange({ reportingPeriod, skip: cursor, limit }); | ||
| }; | ||
|
|
||
| const getRecentReportingPeriodsRange = () => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Returning the current + previous period's data is pretty confusing to the consumer. 😓 I think I understand why you did it (it is better than just returning the current OR the previous period's data), but still.... I would like this much better if we could just a rolling sum from the last 30 days. (That kind of value will be WAY easier to track/measure in Watchdog) However, I think doing that efficiently would require a view (like we have for
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea, I really don't want to add views right now :D Do you think current and past calendaristic month is a hard concept to grasp for the consumer?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I see your concern, which is why I am taking the last two reporting periods when returning results. |
||
| const now = moment(); | ||
| const earliest = now.clone().subtract(RECENT_PERIODS_FOR_USER_COUNT - 1, 'month').format(REPORTING_PERIOD_FORMAT); | ||
| const latest = now.format(REPORTING_PERIOD_FORMAT); | ||
| return { | ||
| startkey: `${TYPE_PREFIX}${earliest}-`, | ||
| endkey: `${TYPE_PREFIX}${latest}-\ufff0`, | ||
| }; | ||
| }; | ||
|
|
||
| const usernameFromDocId = (docId) => docId.slice(TYPE_PREFIX.length + REPORTING_PERIOD_LENGTH); | ||
|
|
||
| const getUsersWithFailuresCount = async () => { | ||
| const result = await db.medicLogs.allDocs(getRecentReportingPeriodsRange()); | ||
| const users = new Set(result.rows.map(row => usernameFromDocId(row.id))); | ||
| return users.size; | ||
| }; | ||
|
|
||
| module.exports = { | ||
| capture: captureFailure, | ||
| get, | ||
| getUsersWithFailuresCount, | ||
| }; | ||
Uh oh!
There was an error while loading. Please reload this page.