Skip to content

Commit

Permalink
Allow VisualizationContainer to handle input data from both Metric an…
Browse files Browse the repository at this point in the history
…d PPL

Signed-off-by: Peter Fitzgibbons <peter.fitzgibbons@gmail.com>
  • Loading branch information
pjfitzgibbons committed Aug 7, 2023
1 parent 6565805 commit 2b44603
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 32 deletions.
5 changes: 2 additions & 3 deletions public/components/custom_panels/helpers/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,6 @@ export const renderCatalogVisualization = async ({

setVisualizationMetaData({ ...visualizationMetaData, query: visualizationQuery });

console.log('getqueryResponse', visualizationQuery);
getQueryResponse(
pplService,
visualizationQuery,
Expand Down Expand Up @@ -548,12 +547,12 @@ export const processMetricsData = (schema: any, dataConfig: any) => {
schema.length === 3 &&
schema.every((schemaField) => ['@labels', '@value', '@timestamp'].includes(schemaField.name))
) {
return prepareMetricsData(schema, dataConfig);
return prepareMetricsData(schema);
}
return {};
};

export const prepareMetricsData = (schema: any, dataConfig: any) => {
export const prepareMetricsData = (schema: any) => {
const metricBreakdown: any[] = [];
const metricSeries: any[] = [];
const metricDimension: any[] = [];
Expand Down
1 change: 1 addition & 0 deletions public/components/event_analytics/explorer/explorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ export const Explorer = ({

const fetchData = async (startingTime?: string, endingTime?: string) => {
const curQuery: IQuery = queryRef.current!;
console.log('fetchData', { defaultConfig: getDefaultVisConfig() });
new PPLDataFetcher(
{ ...curQuery },
{ batch, dispatch, changeQuery, changeVizConfig },
Expand Down
54 changes: 25 additions & 29 deletions public/components/visualizations/charts/lines/line.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { hexToRgb } from '../../../../components/event_analytics/utils/utils';
import { AvailabilityUnitType } from '../../../event_analytics/explorer/visualizations/config_panel/config_panes/config_controls/config_availability';
import { ThresholdUnitType } from '../../../event_analytics/explorer/visualizations/config_panel/config_panes/config_controls/config_thresholds';
import { Plt } from '../../plotly/plot';
import { preprocessJsonData, transformPreprocessedDataToTraces } from '../shared/common';

// send both query and exampler data through getVizContainerProps rawdata and try to get it here in data of line 40. print it and see.
// If it doesn't work then use redux to get the data here
Expand Down Expand Up @@ -86,22 +87,22 @@ export const Line = ({ visualizations, layout, config }: any) => {
colorTheme.find((colorSelected) => colorSelected.name.name === field)?.color) ||
PLOTLY_COLOR[index % PLOTLY_COLOR.length];

const checkIfMetrics = (metricsSchema: any) => {
if (isEmpty(metricsSchema)) return {};
const isMetricQuery = () => {
if (isEmpty(schema)) return {};
if (
metricsSchema.length === 3 &&
metricsSchema.every((schemaField) =>
['@labels', '@value', '@timestamp'].includes(schemaField.name)
)
schema.length === 3 &&
schema.every((schemaField) => ['@labels', '@value', '@timestamp'].includes(schemaField.name))
) {
return true;
}
return false;
};

const preprocessMetricsJsonData = (json): any => {
const preprocessMetricsJsonData = (): any => {
if (!isMetricQuery()) return [];

const data: any[] = [];
_.forEach(json, (row) => {
_.forEach(jsonData, (row) => {
const record: any = {};
record['@labels'] = JSON.parse(row['@labels']);
record['@timestamp'] = JSON.parse(row['@timestamp']);
Expand All @@ -110,7 +111,7 @@ export const Line = ({ visualizations, layout, config }: any) => {
});
return data;
};
const formattedMetricsJson = preprocessMetricsJsonData(jsonData);
const formattedMetricsJson = preprocessMetricsJsonData();

const addStylesToTraces = (traces, traceStyles) => {
const {
Expand Down Expand Up @@ -181,27 +182,22 @@ export const Line = ({ visualizations, layout, config }: any) => {
y_coordinate: 'y',
};

// return addStylesToTraces(
// transformPreprocessedDataToTraces(
// preprocessJsonData(jsonData, visConfig),
// visConfig,
// lineSpecficMetaData
// ),
// traceStyles
// );
const traceData = isMetricQuery()
? formattedMetricsJson.map((trace) => {
return {
...trace,
x: trace['@timestamp'],
y: trace['@value'],
name: JSON.stringify(trace['@labels']),
};
})
: transformPreprocessedDataToTraces(
preprocessJsonData(jsonData, visConfig),
visConfig,
lineSpecficMetaData
);

const result = addStylesToTraces(
formattedMetricsJson.map((trace) => {
return {
...trace,
x: trace['@timestamp'],
y: trace['@value'],
name: JSON.stringify(trace['@labels']),
};
}),
traceStyles
);
return result;
return addStylesToTraces(traceData, traceStyles);
}, [
chartStyles,
// jsonData,
Expand Down

0 comments on commit 2b44603

Please sign in to comment.