datasource: testdata - add predictable pulse scenario (#18142)

Adds pulse waveform. Is predictable in the sense that the start of the waveform is aligned to epoch time (instead of the start of the query time). This makes a useful signal for manual testing of alerting in the devenv.
This commit is contained in:
Kyle Brandt
2019-07-17 15:48:08 -04:00
committed by GitHub
parent f38187d68b
commit ed099d5ca0
3 changed files with 184 additions and 0 deletions

View File

@@ -116,4 +116,68 @@
<gf-form-switch class="gf-form" label="Level" label-class="query-keyword width-5" checked="ctrl.target.levelColumn" switch-class="max-width-6" on-change="ctrl.refresh()"></gf-form-switch>
</div>
</div>
<!-- Predictable Pulse Scenario Options Form -->
<div class="gf-form-inline" ng-if="ctrl.scenario.id === 'predictable_pulse'">
<div class="gf-form">
<label class="gf-form-label query-keyword width-7">
Step
<info-popover mode="right-normal">The number of seconds between datapoints.</info-popover>
</label>
<input type="number"
class="gf-form-input width-5"
placeholder="60"
ng-model="ctrl.target.pulseWave.timeStep"
ng-change="ctrl.refresh()"
ng-model-onblur />
</div>
<div class="gf-form">
<label class="gf-form-label query-keyword width-7">
On Count
<info-popover mode="right-normal">The number of values within a cycle, at the start of the cycle, that should have the onValue.</info-popover>
</label>
<input type="number"
class="gf-form-input width-3"
placeholder="3"
ng-model="ctrl.target.pulseWave.onCount"
ng-change="ctrl.refresh()"
ng-model-onblur />
</div>
<div class="gf-form">
<label class="gf-form-label query-keyword width-7">
Off Count
<info-popover mode="right-normal">The number of offValues within the cycle.</info-popover>
</label>
<input type="number"
class="gf-form-input width-3"
placeholder="6"
ng-model="ctrl.target.pulseWave.offCount"
ng-change="ctrl.refresh()"
ng-model-onblur />
</div>
<div class="gf-form">
<label class="gf-form-label query-keyword width-7">
On Value
<info-popover mode="right-normal">The value for "on values", may be a int, float, or null.</info-popover>
</label>
<input type="string"
class="gf-form-input width-5"
placeholder="1"
ng-model="ctrl.target.pulseWave.onValue"
ng-change="ctrl.refresh()"
ng-model-onblur />
</div>
<div class="gf-form">
<label class="gf-form-label query-keyword width-7">
Off Value
<info-popover mode="right-normal">The value for "off values", may be a int, float, or null.</info-popover>
</label>
<input type="string"
class="gf-form-input width-5"
placeholder="1"
ng-model="ctrl.target.pulseWave.offValue"
ng-change="ctrl.refresh()"
ng-model-onblur />
</div>
</div>
</query-editor-row>

View File

@@ -5,6 +5,14 @@ import { defaultQuery } from './StreamHandler';
import { getBackendSrv } from 'app/core/services/backend_srv';
import { dateTime } from '@grafana/data';
export const defaultPulse: any = {
timeStep: 60,
onCount: 3,
onValue: 2,
offCount: 3,
offValue: 1,
};
export class TestDataQueryCtrl extends QueryCtrl {
static templateUrl = 'partials/query.editor.html';
@@ -75,6 +83,12 @@ export class TestDataQueryCtrl extends QueryCtrl {
delete this.target.stream;
}
if (this.target.scenarioId === 'predictable_pulse') {
this.target.pulseWave = _.defaults(this.target.pulseWave || {}, defaultPulse);
} else {
delete this.target.pulseWave;
}
this.refresh();
}