Skip to content

Commit e30f885

Browse files
authored
Merge pull request #69 from quickwit-oss/fmassot/custom-display-message
Add support for displaying multiple fields. Remove _source from the d…
2 parents 9524b4f + 10817a2 commit e30f885

File tree

2 files changed

+40
-20
lines changed

2 files changed

+40
-20
lines changed

pkg/quickwit/response_parser.go

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ func processLogsResponse(res *es.SearchResponse, target *Query, configuredFields
106106
}
107107

108108
doc := map[string]interface{}{
109-
"_source": flattened,
110-
"sort": hit["sort"],
109+
"sort": hit["sort"],
111110
}
112111

113112
for k, v := range flattened {
@@ -118,15 +117,6 @@ func processLogsResponse(res *es.SearchResponse, target *Query, configuredFields
118117
}
119118
}
120119

121-
if hit["fields"] != nil {
122-
source, ok := hit["fields"].(map[string]interface{})
123-
if ok {
124-
for k, v := range source {
125-
doc[k] = v
126-
}
127-
}
128-
}
129-
130120
for key := range doc {
131121
propNames[key] = true
132122
}
@@ -1066,25 +1056,18 @@ func flatten(target map[string]interface{}) map[string]interface{} {
10661056
// if shouldSortLogMessageField is true, and rest of propNames are ordered alphabetically
10671057
func sortPropNames(propNames map[string]bool, configuredFields es.ConfiguredFields, shouldSortLogMessageField bool) []string {
10681058
hasTimeField := false
1069-
hasLogMessageField := false
10701059

10711060
var sortedPropNames []string
10721061
for k := range propNames {
10731062
if configuredFields.TimeField != "" && k == configuredFields.TimeField {
10741063
hasTimeField = true
1075-
} else if shouldSortLogMessageField && configuredFields.LogMessageField != "" && k == configuredFields.LogMessageField {
1076-
hasLogMessageField = true
10771064
} else {
10781065
sortedPropNames = append(sortedPropNames, k)
10791066
}
10801067
}
10811068

10821069
sort.Strings(sortedPropNames)
10831070

1084-
if hasLogMessageField {
1085-
sortedPropNames = append([]string{configuredFields.LogMessageField}, sortedPropNames...)
1086-
}
1087-
10881071
if hasTimeField {
10891072
sortedPropNames = append([]string{configuredFields.TimeField}, sortedPropNames...)
10901073
}

src/datasource.ts

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export class QuickwitDataSource
9797
return super.query(request)
9898
.pipe(map((response) => {
9999
response.data.forEach((dataFrame) => {
100-
enhanceDataFrameWithDataLinks(dataFrame, this.dataLinks);
100+
enhanceDataFrameWithDataLinks(dataFrame, this.dataLinks, this.logMessageField);
101101
});
102102
return response;
103103
}));
@@ -738,7 +738,44 @@ function luceneEscape(value: string) {
738738
return value.replace(/([\!\*\+\-\=<>\s\&\|\(\)\[\]\{\}\^\~\?\:\\/"])/g, '\\$1');
739739
}
740740

741-
export function enhanceDataFrameWithDataLinks(dataFrame: DataFrame, dataLinks: DataLinkConfig[]) {
741+
export function enhanceDataFrameWithDataLinks(dataFrame: DataFrame, dataLinks: DataLinkConfig[], logMessageField: string | undefined) {
742+
// Ignore log volume dataframe, no need to add links or a displayed message field.
743+
if (!dataFrame.refId || dataFrame.refId.startsWith('log-volume')) {
744+
return;
745+
}
746+
if (logMessageField) {
747+
const messageFields = logMessageField.split(',');
748+
let field_idx_list = [];
749+
for (const messageField of messageFields) {
750+
const field_idx = dataFrame.fields.findIndex((field) => field.name === messageField);
751+
if (field_idx !== -1) {
752+
field_idx_list.push(field_idx);
753+
}
754+
}
755+
const displayedMessages = Array(dataFrame.length);
756+
for (let idx = 0; idx < dataFrame.length; idx++) {
757+
let displayedMessage = "";
758+
// If we have only one field, we assume the field name is obvious for the user and we don't need to show it.
759+
if (field_idx_list.length === 1) {
760+
displayedMessage = `${dataFrame.fields[field_idx_list[0]].values[idx]}`;
761+
} else {
762+
for (const field_idx of field_idx_list) {
763+
displayedMessage += ` ${dataFrame.fields[field_idx].name}=${dataFrame.fields[field_idx].values[idx]}`;
764+
}
765+
}
766+
displayedMessages[idx] = displayedMessage.trim();
767+
}
768+
769+
const newField = {
770+
name: 'message',
771+
type: FieldType.string,
772+
config: {},
773+
values: displayedMessages,
774+
}
775+
console.log('newField');
776+
dataFrame.fields = [newField, ...dataFrame.fields];
777+
}
778+
742779
if (!dataLinks.length) {
743780
return;
744781
}

0 commit comments

Comments
 (0)