Skip to content

Commit f587e89

Browse files
committed
Prepare quickwit datasource for quickwit 0.7.
1 parent 6946a39 commit f587e89

File tree

5 files changed

+7
-62
lines changed

5 files changed

+7
-62
lines changed

pkg/quickwit/client/search_request.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ const (
8181
)
8282

8383
// Sort adds a "asc" | "desc" sort to the search request
84-
func (b *SearchRequestBuilder) Sort(order SortOrder, field string, unmappedType string) *SearchRequestBuilder {
84+
func (b *SearchRequestBuilder) Sort(order SortOrder, field string, format string) *SearchRequestBuilder {
8585
if order != SortOrderAsc && order != SortOrderDesc {
8686
return b
8787
}
@@ -91,10 +91,9 @@ func (b *SearchRequestBuilder) Sort(order SortOrder, field string, unmappedType
9191
"order": string(order),
9292
}
9393

94-
// FIXME when quickwit supports unmapped_type
95-
// if unmappedType != "" {
96-
// props["unmapped_type"] = unmappedType
97-
// }
94+
if format != "" {
95+
sort[field]["format"] = format
96+
}
9897

9998
b.sort = append(b.sort, sort)
10099

pkg/quickwit/client/search_request_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func TestSearchRequest(t *testing.T) {
4545
t.Run("When adding size, sort, filters", func(t *testing.T) {
4646
b := setup()
4747
b.Size(200)
48-
b.Sort(SortOrderDesc, timeField, "boolean")
48+
b.Sort(SortOrderDesc, timeField, "epoch_nanos_int")
4949
filters := b.Query().Bool().Filter()
5050
filters.AddDateRangeFilter(timeField, 1684398201000, 1684308201000)
5151
filters.AddQueryStringFilter("test", true)

pkg/quickwit/data_query.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ func processLogsQuery(q *Query, b *es.SearchRequestBuilder, from, to int64, defa
353353
// This is currently used only for log context query
354354
sort = es.SortOrderAsc
355355
}
356-
b.Sort(sort, defaultTimeField, "boolean")
356+
b.Sort(sort, defaultTimeField, "epoch_nanos_int")
357357
b.Size(stringToIntWithDefaultValue(metric.Settings.Get("limit").MustString(), defaultSize))
358358
// TODO when hightlight is supported in quickwit
359359
// b.AddHighlight()
@@ -368,7 +368,7 @@ func processLogsQuery(q *Query, b *es.SearchRequestBuilder, from, to int64, defa
368368

369369
func processDocumentQuery(q *Query, b *es.SearchRequestBuilder, from, to int64, defaultTimeField string) {
370370
metric := q.Metrics[0]
371-
b.Sort(es.SortOrderDesc, defaultTimeField, "boolean")
371+
b.Sort(es.SortOrderDesc, defaultTimeField, "epoch_nanos_int")
372372
b.Sort(es.SortOrderDesc, "_doc", "")
373373
// Note: not supported in Quickwit
374374
// b.AddDocValueField(defaultTimeField)

src/configuration/DataLink.tsx

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export const DataLink = (props: Props) => {
3030
const { value, onChange, onDelete, suggestions, className } = props;
3131
const styles = useStyles2(getStyles);
3232
const [showInternalLink, setShowInternalLink] = useInternalLink(value.datasourceUid);
33-
const [base64TraceId, setBase64TraceId] = useState(true)
3433
const labelWidth = 24
3534

3635
const handleChange = (field: keyof typeof value) => (event: React.ChangeEvent<HTMLInputElement>) => {
@@ -40,11 +39,6 @@ export const DataLink = (props: Props) => {
4039
});
4140
};
4241

43-
const handleBase64TraceId = (base64TraceId: boolean, config: DataLinkConfig) => {
44-
setBase64TraceId(base64TraceId)
45-
config = {...config, base64TraceId: base64TraceId };
46-
}
47-
4842
return (
4943
<div className={className}>
5044
<div className={styles.firstRow}>
@@ -73,15 +67,6 @@ export const DataLink = (props: Props) => {
7367
/>
7468
</div>
7569

76-
<div className={styles.row}>
77-
<InlineField label="Field encoded in base64?" labelWidth={labelWidth} tooltip="Must be at true if your trace ID is encoded in base64. This is the case for the `otel-traces-v0_6` index.">
78-
<InlineSwitch
79-
value={base64TraceId}
80-
onChange={() => handleBase64TraceId(!base64TraceId, value)}
81-
/>
82-
</InlineField>
83-
</div>
84-
8570
<InlineFieldRow>
8671
<div className={styles.urlField}>
8772
<InlineLabel htmlFor="elasticsearch-datasource-internal-link" width={labelWidth}>

src/datasource.ts

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { catchError, mergeMap, map } from 'rxjs/operators';
44

55
import {
66
AbstractQuery,
7-
ArrayVector,
87
CoreApp,
98
DataFrame,
109
DataLink,
@@ -18,7 +17,6 @@ import {
1817
DataSourceWithQueryImportSupport,
1918
DataSourceWithSupplementaryQueriesSupport,
2019
dateTime,
21-
Field,
2220
FieldColorModeId,
2321
FieldType,
2422
getDefaultTimeRange,
@@ -850,47 +848,10 @@ function luceneEscape(value: string) {
850848
return value.replace(/([\!\*\+\-\=<>\s\&\|\(\)\[\]\{\}\^\~\?\:\\/"])/g, '\\$1');
851849
}
852850

853-
function base64ToHex(base64String: string) {
854-
const binaryString = window.atob(base64String);
855-
return Array.from(binaryString).map(char => {
856-
const byte = char.charCodeAt(0);
857-
return ('0' + byte.toString(16)).slice(-2);
858-
}).join('');
859-
}
860-
861851
export function enhanceDataFrameWithDataLinks(dataFrame: DataFrame, dataLinks: DataLinkConfig[]) {
862852
if (!dataLinks.length) {
863853
return;
864854
}
865-
let fields_to_fix_condition = (field: Field) => {
866-
return dataLinks.filter((dataLink) => dataLink.field === field.name && dataLink.base64TraceId).length === 1;
867-
};
868-
const fields_to_keep = dataFrame.fields.filter((field) => {
869-
return !fields_to_fix_condition(field)
870-
});
871-
let new_fields = dataFrame
872-
.fields
873-
.filter(fields_to_fix_condition)
874-
.map((field) => {
875-
let values = field.values.toArray().map((value) => {
876-
try {
877-
return base64ToHex(value);
878-
} catch (e) {
879-
console.warn("cannot convert value from base64 to hex", e);
880-
return value;
881-
};
882-
});
883-
return {
884-
...field,
885-
values: new ArrayVector(values),
886-
}
887-
});
888-
889-
if (new_fields.length === 0) {
890-
return;
891-
}
892-
893-
dataFrame.fields = [new_fields[0], ...fields_to_keep];
894855

895856
for (const field of dataFrame.fields) {
896857
const linksToApply = dataLinks.filter((dataLink) => dataLink.field === field.name);

0 commit comments

Comments
 (0)