Skip to content

Commit 8183a5b

Browse files
authored
Merge pull request #32 from GaMeRaM/alerts_state_fix
Fix: Alert state type and value
2 parents cfa5825 + 60e1772 commit 8183a5b

File tree

6 files changed

+19
-17
lines changed

6 files changed

+19
-17
lines changed

dist/prometheus-query.cjs.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/prometheus-query.esm.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/prometheus-query.umd.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/types.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ export declare class Alert {
5252
activeAt: Date;
5353
annotations: object;
5454
labels: object;
55-
state: TargetState;
55+
state: AlertState;
5656
value: number;
57-
constructor(activeAt: Date, annotations: object, labels: object, state: TargetState, value: number);
57+
constructor(activeAt: Date, annotations: object, labels: object, state: AlertState, value: number);
5858
static fromJSON(obj: any): Alert;
5959
}
6060
export declare class Rule {
@@ -79,3 +79,4 @@ export declare class RuleGroup {
7979
}
8080
export declare type SerieSelector = string | string[];
8181
export declare type TargetState = 'active' | 'dropped' | 'any';
82+
export declare type AlertState = 'firing' | 'pending' | 'inactive';

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "prometheus-query",
33
"description": "A Javascript client for Prometheus query API",
4-
"version": "3.3.0",
4+
"version": "3.3.1",
55
"main": "dist/prometheus-query.cjs.js",
66
"module": "dist/prometheus-query.esm.js",
77
"browser": "dist/prometheus-query.umd.js",

src/types.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,18 +199,18 @@ export class Alert {
199199
public activeAt: Date;
200200
public annotations: object;
201201
public labels: object;
202-
public state: TargetState;
202+
public state: AlertState;
203203
public value: number;
204204

205-
constructor(activeAt: Date, annotations: object, labels: object, state: TargetState, value: number) {
205+
constructor(activeAt: Date, annotations: object, labels: object, state: AlertState, value: number) {
206206
if (!!activeAt && (typeof (activeAt) != 'object' || activeAt.constructor.name != 'Date'))
207207
throw new Error(`Unexpected format for activeAt. Got ${typeof (activeAt)} instead of object`);
208208
if (!!annotations && typeof (annotations) != 'object')
209209
throw new Error(`Unexpected format for annotations. Got ${typeof (annotations)} instead of object`);
210210
if (!!labels && typeof (labels) != 'object')
211211
throw new Error(`Unexpected format for labels. Got ${typeof (labels)} instead of object`);
212-
// if (!!state && typeof (state) != 'TargetState')
213-
// throw new Error(`Unexpected format for state. Got ${typeof (state)} instead of string`);
212+
// if (!!state && typeof (state) != 'AlertState')
213+
// throw new Error(`Unexpected format for state. Got ${typeof (state)} instead of string`);
214214
if (!!value && typeof (value) != 'number')
215215
throw new Error(`Unexpected format for value. Got ${typeof (value)} instead of number`);
216216

@@ -226,7 +226,7 @@ export class Alert {
226226
!!obj['activeAt'] ? new Date(obj['activeAt']) : null,
227227
obj['annotations'],
228228
obj['labels'],
229-
ResponseType[obj['state']],
229+
obj['state'],
230230
!!obj['value'] ? parseFloat(obj['value']) : null,
231231
);
232232
}
@@ -296,4 +296,5 @@ export class RuleGroup {
296296
};
297297

298298
export type SerieSelector = string | string[];
299-
export type TargetState = 'active' | 'dropped' | 'any';
299+
export type TargetState = 'active' | 'dropped' | 'any';
300+
export type AlertState = 'firing' | 'pending' | 'inactive';

0 commit comments

Comments
 (0)