Skip to content

Commit bf78214

Browse files
committed
fix(labelNames+labelValues): fix default parameter for dates
1 parent 0901cb9 commit bf78214

File tree

5 files changed

+16
-14
lines changed

5 files changed

+16
-14
lines changed

dist/prometheus-query.cjs.js

Lines changed: 4 additions & 4 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: 4 additions & 4 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: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/nodejs/app.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { PrometheusDriver, Alert, Metric, QueryResult } from '../../';
33

44
const prom = new PrometheusDriver({
55
endpoint: 'https://prometheus.demo.do.prometheus.io/',
6+
// endpoint: 'http://localhost:9090/',
67
});
78

89
const query = 'up{instance="demo.do.prometheus.io:9090",job="prometheus"}';

src/driver.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export class PrometheusDriver {
120120

121121
if (!!this.options.warningHook && !!response['warnings'] && response['warnings'].length > 0)
122122
this.options.warningHook(response['warnings']);
123-
123+
124124
const data = (response as any).data;
125125
if (!data || data.status == null)
126126
throw {
@@ -146,6 +146,7 @@ export class PrometheusDriver {
146146
return input / 1000;
147147
else if (typeof (input) == 'object' && input?.constructor?.name == 'Date')
148148
return input.getTime() / 1000;
149+
149150
throw new Error('Wrong time format. Expected number or Date.');
150151
}
151152

@@ -242,8 +243,8 @@ export class PrometheusDriver {
242243
public labelNames(matchs?: SerieSelector, start?: PrometheusQueryDate, end?: PrometheusQueryDate): Promise<string[]> {
243244
const params = {
244245
match: this.listifyIfNeeded(matchs),
245-
start: this.formatTimeToPrometheus(start),
246-
end: this.formatTimeToPrometheus(end),
246+
start: start ? this.formatTimeToPrometheus(start): undefined,
247+
end: end ? this.formatTimeToPrometheus(end) : undefined,
247248
}
248249

249250
return (this.options.preferPost)
@@ -261,8 +262,8 @@ export class PrometheusDriver {
261262
public labelValues(labelName: string, matchs?: SerieSelector, start?: PrometheusQueryDate, end?: PrometheusQueryDate): Promise<string[]> {
262263
const params = {
263264
match: this.listifyIfNeeded(matchs),
264-
start: this.formatTimeToPrometheus(start, new Date()),
265-
end: this.formatTimeToPrometheus(end, new Date()),
265+
start: start ? this.formatTimeToPrometheus(start) : undefined,
266+
end: end ? this.formatTimeToPrometheus(end) : undefined,
266267
}
267268

268269
return this.request('GET', `label/${labelName}/values`, params)

0 commit comments

Comments
 (0)