Skip to content

Commit 1b93d6e

Browse files
committed
feat #OBS-I649 : set channel as a reciever for a alert rule
1 parent 72fa495 commit 1b93d6e

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

api-service/src/controllers/DatasetRead/DatasetRead.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ const readDataset = async (datasetId: string, attributes: string[]): Promise<any
8282
const api_version = _.get(dataset, "api_version")
8383
const datasetConfigs: any = {}
8484
const transformations_config = await datasetService.getTransformations(datasetId, ["field_key", "transformation_function", "mode", "metadata"])
85-
const datasourceConfig = await Datasource.findOne({ where: { dataset_id: datasetId, is_primary: true }, attributes: ["datasource"], raw: true })
85+
const datasourceConfig = await Datasource.findOne({ where: { dataset_id: datasetId, is_primary: true, type: "druid" }, attributes: ["datasource"], raw: true })
8686
datasetConfigs["alias"] = _.get(datasourceConfig, "datasource")
8787
if (api_version !== "v2") {
8888
datasetConfigs["transformations_config"] = _.map(transformations_config, (config) => {

api-service/src/services/DatasetService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ class DatasetService {
144144
{
145145
model: Datasource,
146146
attributes: ['datasource'],
147-
where: { is_primary: true },
147+
where: { is_primary: true, type: "druid" },
148148
required: false
149149
},
150150
], raw: true, where: filters, attributes, order: [["updated_date", "DESC"]]

api-service/src/services/managers/grafana/alert/helpers/index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,27 @@ const getMatchingLabels = async (channels: string[]) => {
244244
}
245245
}
246246

247+
const getNotificationChannel = async (channels: string[]) => {
248+
const fetchChannel = (id: string) => {
249+
return Notification.findOne({ where: { id } })
250+
.then(response => response?.toJSON())
251+
.then(channelMetadata => {
252+
const { name, type } = channelMetadata;
253+
return name;
254+
})
255+
.catch(() => null);
256+
}
257+
258+
const [name] = await Promise.all(channels.map(fetchChannel));
259+
return name;
260+
}
261+
247262
const transformRule = async ({ value, condition, metadata, isGroup }: any) => {
248263
const { name, id, interval, category, frequency, labels = {}, annotations = {}, severity, description, notification = {} } = value;
249264
const annotationObj = { ...annotations, description: description };
250265
const channels = _.get(notification, "channels") || [];
251266
const matchingLabelsForNotification = await getMatchingLabels(channels);
267+
const channel = await getNotificationChannel(channels);
252268

253269
const payload = {
254270
grafana_alert: {
@@ -258,6 +274,7 @@ const transformRule = async ({ value, condition, metadata, isGroup }: any) => {
258274
exec_err_state: _.get(metadata, "exec_err_state", "Error"),
259275
data: metadata,
260276
is_paused: false,
277+
...(channel && { notification_settings: { receiver: channel } })
261278
},
262279
for: interval,
263280
annotations: annotationObj,

0 commit comments

Comments
 (0)