mirror of
https://github.com/grafana/grafana.git
synced 2025-08-02 01:15:46 +08:00

* wip: add slo support * Export DataSourcePlugin * wip: break out metric query editor into its own component * wip: refactor frontend - keep SLO and Metric query in differnt objects * wip - load services and slos * Fix broken test * Add interactive slo expression builder * Change order of dropdowns * Refactoring backend model. slo unit testing in progress * Unit test migration and SLOs * Cleanup SLO editor * Simplify alias by component * Support alias by for slos * Support slos in variable queries * Fix broken last query error * Update Help section to include SLO aliases * streamline datasource resource cache * Break out api specific stuff in datasource to its own file * Move get projects call to frontend * Refactor api caching * Unit test api service * Fix lint go issue * Fix typescript strict errors * Fix test datasource * Use budget fraction selector instead of budget * Reset SLO when service is changed * Handle error in case resource call returned no data * Show real SLI display name * Use unsafe prefix on will mount hook * Store goal in query model since it will be used as soon as graph panel supports adding a threshold * Add comment to describe why componentWillMount is used * Interpolate sloid * Break out SLO aggregation into its own func * Also test group bys for metricquery test * Remove not used type fields * Remove annoying stackdriver prefix from error message * Default view param to FULL * Add part about SLO query builder in docs * Use new images * Fixes after feedback * Add one more group by test * Make stackdriver types internal * Update docs/sources/features/datasources/stackdriver.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update docs/sources/features/datasources/stackdriver.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update docs/sources/features/datasources/stackdriver.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Updates after PR feedback * add test for when no alias by defined * fix infinite loop when newVariables feature flag is on onChange being called in componentDidUpdate produces an infinite loop when using the new React template variable implementation. Also fixes a spelling mistake * implements feedback for documentation changes * more doc changes Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Daniel Lee <dan.limerick@gmail.com>
109 lines
3.5 KiB
TypeScript
109 lines
3.5 KiB
TypeScript
import React from 'react';
|
|
import { Segment, SegmentAsync } from '@grafana/ui';
|
|
import { SelectableValue } from '@grafana/data';
|
|
import { selectors } from '../constants';
|
|
import { Project, AlignmentPeriods, AliasBy, QueryInlineField } from '.';
|
|
import { SLOQuery } from '../types';
|
|
import StackdriverDatasource from '../datasource';
|
|
|
|
export interface Props {
|
|
usedAlignmentPeriod: string;
|
|
variableOptionGroup: SelectableValue<string>;
|
|
onChange: (query: SLOQuery) => void;
|
|
onRunQuery: () => void;
|
|
query: SLOQuery;
|
|
datasource: StackdriverDatasource;
|
|
}
|
|
|
|
export const defaultQuery: SLOQuery = {
|
|
projectName: '',
|
|
alignmentPeriod: 'stackdriver-auto',
|
|
aliasBy: '',
|
|
selectorName: 'select_slo_health',
|
|
serviceId: '',
|
|
sloId: '',
|
|
};
|
|
|
|
export function SLOQueryEditor({
|
|
query,
|
|
datasource,
|
|
onChange,
|
|
variableOptionGroup,
|
|
usedAlignmentPeriod,
|
|
}: React.PropsWithChildren<Props>) {
|
|
return (
|
|
<>
|
|
<Project
|
|
templateVariableOptions={variableOptionGroup.options}
|
|
projectName={query.projectName}
|
|
datasource={datasource}
|
|
onChange={projectName => onChange({ ...query, projectName })}
|
|
/>
|
|
<QueryInlineField label="Service">
|
|
<SegmentAsync
|
|
allowCustomValue
|
|
value={query?.serviceId}
|
|
placeholder="Select service"
|
|
loadOptions={() =>
|
|
datasource.getSLOServices(query.projectName).then(services => [
|
|
{
|
|
label: 'Template Variables',
|
|
options: variableOptionGroup.options,
|
|
},
|
|
...services,
|
|
])
|
|
}
|
|
onChange={({ value: serviceId = '' }) => onChange({ ...query, serviceId, sloId: '' })}
|
|
/>
|
|
</QueryInlineField>
|
|
|
|
<QueryInlineField label="SLO">
|
|
<SegmentAsync
|
|
allowCustomValue
|
|
value={query?.sloId}
|
|
placeholder="Select SLO"
|
|
loadOptions={() =>
|
|
datasource.getServiceLevelObjectives(query.projectName, query.serviceId).then(sloIds => [
|
|
{
|
|
label: 'Template Variables',
|
|
options: variableOptionGroup.options,
|
|
},
|
|
...sloIds,
|
|
])
|
|
}
|
|
onChange={async ({ value: sloId = '' }) => {
|
|
const slos = await datasource.getServiceLevelObjectives(query.projectName, query.serviceId);
|
|
const slo = slos.find(({ value }) => value === datasource.templateSrv.replace(sloId));
|
|
onChange({ ...query, sloId, goal: slo?.goal });
|
|
}}
|
|
/>
|
|
</QueryInlineField>
|
|
|
|
<QueryInlineField label="Selector">
|
|
<Segment
|
|
allowCustomValue
|
|
value={[...selectors, ...variableOptionGroup.options].find(s => s.value === query?.selectorName ?? '')}
|
|
options={[
|
|
{
|
|
label: 'Template Variables',
|
|
options: variableOptionGroup.options,
|
|
},
|
|
...selectors,
|
|
]}
|
|
onChange={({ value: selectorName }) => onChange({ ...query, selectorName })}
|
|
/>
|
|
</QueryInlineField>
|
|
|
|
<AlignmentPeriods
|
|
templateSrv={datasource.templateSrv}
|
|
templateVariableOptions={variableOptionGroup.options}
|
|
alignmentPeriod={query.alignmentPeriod || ''}
|
|
perSeriesAligner={query.selectorName === 'select_slo_health' ? 'ALIGN_MEAN' : 'ALIGN_NEXT_OLDER'}
|
|
usedAlignmentPeriod={usedAlignmentPeriod}
|
|
onChange={alignmentPeriod => onChange({ ...query, alignmentPeriod })}
|
|
/>
|
|
<AliasBy value={query.aliasBy} onChange={aliasBy => onChange({ ...query, aliasBy })} />
|
|
</>
|
|
);
|
|
}
|