Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for alerts #1

Open
rizo opened this issue Oct 1, 2019 · 0 comments
Open

Add support for alerts #1

rizo opened this issue Oct 1, 2019 · 0 comments

Comments

@rizo
Copy link
Member

rizo commented Oct 1, 2019

type no_data_state = [
  | `ok
  | `no_data
  | `keep_state 
  | `alerting
];
  
let no_data_state_to_yojson = (alert) =>
    switch (alert) {
    | `ok => `String("ok")
    | `no_data => `String("no_data")
    | `keep_state => `String("keep_state")
    | `alerting => `String("alerting")
    };

type execution_error_state = [
  | `no_data
  | `paused
  | `alerting
  | `ok
  | `pending
];
  
let execution_error_state_to_yojson = (error_state) =>
  switch (error_state) {
  | `no_data => `String("no_data")
  | `paused => `String("paused")
  | `alerting => `String("alerting")
  | `ok => `String("ok")
  | `pending => `String("pending")
  };

/* Operator */
type operator_type = [
  | `and_
  | `or_
];

let operator_type_to_yojson = (operator_type) =>
  switch (operator_type) {
  | `and_ => `String("and")
  | `or_ => `String("or")
  };

[@deriving (make, to_yojson { strict: false })]
type operator = {
  [@deriving.yojson.key "type"]
  [@deriving.make.default `and_]
  type_: operator_type
};

/* Reducer */
type reducer_type = [
  | `avg
  | `min
  | `max
  | `sum
  | `count
  | `last
  | `median
  | `diff
  | `percent_diff
  | `count_non_null
];
  
let reducer_type_to_yojson = (reducer) =>
  switch (reducer) {
  | `avg => `String("avg")
  | `min => `String("min")
  | `max => `String("max")
  | `sum => `String("sum")
  | `count => `String("count")
  | `last => `String("last")
  | `median => `String("median")
  | `diff => `String("diff")
  | `percent_diff => `String("percent_diff")
  | `count_non_null => `String("count_non_null")
  };

[@deriving (make, to_yojson { strict: false })]
type reducer = {
  [@deriving.yojson.key "type"]
  [@deriving.make.default `avg]
  type_: reducer_type,

  [@deriving.make.default []]
  params: list(string),
};

let reducer = (reducer_type) => { type_: reducer_type, params: [] };

/* Query */
[@deriving (make, to_yojson { strict: false })]
type query = {
  [@deriving.make.default ["A", "5m", "now"]]
  params: list(string)
};

let query = (a, b, c) => {params: [a, b, c]};

/* Evaluator */
[@deriving (make, to_yojson { strict: false })]
type evaluator = {
  [@deriving.yojson.key "type"]
  [@deriving.make.default "gt"]
  type_: string,

  [@deriving.make.default []]
  params: list(int),
};

let gt = (value) => { type_: "gt", params: [value] };
let lt = (value) => { type_: "lt", params: [value] };
let outside_range = (from_, to_) => { type_: "outside_range", params: [from_, to_] };
let within_range = (from_, to_) => { type_: "within_range", params: [from_, to_] };
let no_value = () => { type_: "no_value", params: [] };

/* Condition */
[@deriving (make, to_yojson { strict: false })]
type condition = {
  [@deriving.make.default "query"]
  type_: string,
  operator: operator,
  reducer: reducer,
  query: query,
  evaluator: evaluator,
};

[@deriving (make, to_yojson { strict: false })]
type notification = {
  /* Currently the notification with ID 1 is Slack  */
  [@deriving.make.default 1]
  id: int
};

let notifiction = make_notification;

let condition = (operator_type, reducer_type, query, evaluator) =>
    { type_: "query", operator: {type_: operator_type}, reducer: reducer(reducer_type), query, evaluator};

[@deriving (make, to_yojson { strict: false })]
type t = {
  message: string,
  name: string,
  
  [@deriving.make.default []]
  conditions: list(condition),

  [@deriving.yojson.key "executionErrorState"]
  [@deriving.make.default `alerting]
  execution_error_state: execution_error_state,
  
  [@deriving.make.default "60s"]
  frequency: string,
  
  [@deriving.yojson.key "noDataState"]
  [@deriving.make.default `ok]
  no_data_state: no_data_state,

  [@deriving.make.default [notifiction()]]
  notifications: list(notification),

  [@deriving.make.default 1]
  handler: int,
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant