Browse Source

Production hotfixes (#803)

* fix compose variables

* fix server/Dockerfile

* fix notification message

* HASTIC_TIMEZONE_OFFSET
pull/1/head
rozetko 5 years ago committed by Alexey Velikiy
parent
commit
3f64c25c10
  1. 6
      docker-compose-mongo.yml
  2. 6
      docker-compose.yml
  3. 6
      server/Dockerfile
  4. 4
      server/src/config.ts
  5. 11
      server/src/services/notification_service.ts
  6. 6
      server/src/utils/time.ts

6
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} 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} 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_URL: ${HASTIC_WEBHOOK_URL}
HASTIC_WEBHOOK_TYPE: ${HASTIC_WEBHOOK_TYPE} HASTIC_WEBHOOK_TYPE: ${HASTIC_WEBHOOK_TYPE}
HASTIC_INSTANCE_NAME: ${HASTIC_INSTANCE_NAME} HASTIC_INSTANCE_NAME: ${HASTIC_INSTANCE_NAME}
HASTIC_WEBHOOK_IMAGE: ${HASTIC_WEBHOOK_IMAGE} HASTIC_ALERT_IMAGE: ${HASTIC_ALERT_IMAGE}
TIMEZONE_UTC_OFFSET: ${TIMEZONE_UTC_OFFSET} HASTIC_TIMEZONE_OFFSET: ${HASTIC_TIMEZONE_OFFSET}
HASTIC_DB_CONNECTION_TYPE: mongodb HASTIC_DB_CONNECTION_TYPE: mongodb

6
docker-compose.yml

@ -12,13 +12,15 @@ services:
ZMQ_CONNECTION_STRING: ${ZMQ_CONNECTION_STRING:-tcp://analytics:8002} 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_URL: ${HASTIC_WEBHOOK_URL}
HASTIC_WEBHOOK_TYPE: ${HASTIC_WEBHOOK_TYPE} HASTIC_WEBHOOK_TYPE: ${HASTIC_WEBHOOK_TYPE}
HASTIC_INSTANCE_NAME: ${HASTIC_INSTANCE_NAME} 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_STRING: ${HASTIC_DB_CONNECTION_STRING}
HASTIC_DB_CONNECTION_TYPE: ${HASTIC_DB_CONNECTION_TYPE} HASTIC_DB_CONNECTION_TYPE: ${HASTIC_DB_CONNECTION_TYPE}
TIMEZONE_UTC_OFFSET: ${TIMEZONE_UTC_OFFSET} HASTIC_TIMEZONE_OFFSET: ${HASTIC_TIMEZONE_OFFSET}
ports: ports:
- ${HASTIC_PORT:-8000}:8000 - ${HASTIC_PORT:-8000}:8000

6
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) # Note: context starts in directory above (see docker-compose file)
COPY server /var/www/server 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 WORKDIR /var/www/server
RUN npm install RUN npm install
@ -19,7 +15,7 @@ RUN npm run build
FROM node:8-alpine FROM node:8-alpine
# Note: context starts in directory above (see docker-compose file) # 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/ COPY server/package.json /var/www/server/
WORKDIR /var/www/server WORKDIR /var/www/server

4
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_URL = getConfigField('HASTIC_WEBHOOK_URL', null);
export const HASTIC_WEBHOOK_TYPE = getConfigField('HASTIC_WEBHOOK_TYPE', 'application/json'); export const HASTIC_WEBHOOK_TYPE = getConfigField('HASTIC_WEBHOOK_TYPE', 'application/json');
export const HASTIC_WEBHOOK_SECRET = getConfigField('HASTIC_WEBHOOK_SECRET', null); 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); export const HASTIC_ALERTMANAGER_URL = getConfigField('HASTIC_ALERTMANAGER_URL', null);
@ -167,7 +167,7 @@ function getDbConfig(connectionStr: string): DBConfig {
} }
function getTimeZoneOffset(): number { function getTimeZoneOffset(): number {
let configTimeZone = getConfigField('TIMEZONE_UTC_OFFSET', null); let configTimeZone = getConfigField('HASTIC_TIMEZONE_OFFSET', null);
if(configTimeZone !== null) { if(configTimeZone !== null) {
return parseTimeZone(configTimeZone); return parseTimeZone(configTimeZone);
} else { } else {

11
server/src/services/notification_service.ts

@ -131,8 +131,10 @@ class AlertManagerNotifier implements Notifier {
labels.alertname = (notification.meta as AnalyticMeta).analyticUnitName; labels.alertname = (notification.meta as AnalyticMeta).analyticUnitName;
labels.analyticUnitId = (notification.meta as AnalyticMeta).analyticUnitId; labels.analyticUnitId = (notification.meta as AnalyticMeta).analyticUnitId;
labels.analyticUnitType = (notification.meta as AnalyticMeta).analyticUnitType; 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 = { let alertData: PostableAlert = {
labels, labels,
@ -147,11 +149,10 @@ class AlertManagerNotifier implements Notifier {
headers: { 'Content-Type': ContentType.JSON } headers: { 'Content-Type': ContentType.JSON }
}; };
//first part: send start request // first part: send "start" request
await axios(options); await axios(options);
//TODO: resolve FAILURE alert only after RECOVERY event // TODO: resolve FAILURE alert only after RECOVERY event
//second part: send end request // second part: send "end" request
alertData.endsAt = (new Date()).toISOString();
options.data = JSON.stringify([alertData]); options.data = JSON.stringify([alertData]);
await axios(options); await axios(options);
} }

6
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 _ from 'lodash';
import * as moment from 'moment'; import * as moment from 'moment';
@ -11,7 +11,7 @@ export function parseTimeZone(timeZone: string): number {
const re = /^-?\d{1,2}?:\d{2}$/; const re = /^-?\d{1,2}?:\d{2}$/;
const correctFormat = re.test(timeZone); const correctFormat = re.test(timeZone);
if(!correctFormat) { 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, ':'); const time = _.split(timeZone, ':');
let minutesOffset = Math.abs(Number(time[0])) * MINUTES_IN_HOUR + Number(time[1]); 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 { export function toTimeZone(time: moment.MomentInput): string {
const utcTime = moment(time).utc(); const utcTime = moment(time).utc();
const timeWithOffset = utcTime.utcOffset(TIMEZONE_UTC_OFFSET); const timeWithOffset = utcTime.utcOffset(HASTIC_TIMEZONE_OFFSET);
return timeWithOffset.format(TIME_FORMAT); return timeWithOffset.format(TIME_FORMAT);
} }

Loading…
Cancel
Save