Skip to content

Commit

Permalink
Production hotfixes (#803)
Browse files Browse the repository at this point in the history
* fix compose variables

* fix server/Dockerfile

* fix notification message

* HASTIC_TIMEZONE_OFFSET
  • Loading branch information
rozetko authored and jonyrock committed Nov 6, 2019
1 parent 353da09 commit 3f64c25
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 19 deletions.
6 changes: 4 additions & 2 deletions docker-compose-mongo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 4 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions server/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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 {
Expand Down
11 changes: 6 additions & 5 deletions server/src/services/notification_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions server/src/utils/time.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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]);
Expand All @@ -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);
}

0 comments on commit 3f64c25

Please sign in to comment.