From 3f64c25c104ca227359c32b5e5d14e27ed9341b8 Mon Sep 17 00:00:00 2001 From: rozetko Date: Wed, 6 Nov 2019 22:30:54 +0300 Subject: [PATCH] Production hotfixes (#803) * fix compose variables * fix server/Dockerfile * fix notification message * HASTIC_TIMEZONE_OFFSET --- docker-compose-mongo.yml | 6 ++++-- docker-compose.yml | 6 ++++-- server/Dockerfile | 6 +----- server/src/config.ts | 4 ++-- server/src/services/notification_service.ts | 11 ++++++----- server/src/utils/time.ts | 6 +++--- 6 files changed, 20 insertions(+), 19 deletions(-) diff --git a/docker-compose-mongo.yml b/docker-compose-mongo.yml index 79a649f..fb10283 100644 --- a/docker-compose-mongo.yml +++ b/docker-compose-mongo.yml @@ -13,11 +13,13 @@ services: HASTIC_DB_CONNECTION_STRING: ${HASTIC_MONGO_USER:-hastic}:${HASTIC_MONGO_PASSWORD:-password}@mongo:27017/${HASTIC_MONGO_DB:-hastic} ZMQ_CONNECTION_STRING: ${ZMQ_CONNECTION_STRING:-tcp://analytics:8002} + HASTIC_ALERT_TYPE: ${HASTIC_ALERT_TYPE} + HASTIC_ALERTMANAGER_URL: ${HASTIC_ALERTMANAGER_URL} HASTIC_WEBHOOK_URL: ${HASTIC_WEBHOOK_URL} HASTIC_WEBHOOK_TYPE: ${HASTIC_WEBHOOK_TYPE} HASTIC_INSTANCE_NAME: ${HASTIC_INSTANCE_NAME} - HASTIC_WEBHOOK_IMAGE: ${HASTIC_WEBHOOK_IMAGE} - TIMEZONE_UTC_OFFSET: ${TIMEZONE_UTC_OFFSET} + HASTIC_ALERT_IMAGE: ${HASTIC_ALERT_IMAGE} + HASTIC_TIMEZONE_OFFSET: ${HASTIC_TIMEZONE_OFFSET} HASTIC_DB_CONNECTION_TYPE: mongodb diff --git a/docker-compose.yml b/docker-compose.yml index 771c3c2..7a9d8f3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,13 +12,15 @@ services: ZMQ_CONNECTION_STRING: ${ZMQ_CONNECTION_STRING:-tcp://analytics:8002} + HASTIC_ALERT_TYPE: ${HASTIC_ALERT_TYPE} + HASTIC_ALERTMANAGER_URL: ${HASTIC_ALERTMANAGER_URL} HASTIC_WEBHOOK_URL: ${HASTIC_WEBHOOK_URL} HASTIC_WEBHOOK_TYPE: ${HASTIC_WEBHOOK_TYPE} HASTIC_INSTANCE_NAME: ${HASTIC_INSTANCE_NAME} - HASTIC_WEBHOOK_IMAGE: ${HASTIC_WEBHOOK_IMAGE} + HASTIC_ALERT_IMAGE: ${HASTIC_ALERT_IMAGE} HASTIC_DB_CONNECTION_STRING: ${HASTIC_DB_CONNECTION_STRING} HASTIC_DB_CONNECTION_TYPE: ${HASTIC_DB_CONNECTION_TYPE} - TIMEZONE_UTC_OFFSET: ${TIMEZONE_UTC_OFFSET} + HASTIC_TIMEZONE_OFFSET: ${HASTIC_TIMEZONE_OFFSET} ports: - ${HASTIC_PORT:-8000}:8000 diff --git a/server/Dockerfile b/server/Dockerfile index ad5d1d1..572789a 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -7,10 +7,6 @@ RUN apk add --no-cache curl gnupg make g++ bash python # Note: context starts in directory above (see docker-compose file) COPY server /var/www/server -# copy git head file for current branch -# if nothing specified in `git_branch` arg then whole directory will be copied -COPY .git/refs/heads /var/www/.git/refs/heads - WORKDIR /var/www/server RUN npm install @@ -19,7 +15,7 @@ RUN npm run build FROM node:8-alpine # Note: context starts in directory above (see docker-compose file) -COPY .git/HEAD /var/www/.git/ +COPY .git /var/www/.git COPY server/package.json /var/www/server/ WORKDIR /var/www/server diff --git a/server/src/config.ts b/server/src/config.ts index 8214053..a66730c 100644 --- a/server/src/config.ts +++ b/server/src/config.ts @@ -62,7 +62,7 @@ export const HASTIC_ALERT_IMAGE = getConfigField('HASTIC_ALERT_IMAGE', false); export const HASTIC_WEBHOOK_URL = getConfigField('HASTIC_WEBHOOK_URL', null); export const HASTIC_WEBHOOK_TYPE = getConfigField('HASTIC_WEBHOOK_TYPE', 'application/json'); export const HASTIC_WEBHOOK_SECRET = getConfigField('HASTIC_WEBHOOK_SECRET', null); -export const TIMEZONE_UTC_OFFSET = getTimeZoneOffset(); +export const HASTIC_TIMEZONE_OFFSET = getTimeZoneOffset(); export const HASTIC_ALERTMANAGER_URL = getConfigField('HASTIC_ALERTMANAGER_URL', null); @@ -167,7 +167,7 @@ function getDbConfig(connectionStr: string): DBConfig { } function getTimeZoneOffset(): number { - let configTimeZone = getConfigField('TIMEZONE_UTC_OFFSET', null); + let configTimeZone = getConfigField('HASTIC_TIMEZONE_OFFSET', null); if(configTimeZone !== null) { return parseTimeZone(configTimeZone); } else { diff --git a/server/src/services/notification_service.ts b/server/src/services/notification_service.ts index b0cce80..bf45ce6 100644 --- a/server/src/services/notification_service.ts +++ b/server/src/services/notification_service.ts @@ -131,8 +131,10 @@ class AlertManagerNotifier implements Notifier { labels.alertname = (notification.meta as AnalyticMeta).analyticUnitName; labels.analyticUnitId = (notification.meta as AnalyticMeta).analyticUnitId; labels.analyticUnitType = (notification.meta as AnalyticMeta).analyticUnitType; - annotations.message = `${(notification.meta as AnalyticMeta).message}\n${generatorURL}`; + annotations.message = `${(notification.meta as AnalyticMeta).message}\nURL: ${generatorURL}`; } + + annotations.message += `\nInstance: ${config.HASTIC_INSTANCE_NAME}`; let alertData: PostableAlert = { labels, @@ -147,11 +149,10 @@ class AlertManagerNotifier implements Notifier { headers: { 'Content-Type': ContentType.JSON } }; - //first part: send start request + // first part: send "start" request await axios(options); - //TODO: resolve FAILURE alert only after RECOVERY event - //second part: send end request - alertData.endsAt = (new Date()).toISOString(); + // TODO: resolve FAILURE alert only after RECOVERY event + // second part: send "end" request options.data = JSON.stringify([alertData]); await axios(options); } diff --git a/server/src/utils/time.ts b/server/src/utils/time.ts index 658d781..18561f1 100644 --- a/server/src/utils/time.ts +++ b/server/src/utils/time.ts @@ -1,4 +1,4 @@ -import { TIMEZONE_UTC_OFFSET } from '../config'; +import { HASTIC_TIMEZONE_OFFSET } from '../config'; import * as _ from 'lodash'; import * as moment from 'moment'; @@ -11,7 +11,7 @@ export function parseTimeZone(timeZone: string): number { const re = /^-?\d{1,2}?:\d{2}$/; const correctFormat = re.test(timeZone); if(!correctFormat) { - throw new Error(`Wrong timeZone format in config - "TIMEZONE_UTC_OFFSET": ${timeZone}`); + throw new Error(`Wrong timeZone format in config - "HASTIC_TIMEZONE_OFFSET": ${timeZone}`); } const time = _.split(timeZone, ':'); let minutesOffset = Math.abs(Number(time[0])) * MINUTES_IN_HOUR + Number(time[1]); @@ -23,7 +23,7 @@ export function parseTimeZone(timeZone: string): number { export function toTimeZone(time: moment.MomentInput): string { const utcTime = moment(time).utc(); - const timeWithOffset = utcTime.utcOffset(TIMEZONE_UTC_OFFSET); + const timeWithOffset = utcTime.utcOffset(HASTIC_TIMEZONE_OFFSET); return timeWithOffset.format(TIME_FORMAT); }