mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
singlestat: render time of last point based on dashboard timezone (#11425)
* singlestat: render time of last point based on dashboard timezone * changelog: add note for #10338
This commit is contained in:
committed by
Torkel Ödegaard
parent
e52aceeaba
commit
ef0b7bda6f
@@ -308,7 +308,7 @@ class SingleStatCtrl extends MetricsPanelCtrl {
|
||||
let formatFunc = kbn.valueFormats[this.panel.format];
|
||||
data.value = lastPoint[1];
|
||||
data.valueRounded = data.value;
|
||||
data.valueFormatted = formatFunc(data.value, 0, 0);
|
||||
data.valueFormatted = formatFunc(data.value, this.dashboard.isTimezoneUtc());
|
||||
} else {
|
||||
data.value = this.series[0].stats[this.panel.valueName];
|
||||
data.flotpairs = this.series[0].flotpairs;
|
||||
|
||||
@@ -82,6 +82,19 @@ describe('SingleStatCtrl', function() {
|
||||
});
|
||||
});
|
||||
|
||||
singleStatScenario('showing last iso time instead of value (in UTC)', function(ctx) {
|
||||
ctx.setup(function() {
|
||||
ctx.data = [{ target: 'test.cpu1', datapoints: [[10, 12], [20, 1505634997920]] }];
|
||||
ctx.ctrl.panel.valueName = 'last_time';
|
||||
ctx.ctrl.panel.format = 'dateTimeAsIso';
|
||||
ctx.setIsUtc(true);
|
||||
});
|
||||
|
||||
it('should set formatted value', function() {
|
||||
expect(ctx.data.valueFormatted).to.be(moment.utc(1505634997920).format('YYYY-MM-DD HH:mm:ss'));
|
||||
});
|
||||
});
|
||||
|
||||
singleStatScenario('showing last us time instead of value', function(ctx) {
|
||||
ctx.setup(function() {
|
||||
ctx.data = [{ target: 'test.cpu1', datapoints: [[10, 12], [20, 1505634997920]] }];
|
||||
@@ -99,6 +112,19 @@ describe('SingleStatCtrl', function() {
|
||||
});
|
||||
});
|
||||
|
||||
singleStatScenario('showing last us time instead of value (in UTC)', function(ctx) {
|
||||
ctx.setup(function() {
|
||||
ctx.data = [{ target: 'test.cpu1', datapoints: [[10, 12], [20, 1505634997920]] }];
|
||||
ctx.ctrl.panel.valueName = 'last_time';
|
||||
ctx.ctrl.panel.format = 'dateTimeAsUS';
|
||||
ctx.setIsUtc(true);
|
||||
});
|
||||
|
||||
it('should set formatted value', function() {
|
||||
expect(ctx.data.valueFormatted).to.be(moment.utc(1505634997920).format('MM/DD/YYYY h:mm:ss a'));
|
||||
});
|
||||
});
|
||||
|
||||
singleStatScenario('showing last time from now instead of value', function(ctx) {
|
||||
beforeEach(() => {
|
||||
clock = sinon.useFakeTimers(epoch);
|
||||
@@ -124,6 +150,27 @@ describe('SingleStatCtrl', function() {
|
||||
});
|
||||
});
|
||||
|
||||
singleStatScenario('showing last time from now instead of value (in UTC)', function(ctx) {
|
||||
beforeEach(() => {
|
||||
clock = sinon.useFakeTimers(epoch);
|
||||
});
|
||||
|
||||
ctx.setup(function() {
|
||||
ctx.data = [{ target: 'test.cpu1', datapoints: [[10, 12], [20, 1505634997920]] }];
|
||||
ctx.ctrl.panel.valueName = 'last_time';
|
||||
ctx.ctrl.panel.format = 'dateTimeFromNow';
|
||||
ctx.setIsUtc(true);
|
||||
});
|
||||
|
||||
it('should set formatted value', function() {
|
||||
expect(ctx.data.valueFormatted).to.be('2 days ago');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
clock.restore();
|
||||
});
|
||||
});
|
||||
|
||||
singleStatScenario('MainValue should use same number for decimals as displayed when checking thresholds', function(
|
||||
ctx
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user