From 0ed25d576cc19dc9368999a8a9ec170d3b7fb62a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6ran=20Sander?= Date: Wed, 11 Sep 2024 19:43:48 +0000 Subject: [PATCH] fix(config)!: Make naming of InfluxDB tags consistent across entire config file Fixes #890 --- src/config/production_template.yaml | 16 ++++++------- src/globals.js | 2 +- src/lib/config-file-schema.js | 8 +++---- src/lib/config-file-verify.js | 4 ---- src/lib/post-to-influxdb.js | 20 ++++++++-------- src/lib/post-to-mqtt.js | 4 ++-- src/lib/post-to-new-relic.js | 37 +++++++---------------------- 7 files changed, 33 insertions(+), 58 deletions(-) diff --git a/src/config/production_template.yaml b/src/config/production_template.yaml index b56a5f36..7538bbca 100644 --- a/src/config/production_template.yaml +++ b/src/config/production_template.yaml @@ -89,9 +89,9 @@ Butler-SOS: influxdb: measurementName: event_count # Name of the InfluxDB measurement where event count is stored tags: # Tags are added to the data before it's stored in InfluxDB - # - tag: env + # - name: env # value: DEV - # - tag: foo + # - name: foo # value: bar rejectedEventCount: enable: true # Should rejected events be counted and stored in InfluxDB? @@ -111,9 +111,9 @@ Butler-SOS: serverHost: # Host/IP where user event server will listen for events from Sense portUserActivityEvents: 9997 # Port on which user event server will listen for events from Sense tags: # Tags are added to the data before it's stored in InfluxDB - # - tag: env + # - name: env # value: DEV - # - tag: foo + # - name: foo # value: bar sendToMQTT: enable: false # Set to true if user events should be forwarded as MQTT messages @@ -148,9 +148,9 @@ Butler-SOS: serverHost: # Host/IP where log event server will listen for events from Sense portLogEvents: 9996 # Port on which log event server will listen for events from Sense tags: - # - tag: env + # - name: env # value: DEV - # - tag: foo + # - name: foo # value: bar source: engine: @@ -233,9 +233,9 @@ Butler-SOS: trackRejectedEvents: enable: false # Should events that are rejected by the app performance monitor be tracked? tags: # Tags are added to the data before it's stored in InfluxDB - # - tag: env + # - name: env # value: DEV - # - tag: foo + # - name: foo # value: bar monitorFilter: # What objects should be monitored? Entire apps or just specific object(s) within some specific app(s)? # Two kinds of monitoring can be done: diff --git a/src/globals.js b/src/globals.js index a73238d2..f6a4ed80 100755 --- a/src/globals.js +++ b/src/globals.js @@ -422,7 +422,7 @@ class Settings { )}` ); - tagValuesLogEvent.push(entry.tag); + tagValuesLogEvent.push(entry.name); }); } diff --git a/src/lib/config-file-schema.js b/src/lib/config-file-schema.js index 74616fbc..3cdeeb5d 100755 --- a/src/lib/config-file-schema.js +++ b/src/lib/config-file-schema.js @@ -77,7 +77,7 @@ export const confifgFileSchema = { measurementName: 'string', 'tags?': [ { - tag: 'string', + name: 'string', value: 'string', }, ], @@ -105,7 +105,7 @@ export const confifgFileSchema = { }, 'tags?': [ { - tag: 'string', + name: 'string', value: 'string', }, ], @@ -150,7 +150,7 @@ export const confifgFileSchema = { }, 'tags?': [ { - tag: 'string', + name: 'string', value: 'string', }, ], @@ -208,7 +208,7 @@ export const confifgFileSchema = { enable: 'boolean', 'tags?': [ { - tag: 'string', + name: 'string', value: 'string', }, ], diff --git a/src/lib/config-file-verify.js b/src/lib/config-file-verify.js index e9fea22b..14005976 100755 --- a/src/lib/config-file-verify.js +++ b/src/lib/config-file-verify.js @@ -68,11 +68,9 @@ export async function verifyConfigFile() { const serverTagsDefinition = globals.config.get( 'Butler-SOS.serversToMonitor.serverTagsDefinition' ); - // eslint-disable-next-line no-restricted-syntax for (const tag of serverTagsDefinition) { // Check that all servers have this tag const servers = globals.config.get('Butler-SOS.serversToMonitor.servers'); - // eslint-disable-next-line no-restricted-syntax for (const server of servers) { // Check if server.serverTags.tag is defined if (server?.serverTags === null || !server?.serverTags[tag]) { @@ -90,9 +88,7 @@ export async function verifyConfigFile() { // Now ensure that the tags defined for each server are valid and that there are no extra tags there const servers = globals.config.get('Butler-SOS.serversToMonitor.servers'); - // eslint-disable-next-line no-restricted-syntax for (const server of servers) { - // eslint-disable-next-line no-restricted-syntax for (const tag in server.serverTags) { if (!serverTagsDefinition.includes(tag)) { globals.logger.error( diff --git a/src/lib/post-to-influxdb.js b/src/lib/post-to-influxdb.js index a88a3c77..3dd63bc4 100755 --- a/src/lib/post-to-influxdb.js +++ b/src/lib/post-to-influxdb.js @@ -712,7 +712,7 @@ export async function postUserEventToInfluxdb(msg) { ) { const configTags = globals.config.get('Butler-SOS.userEvents.tags'); for (const item of configTags) { - tags[item.tag] = item.value; + tags[item.name] = item.value; } } @@ -824,7 +824,7 @@ export async function postUserEventToInfluxdb(msg) { ) { const configTags = globals.config.get('Butler-SOS.userEvents.tags'); for (const item of configTags) { - point.tag(item.tag, item.value); + point.tag(item.name, item.value); } } @@ -1043,7 +1043,7 @@ export async function postLogEventToInfluxdb(msg) { ) { const configTags = globals.config.get('Butler-SOS.logEvents.tags'); for (const item of configTags) { - tags[item.tag] = item.value; + tags[item.name] = item.value; } } @@ -1280,7 +1280,7 @@ export async function postLogEventToInfluxdb(msg) { ) { const configTags = globals.config.get('Butler-SOS.logEvents.tags'); for (const item of configTags) { - point.tag(item.tag, item.value); + point.tag(item.name, item.value); } } @@ -1357,7 +1357,7 @@ export async function storeEventCountInfluxDB() { 'Butler-SOS.qlikSenseEvents.eventCount.influxdb.tags' ); for (const item of configTags) { - point.tags[item.tag] = item.value; + point.tags[item.name] = item.value; } } @@ -1391,7 +1391,7 @@ export async function storeEventCountInfluxDB() { 'Butler-SOS.qlikSenseEvents.eventCount.influxdb.tags' ); for (const item of configTags) { - point.tags[item.tag] = item.value; + point.tags[item.name] = item.value; } } @@ -1468,7 +1468,7 @@ export async function storeEventCountInfluxDB() { 'Butler-SOS.qlikSenseEvents.eventCount.influxdb.tags' ); for (const item of configTags) { - point.tag(item.tag, item.value); + point.tag(item.name, item.value); } } @@ -1497,7 +1497,7 @@ export async function storeEventCountInfluxDB() { 'Butler-SOS.qlikSenseEvents.eventCount.influxdb.tags' ); for (const item of configTags) { - point.tag(item.tag, item.value); + point.tag(item.name, item.value); } } @@ -1578,7 +1578,7 @@ export async function storeRejectedEventCountInfluxDB() { 'Butler-SOS.logEvents.enginePerformanceMonitor.trackRejectedEvents.tags' ); for (const item of configTags) { - tags[item.tag] = item.value; + tags[item.name] = item.value; } } @@ -1699,7 +1699,7 @@ export async function storeRejectedEventCountInfluxDB() { 'Butler-SOS.logEvents.enginePerformanceMonitor.trackRejectedEvents.tags' ); for (const item of configTags) { - point.tag(item.tag, item.value); + point.tag(item.name, item.value); } } diff --git a/src/lib/post-to-mqtt.js b/src/lib/post-to-mqtt.js index fa7bfe09..f8739b53 100755 --- a/src/lib/post-to-mqtt.js +++ b/src/lib/post-to-mqtt.js @@ -135,7 +135,7 @@ export function postUserEventToMQTT(msg) { const configTags = globals.config.get('Butler-SOS.userEvents.tags'); // eslint-disable-next-line no-restricted-syntax for (const item of configTags) { - payload.tags[item.tag] = item.value; + payload.tags[item.name] = item.value; } } @@ -221,7 +221,7 @@ export function postLogEventToMQTT(msg) { const configTags = globals.config.get('Butler-SOS.logEvents.tags'); // eslint-disable-next-line no-restricted-syntax for (const item of configTags) { - payload.tags[item.tag] = item.value; + payload.tags[item.name] = item.value; } } diff --git a/src/lib/post-to-new-relic.js b/src/lib/post-to-new-relic.js index 6074e283..e24e95d7 100755 --- a/src/lib/post-to-new-relic.js +++ b/src/lib/post-to-new-relic.js @@ -1,6 +1,3 @@ -/* eslint-disable prefer-destructuring */ -/* eslint-disable no-unused-vars */ - import crypto from 'crypto'; import axios from 'axios'; @@ -86,7 +83,6 @@ export async function postHealthMetricsToNewRelic(_host, body, tags) { 'Butler-SOS.newRelic.metric.attribute.static' ); - // eslint-disable-next-line no-restricted-syntax for (const item of staticAttributes) { attributes[item.name] = item.value; } @@ -281,7 +277,6 @@ export async function postHealthMetricsToNewRelic(_host, body, tags) { globals.config.get('Butler-SOS.newRelic.metric.header').length > 0 ) { const configHeaders = globals.config.get('Butler-SOS.newRelic.metric.header'); - // eslint-disable-next-line no-restricted-syntax for (const header of configHeaders) { headers[header.name] = header.value; } @@ -300,7 +295,6 @@ export async function postHealthMetricsToNewRelic(_host, body, tags) { `HEALTH METRICS NEW RELIC: Complete New Relic config=${JSON.stringify(nrAccounts)}` ); - // eslint-disable-next-line no-restricted-syntax for (const accountName of globals.config.get( 'Butler-SOS.userEvents.sendToNewRelic.destinationAccount' )) { @@ -323,7 +317,6 @@ export async function postHealthMetricsToNewRelic(_host, body, tags) { } else { headers['Api-Key'] = newRelicConfig[0].insertApiKey; - // eslint-disable-next-line no-await-in-loop const res = await axios.post(remoteUrl, payload, { headers, timeout: 10000 }); globals.logger.debug( @@ -373,7 +366,6 @@ export async function postProxySessionsToNewRelic(userSessions) { 'Butler-SOS.newRelic.metric.attribute.static' ); - // eslint-disable-next-line no-restricted-syntax for (const item of staticAttributes) { attributes[item.name] = item.value; } @@ -432,7 +424,6 @@ export async function postProxySessionsToNewRelic(userSessions) { globals.config.get('Butler-SOS.newRelic.metric.header').length > 0 ) { const configHeaders = globals.config.get('Butler-SOS.newRelic.metric.header'); - // eslint-disable-next-line no-restricted-syntax for (const header of configHeaders) { headers[header.name] = header.value; } @@ -450,7 +441,6 @@ export async function postProxySessionsToNewRelic(userSessions) { `PROXY SESSIONS NEW RELIC: Complete New Relic config=${JSON.stringify(nrAccounts)}` ); - // eslint-disable-next-line no-restricted-syntax for (const accountName of globals.config.get( 'Butler-SOS.userEvents.sendToNewRelic.destinationAccount' )) { @@ -477,7 +467,6 @@ export async function postProxySessionsToNewRelic(userSessions) { `PROXY SESSIONS NEW RELIC: Proxy session count for server "${userSessions.host}", virtual proxy "${userSessions.virtualProxy}": ${userSessions.sessionCount}` ); - // eslint-disable-next-line no-await-in-loop const res = await axios.post(remoteUrl, payload, { headers, timeout: 5000 }); globals.logger.debug( @@ -513,13 +502,15 @@ export async function postButlerSOSUptimeToNewRelic(fields) { const ts = new Date().getTime(); // Timestamp in millisec // Add static fields to attributes if they exist - if (globals.config.has('Butler-SOS.uptimeMonitor.storeNewRelic.attribute.static') && globals.config.get('Butler-SOS.uptimeMonitor.storeNewRelic.attribute.static') !== null) { + if ( + globals.config.has('Butler-SOS.uptimeMonitor.storeNewRelic.attribute.static') && + globals.config.get('Butler-SOS.uptimeMonitor.storeNewRelic.attribute.static') !== null + ) { const staticAttributes = globals.config.get( 'Butler-SOS.uptimeMonitor.storeNewRelic.attribute.static' ); - // staticAttributes is an array of objects. Null - // eslint-disable-next-line no-restricted-syntax + // staticAttributes is an array of objects. Null for (const item of staticAttributes) { attributes[item.name] = item.value; } @@ -600,7 +591,6 @@ export async function postButlerSOSUptimeToNewRelic(fields) { 'Content-Type': 'application/json', }; - // eslint-disable-next-line no-restricted-syntax for (const header of globals.config.get('Butler-SOS.newRelic.metric.header')) { headers[header.name] = header.value; } @@ -617,7 +607,6 @@ export async function postButlerSOSUptimeToNewRelic(fields) { `UPTIME NEW RELIC: Complete New Relic config=${JSON.stringify(nrAccounts)}` ); - // eslint-disable-next-line no-restricted-syntax for (const accountName of globals.config.get( 'Butler-SOS.uptimeMonitor.storeNewRelic.destinationAccount' )) { @@ -638,7 +627,6 @@ export async function postButlerSOSUptimeToNewRelic(fields) { } else { headers['Api-Key'] = newRelicConfig[0].insertApiKey; - // eslint-disable-next-line no-await-in-loop const res = await axios.post(remoteUrl, payload, { headers, timeout: 5000 }); globals.logger.debug( @@ -719,9 +707,8 @@ export async function postUserEventToNewRelic(msg) { globals.config.get('Butler-SOS.userEvents.tags').length > 0 ) { const configTags = globals.config.get('Butler-SOS.userEvents.tags'); - // eslint-disable-next-line no-restricted-syntax for (const item of configTags) { - attributes[item.tag] = item.value; + attributes[item.name] = item.value; } } @@ -748,7 +735,6 @@ export async function postUserEventToNewRelic(msg) { globals.config.get('Butler-SOS.newRelic.event.header').length > 0 ) { const configHeaders = globals.config.get('Butler-SOS.newRelic.event.header'); - // eslint-disable-next-line no-restricted-syntax for (const header of configHeaders) { headers[header.name] = header.value; } @@ -766,7 +752,6 @@ export async function postUserEventToNewRelic(msg) { `USER EVENT NEW RELIC: Complete New Relic config=${JSON.stringify(nrAccounts)}` ); - // eslint-disable-next-line no-restricted-syntax for (const accountName of globals.config.get( 'Butler-SOS.userEvents.sendToNewRelic.destinationAccount' )) { @@ -792,7 +777,6 @@ export async function postUserEventToNewRelic(msg) { // Add API key for this NR account as http header headers['Api-Key'] = newRelicConfig[0].insertApiKey; - // eslint-disable-next-line no-await-in-loop const res = await axios.post(eventUrl, payload, { headers, timeout: 10000 }); globals.logger.debug( @@ -974,9 +958,8 @@ export async function postLogEventToNewRelic(msg) { globals.config.get('Butler-SOS.logEvents.tags').length > 0 ) { const configTags = globals.config.get('Butler-SOS.logEvents.tags'); - // eslint-disable-next-line no-restricted-syntax for (const item of configTags) { - attributes[item.tag] = item.value; + attributes[item.name] = item.value; } } @@ -987,7 +970,6 @@ export async function postLogEventToNewRelic(msg) { globals.config.get('Butler-SOS.newRelic.event.attribute.static').length > 0 ) { const configTags = globals.config.get('Butler-SOS.newRelic.event.attribute.static'); - // eslint-disable-next-line no-restricted-syntax for (const item of configTags) { attributes[item.name] = item.value; } @@ -1030,7 +1012,6 @@ export async function postLogEventToNewRelic(msg) { globals.config.get('Butler-SOS.newRelic.event.header').length > 0 ) { const configHeaders = globals.config.get('Butler-SOS.newRelic.event.header'); - // eslint-disable-next-line no-restricted-syntax for (const header of configHeaders) { headers[header.name] = header.value; } @@ -1043,12 +1024,11 @@ export async function postLogEventToNewRelic(msg) { let nrAccounts = globals.config.get('Butler-SOS.thirdPartyToolsCredentials.newRelic'); if (nrAccounts === null) { nrAccounts = []; - } + } globals.logger.debug( `LOG EVENT NEW RELIC: Complete New Relic config=${JSON.stringify(nrAccounts)}` ); - // eslint-disable-next-line no-restricted-syntax for (const accountName of globals.config.get( 'Butler-SOS.logEvents.sendToNewRelic.destinationAccount' )) { @@ -1078,7 +1058,6 @@ export async function postLogEventToNewRelic(msg) { // Add API key for this NR account as http header headers['Api-Key'] = newRelicConfig[0].insertApiKey; - // eslint-disable-next-line no-await-in-loop const res = await axios.post(eventUrl, payload, { headers, timeout: 10000 }); globals.logger.debug(