From a4b7323c97c7f977a2aa4977d628b825235775c2 Mon Sep 17 00:00:00 2001 From: Andrew Dunkman Date: Wed, 1 Sep 2021 20:41:54 -0400 Subject: [PATCH] Disable agent via configuration --- .env.example | 1 + .gitignore | 1 + bot/actions/closeMessage.ts | 4 ++-- bot/actions/menuClick.ts | 4 ++-- bot/actions/message.ts | 6 +++--- bot/actions/messageEdited.ts | 4 ++-- bot/app.ts | 8 ++++---- docker-compose.yml | 1 + 8 files changed, 16 insertions(+), 13 deletions(-) diff --git a/.env.example b/.env.example index 8475e47..cb02246 100644 --- a/.env.example +++ b/.env.example @@ -9,6 +9,7 @@ # NEW_RELIC_LICENSE_KEY=c1C2c1C2c1C2c1C2c1C2c1C2c1C2c1C2c1C2c1C2 # NEW_RELIC_APP_NAME=inclusion-bot-prod # NEW_RELIC_DISTRIBUTED_TRACING_ENABLED=true +# NEW_RELIC_ENABLED=true # SLACK_SIGNING_SECRET=a1A2a1A2a1A2a1A2a1A2a1A2a1A2a1A2 SLACK_CLIENT_ID=1111111111111.2222222222222 diff --git a/.gitignore b/.gitignore index ddbf2b5..b600ea3 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ .vscode coverage node_modules +newrelic_agent.log diff --git a/bot/actions/closeMessage.ts b/bot/actions/closeMessage.ts index 1c19174..df1343b 100644 --- a/bot/actions/closeMessage.ts +++ b/bot/actions/closeMessage.ts @@ -1,4 +1,4 @@ -import newrelic from "newrelic"; +import { incrementMetric } from "newrelic"; import { AllMiddlewareArgs, BlockAction, ButtonAction, SlackActionMiddlewareArgs } from "@slack/bolt"; export const CLOSE_MESSAGE_ACTION_ID = "close_ephemeral_message"; @@ -7,7 +7,7 @@ export async function handleMessageClose(event: SlackActionMiddlewareArgs & if (matches.length === 0) { // This message contains only ignored items. - newrelic.incrementMetric("Actions/message/ignoredTerm"); + incrementMetric("Actions/message/ignoredTerm"); return; } @@ -36,7 +36,7 @@ export async function handleMessage(event: SlackEventMiddlewareArgs<'message'> & const random = Math.floor(Math.random() * trigger.alternatives.length); const alternative = trigger.alternatives[random]; const why = (trigger.why || '').replace(/:TERM:/gi, capitalize(text)); - newrelic.incrementMetric(`Actions/message/term/${text.toLowerCase()}`); + incrementMetric(`Actions/message/term/${text.toLowerCase()}`); return `Instead of saying “${text.toLowerCase()},” how about *${alternative}*? You may be able to edit your message. ${why}`; }); diff --git a/bot/actions/messageEdited.ts b/bot/actions/messageEdited.ts index fffb8b2..0471234 100644 --- a/bot/actions/messageEdited.ts +++ b/bot/actions/messageEdited.ts @@ -1,4 +1,4 @@ -import newrelic from "newrelic"; +import { incrementMetric } from "newrelic"; import { AllMiddlewareArgs, GenericMessageEvent, MessageChangedEvent, SlackEventMiddlewareArgs } from "@slack/bolt"; import { config } from "../triggers/triggers"; @@ -43,7 +43,7 @@ export async function handleMessageEdited(event: SlackEventMiddlewareArgs<'messa if (!message.text.match(config.allTriggersRegExp)) { // The user has adjusted their language and it no longer matches our // triggers. - newrelic.incrementMetric("Actions/messageEdited/termRemoved"); + incrementMetric("Actions/messageEdited/termRemoved"); await event.client.reactions.remove({ name: config.emoji, channel: messageChanged.channel, diff --git a/bot/app.ts b/bot/app.ts index c2a50cf..511b8a1 100644 --- a/bot/app.ts +++ b/bot/app.ts @@ -1,4 +1,4 @@ -import newrelic from "newrelic"; +import { incrementMetric } from "newrelic"; import { App, ExpressReceiver, Installation as InstallationType, LogLevel, subtype } from "@slack/bolt"; import { Sequelize } from "sequelize"; import { InstallationFactory } from "./models/installation"; @@ -38,7 +38,7 @@ const receiver = new ExpressReceiver({ logLevel: LogLevel.INFO, installationStore: { storeInstallation: async (installation) => { - newrelic.incrementMetric("InstallationStore/storeInstallation"); + incrementMetric("InstallationStore/storeInstallation"); await Installation.create({ id: installation.isEnterpriseInstall @@ -49,7 +49,7 @@ const receiver = new ExpressReceiver({ }); }, fetchInstallation: async (query) => { - newrelic.incrementMetric("InstallationStore/fetchInstallation"); + incrementMetric("InstallationStore/fetchInstallation"); const installation = await Installation.findByPk( query.isEnterpriseInstall ? query.enterpriseId : query.teamId @@ -58,7 +58,7 @@ const receiver = new ExpressReceiver({ return installation.installationObject as InstallationType; }, deleteInstallation: async (query) => { - newrelic.incrementMetric("InstallationStore/deleteInstallation"); + incrementMetric("InstallationStore/deleteInstallation"); const installation = await Installation.findByPk( query.isEnterpriseInstall ? query.enterpriseId : query.teamId diff --git a/docker-compose.yml b/docker-compose.yml index e03f23c..75d8d82 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,6 +14,7 @@ services: SLACK_CLIENT_SECRET: $SLACK_CLIENT_SECRET APP_STATE_SECRET: $APP_STATE_SECRET DATABASE_URL: postgres://postgres:${LOCAL_POSTGRES_PASSWORD}@db:5432/postgres + NEW_RELIC_ENABLED: "false" adminer: image: adminer:4.8.1-standalone