passing time filters (#64086)

* passing time filters

* add settings

* Cleanup and merge fixes

---------

Co-authored-by: André Pereira <adrapereira@gmail.com>
This commit is contained in:
alburthoffman 2023-07-31 08:13:48 -07:00 committed by GitHub
parent bffd55efd4
commit cdfbcb2ec6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 73 additions and 4 deletions

View File

@ -11,6 +11,8 @@ import { TraceToLogsSection } from 'app/core/components/TraceToLogs/TraceToLogsS
import { TraceToMetricsSection } from 'app/core/components/TraceToMetrics/TraceToMetricsSettings';
import { SpanBarSection } from 'app/features/explore/TraceView/components/settings/SpanBarSettings';
import { TraceIdTimeParams } from './TraceIdTimeParams';
export type Props = DataSourcePluginOptionsEditorProps;
export const ConfigEditor = ({ options, onOptionsChange }: Props) => {
@ -54,6 +56,8 @@ export const ConfigEditor = ({ options, onOptionsChange }: Props) => {
<NodeGraphSection options={options} onOptionsChange={onOptionsChange} />
<Divider hideLine={true} />
<SpanBarSection options={options} onOptionsChange={onOptionsChange} />
<Divider hideLine={true} />
<TraceIdTimeParams options={options} onOptionsChange={onOptionsChange} />
</ConfigSection>
</div>
);

View File

@ -0,0 +1,56 @@
import { css } from '@emotion/css';
import React from 'react';
import {
DataSourceJsonData,
DataSourcePluginOptionsEditorProps,
updateDatasourcePluginJsonDataOption,
} from '@grafana/data';
import { InlineField, InlineFieldRow, InlineSwitch } from '@grafana/ui';
export interface TraceIdTimeParamsOptions {
enabled?: boolean;
}
export interface TraceIdTimeParamsData extends DataSourceJsonData {
traceIdTimeParams?: TraceIdTimeParamsOptions;
}
interface Props extends DataSourcePluginOptionsEditorProps<TraceIdTimeParamsData> {}
export function TraceIdTimeParams({ options, onOptionsChange }: Props) {
return (
<div className={styles.container}>
<h3 className="page-heading">Query Trace by ID with Time Params</h3>
<InlineFieldRow className={styles.row}>
<InlineField
tooltip="pass time parameters when querying trace by ID"
label="Enable Time Parameters"
labelWidth={26}
>
<InlineSwitch
id="enableTraceIdTimeParams"
value={options.jsonData.traceIdTimeParams?.enabled}
onChange={(event: React.SyntheticEvent<HTMLInputElement>) =>
updateDatasourcePluginJsonDataOption({ onOptionsChange, options }, 'traceIdTimeParams', {
...options.jsonData.traceIdTimeParams,
enabled: event.currentTarget.checked,
})
}
/>
</InlineField>
</InlineFieldRow>
</div>
);
}
const styles = {
container: css`
label: container;
width: 100%;
`,
row: css`
label: row;
align-items: baseline;
`,
};

View File

@ -21,6 +21,7 @@ import { getTimeSrv, TimeSrv } from 'app/features/dashboard/services/TimeSrv';
import { SpanBarOptions } from 'app/features/explore/TraceView/components';
import { ALL_OPERATIONS_KEY } from './components/SearchForm';
import { TraceIdTimeParamsOptions } from './configuration/TraceIdTimeParams';
import { createGraphFrames } from './graphTransform';
import { createTableFrame, createTraceFrame } from './responseTransform';
import { JaegerQuery } from './types';
@ -28,11 +29,13 @@ import { convertTagsLogfmt } from './util';
export interface JaegerJsonData extends DataSourceJsonData {
nodeGraph?: NodeGraphOptions;
traceIdTimeParams?: TraceIdTimeParamsOptions;
}
export class JaegerDatasource extends DataSourceApi<JaegerQuery, JaegerJsonData> {
uploadedJson: string | ArrayBuffer | null = null;
nodeGraph?: NodeGraphOptions;
traceIdTimeParams?: TraceIdTimeParamsOptions;
spanBar?: SpanBarOptions;
constructor(
private instanceSettings: DataSourceInstanceSettings<JaegerJsonData>,
@ -41,6 +44,7 @@ export class JaegerDatasource extends DataSourceApi<JaegerQuery, JaegerJsonData>
) {
super(instanceSettings);
this.nodeGraph = instanceSettings.jsonData.nodeGraph;
this.traceIdTimeParams = instanceSettings.jsonData.traceIdTimeParams;
}
async metadataRequest(url: string, params?: Record<string, any>): Promise<any> {
@ -65,10 +69,15 @@ export class JaegerDatasource extends DataSourceApi<JaegerQuery, JaegerJsonData>
return of({ error: { message: 'You must select a service.' }, data: [] });
}
let { start, end } = this.getTimeRange();
if (target.queryType !== 'search' && target.query) {
return this._request(
`/api/traces/${encodeURIComponent(this.templateSrv.replace(target.query, options.scopedVars))}`
).pipe(
let url = `/api/traces/${encodeURIComponent(this.templateSrv.replace(target.query, options.scopedVars))}`;
if (this.traceIdTimeParams) {
url += `?start=${start}&end=${end}`;
}
return this._request(url).pipe(
map((response) => {
const traceData = response?.data?.data?.[0];
if (!traceData) {

View File

@ -1,8 +1,8 @@
import { DataSourcePlugin } from '@grafana/data';
import CheatSheet from './CheatSheet';
import { ConfigEditor } from './components/ConfigEditor';
import { QueryEditor } from './components/QueryEditor';
import { ConfigEditor } from './configuration/ConfigEditor';
import { JaegerDatasource } from './datasource';
export const plugin = new DataSourcePlugin(JaegerDatasource)