Skip to content

Add incidents error messages #1

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 53 additions & 8 deletions src/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,60 @@ new client.Gauge({
if (!zdb) await initDBReader(runtimeDir)

columnFamiliesNames.map(async (columnFamilyName) => {
let count: number|undefined;
await walkColumnFamily(zdb!, columnFamilyName, function() {
!count ? count = 1 : count++;
})
if (count) {
this.set(
{db_name: 'runtime', column_family: columnFamilyName}, count
);
if (columnFamilyName !== 'INCIDENTS') { // exclude INCIDENT, as there is a specific gauge for it
let count: number | undefined;
await walkColumnFamily(zdb!, columnFamilyName, function () {
!count ? count = 1 : count++;
})
if (count) {
this.set(
{db_name: 'runtime', column_family: columnFamilyName}, count
);
}
}
})
}
})

new client.Gauge({
name: `zeebe_db_column_family_incident_entries`,
help: `Number of incidents per errorMessage inside the db`,
labelNames: ['db_name', 'error_message'],
async collect() {
// Set the mesure on all the column family
if (!zdb) await initDBReader(runtimeDir)

const incidentMessages: string[] = []

await walkColumnFamily(zdb!, 'INCIDENTS', function(key, value) {
incidentMessages.push(value)
})

const incidentCountPerMessage = new Map<string, number>()

// group by errorMessage and set the mesure
incidentMessages.forEach((value: object|string) => {
value = String(value) // set to string, for whatever we have

let start = value.indexOf('errorMessage');
if (start === -1) return
start += 'errorMessage'.length

// totally arbitral value
start += 2
const end = start + 35
const cleanedErrorMessage = value?.substring(start, end)

// add to Map
if (!incidentCountPerMessage.has(cleanedErrorMessage)) incidentCountPerMessage.set(cleanedErrorMessage, 0)
incidentCountPerMessage.set(cleanedErrorMessage, incidentCountPerMessage.get(cleanedErrorMessage)! +1)
})

//set the measure
incidentCountPerMessage.forEach((count, message) => {
this.set(
{db_name: 'runtime', error_message: message}, count
);
})
}
})