|
1 | 1 | import React, { useEffect, useMemo, useState } from "react";
|
2 |
| -import { Field } from '@grafana/data'; |
| 2 | +// import { Field } from '@grafana/data'; |
3 | 3 | import { CollapsableSection } from '@grafana/ui';
|
4 | 4 | import { LogContextProps } from "./LogContextUI";
|
5 | 5 | import { css } from "@emotion/css";
|
6 | 6 | import { QuickwitQuery } from 'LogContext/QueryBuilder';
|
7 | 7 |
|
8 |
| -const filterFields = [ |
9 |
| - 'attributes.appname', |
10 |
| - 'attributes.proc_id', |
11 |
| - 'attributes.hostname', |
12 |
| - 'attributes.priority', |
13 |
| - 'severity_number', |
14 |
| - 'severity_text' |
| 8 | + |
| 9 | +// TODO : define sensible defaults here |
| 10 | +const excludedFields = [ |
| 11 | + '_source', |
| 12 | + 'sort', |
| 13 | + 'attributes', |
| 14 | + 'attributes.message', |
| 15 | + 'body', |
| 16 | + 'body.message', |
| 17 | + 'observed_timestamp_nanos', |
| 18 | + 'timestamp_nanos', |
15 | 19 | ];
|
16 | 20 |
|
17 | 21 | type FieldContingency = { [value: string]: {
|
@@ -69,29 +73,33 @@ export function LogContextQueryBuilderSidebar(props: LogContextProps & QueryBuil
|
69 | 73 |
|
70 | 74 | const {row, parsedQuery, updateQuery} = props;
|
71 | 75 | const [fields, setFields] = useState<Array<{ name: string; contingency: FieldContingency; }>>([]);
|
| 76 | + |
| 77 | + |
72 | 78 | const filteredFields = useMemo(() => (
|
73 |
| - row.dataFrame.fields.filter((f: Field) => (filterFields.includes(f.name))) |
| 79 | + row.dataFrame.fields |
| 80 | + // sort fields by name |
| 81 | + .sort((f1, f2)=> (f1.name>f2.name ? 1 : -1)) |
| 82 | + // exclude some low-filterability fields |
| 83 | + .filter((f)=> !excludedFields.includes(f.name) |
| 84 | + ) |
74 | 85 | ), [row.dataFrame.fields]);
|
75 | 86 |
|
76 |
| - |
77 | 87 | useEffect(() => {
|
78 |
| - const fields = filteredFields.map((f) => { |
79 |
| - const contingency: FieldContingency = {}; |
80 |
| - |
81 |
| - f.values.toArray().forEach((attrName, i) => { |
82 |
| - if (!contingency[attrName]) { |
83 |
| - contingency[attrName] = { |
84 |
| - count: 0, |
85 |
| - pinned: i === row.rowIndex, |
86 |
| - active: parsedQuery ? parsedQuery.findFilter(`${f.name}:\"${attrName}\"`) > -1 : false |
| 88 | + const fields = filteredFields |
| 89 | + .map((f) => { |
| 90 | + const contingency: FieldContingency = {}; |
| 91 | + f.values.toArray().forEach((attrName, i) => { |
| 92 | + if (!contingency[attrName]) { |
| 93 | + contingency[attrName] = { |
| 94 | + count: 0, |
| 95 | + pinned: i === row.rowIndex, |
| 96 | + active: parsedQuery ? parsedQuery.findFilter(`${f.name}:\"${attrName}\"`) > -1 : false |
| 97 | + } |
87 | 98 | }
|
88 |
| - } |
89 |
| - contingency[attrName].count += 1; |
90 |
| - }); |
91 |
| - return { |
92 |
| - name: f.name, |
93 |
| - contingency }; |
94 |
| - }) |
| 99 | + contingency[attrName].count += 1; |
| 100 | + }); |
| 101 | + return { name: f.name, contingency }; |
| 102 | + }) |
95 | 103 |
|
96 | 104 | setFields(fields);
|
97 | 105 | }, [filteredFields, row.rowIndex, parsedQuery]);
|
|
0 commit comments