Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare quickwit datasource for quickwit 0.7. #43

Merged
merged 2 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,27 @@ The license for this project is [AGPL-3.0](LICENSE.md), and a [notice](NOTICE.md

We recommand Grafana v9.5 or v10.

Quickwit 0.6 is compatible with 0.2.x versions only.

Quickwit 0.7 is compatible with 0.3.x versions only.


## Installation

### Download the latest release (0.2.4)
### Download the 0.3.0 for Quickwit 0.7

```bash
wget https://github.com/quickwit-oss/quickwit-datasource/releases/download/v0.3.0/quickwit-quickwit-datasource-0.3.0.zip
```

### Unzip into the plugins directory

```bash
mkdir -p grafana-storage/plugins
unzip quickwit-quickwit-datasource-0.3.0.zip -d grafana-storage/plugins
```

### Download the 0.2.4 for Quickwit 0.6

```bash
wget https://github.com/quickwit-oss/quickwit-datasource/releases/download/v0.2.4/quickwit-quickwit-datasource-0.2.4.zip
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "quickwit-datasource",
"version": "0.3.0-beta.3",
"version": "0.3.0",
"description": "Quickwit datasource",
"scripts": {
"build": "webpack -c ./.config/webpack/webpack.config.ts --env production",
Expand Down
9 changes: 4 additions & 5 deletions pkg/quickwit/client/search_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const (
)

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

// FIXME when quickwit supports unmapped_type
// if unmappedType != "" {
// props["unmapped_type"] = unmappedType
// }
if format != "" {
sort[field]["format"] = format
}

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

Expand Down
2 changes: 1 addition & 1 deletion pkg/quickwit/client/search_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestSearchRequest(t *testing.T) {
t.Run("When adding size, sort, filters", func(t *testing.T) {
b := setup()
b.Size(200)
b.Sort(SortOrderDesc, timeField, "boolean")
b.Sort(SortOrderDesc, timeField, "epoch_nanos_int")
filters := b.Query().Bool().Filter()
filters.AddDateRangeFilter(timeField, 1684398201000, 1684308201000)
filters.AddQueryStringFilter("test", true)
Expand Down
4 changes: 2 additions & 2 deletions pkg/quickwit/data_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ func processLogsQuery(q *Query, b *es.SearchRequestBuilder, from, to int64, defa
// This is currently used only for log context query
sort = es.SortOrderAsc
}
b.Sort(sort, defaultTimeField, "boolean")
b.Sort(sort, defaultTimeField, "epoch_nanos_int")
b.Size(stringToIntWithDefaultValue(metric.Settings.Get("limit").MustString(), defaultSize))
// TODO when hightlight is supported in quickwit
// b.AddHighlight()
Expand All @@ -368,7 +368,7 @@ func processLogsQuery(q *Query, b *es.SearchRequestBuilder, from, to int64, defa

func processDocumentQuery(q *Query, b *es.SearchRequestBuilder, from, to int64, defaultTimeField string) {
metric := q.Metrics[0]
b.Sort(es.SortOrderDesc, defaultTimeField, "boolean")
b.Sort(es.SortOrderDesc, defaultTimeField, "epoch_nanos_int")
b.Sort(es.SortOrderDesc, "_doc", "")
// Note: not supported in Quickwit
// b.AddDocValueField(defaultTimeField)
Expand Down
15 changes: 0 additions & 15 deletions src/configuration/DataLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export const DataLink = (props: Props) => {
const { value, onChange, onDelete, suggestions, className } = props;
const styles = useStyles2(getStyles);
const [showInternalLink, setShowInternalLink] = useInternalLink(value.datasourceUid);
const [base64TraceId, setBase64TraceId] = useState(true)
const labelWidth = 24

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

const handleBase64TraceId = (base64TraceId: boolean, config: DataLinkConfig) => {
setBase64TraceId(base64TraceId)
config = {...config, base64TraceId: base64TraceId };
}

return (
<div className={className}>
<div className={styles.firstRow}>
Expand Down Expand Up @@ -73,15 +67,6 @@ export const DataLink = (props: Props) => {
/>
</div>

<div className={styles.row}>
<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.">
<InlineSwitch
value={base64TraceId}
onChange={() => handleBase64TraceId(!base64TraceId, value)}
/>
</InlineField>
</div>

<InlineFieldRow>
<div className={styles.urlField}>
<InlineLabel htmlFor="elasticsearch-datasource-internal-link" width={labelWidth}>
Expand Down
39 changes: 0 additions & 39 deletions src/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { catchError, mergeMap, map } from 'rxjs/operators';

import {
AbstractQuery,
ArrayVector,
CoreApp,
DataFrame,
DataLink,
Expand All @@ -18,7 +17,6 @@ import {
DataSourceWithQueryImportSupport,
DataSourceWithSupplementaryQueriesSupport,
dateTime,
Field,
FieldColorModeId,
FieldType,
getDefaultTimeRange,
Expand Down Expand Up @@ -850,47 +848,10 @@ function luceneEscape(value: string) {
return value.replace(/([\!\*\+\-\=<>\s\&\|\(\)\[\]\{\}\^\~\?\:\\/"])/g, '\\$1');
}

function base64ToHex(base64String: string) {
const binaryString = window.atob(base64String);
return Array.from(binaryString).map(char => {
const byte = char.charCodeAt(0);
return ('0' + byte.toString(16)).slice(-2);
}).join('');
}

export function enhanceDataFrameWithDataLinks(dataFrame: DataFrame, dataLinks: DataLinkConfig[]) {
if (!dataLinks.length) {
return;
}
let fields_to_fix_condition = (field: Field) => {
return dataLinks.filter((dataLink) => dataLink.field === field.name && dataLink.base64TraceId).length === 1;
};
const fields_to_keep = dataFrame.fields.filter((field) => {
return !fields_to_fix_condition(field)
});
let new_fields = dataFrame
.fields
.filter(fields_to_fix_condition)
.map((field) => {
let values = field.values.toArray().map((value) => {
try {
return base64ToHex(value);
} catch (e) {
console.warn("cannot convert value from base64 to hex", e);
return value;
};
});
return {
...field,
values: new ArrayVector(values),
}
});

if (new_fields.length === 0) {
return;
}

dataFrame.fields = [new_fields[0], ...fields_to_keep];

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