mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
CloudWatch/Logs: Fix fields not being refetched when log group changed (#24529)
This commit is contained in:
parent
cb74bc6828
commit
55533d12fd
@ -117,17 +117,41 @@ export class CloudWatchLanguageProvider extends LanguageProvider {
|
||||
};
|
||||
}
|
||||
|
||||
private fetchFields = _.throttle(async (logGroups: string[]) => {
|
||||
private fetchedFieldsCache:
|
||||
| {
|
||||
time: number;
|
||||
logGroups: string[];
|
||||
fields: string[];
|
||||
}
|
||||
| undefined;
|
||||
|
||||
private fetchFields = async (logGroups: string[]): Promise<string[]> => {
|
||||
if (
|
||||
this.fetchedFieldsCache &&
|
||||
Date.now() - this.fetchedFieldsCache.time < 30 * 1000 &&
|
||||
_.sortedUniq(this.fetchedFieldsCache.logGroups).join('|') === _.sortedUniq(logGroups).join('|')
|
||||
) {
|
||||
return this.fetchedFieldsCache.fields;
|
||||
}
|
||||
|
||||
const results = await Promise.all(
|
||||
logGroups.map(logGroup => this.datasource.getLogGroupFields({ logGroupName: logGroup }))
|
||||
);
|
||||
|
||||
return [
|
||||
const fields = [
|
||||
...new Set<string>(
|
||||
results.reduce((acc: string[], cur) => acc.concat(cur.logGroupFields?.map(f => f.name) as string[]), [])
|
||||
).values(),
|
||||
];
|
||||
}, 30 * 1000);
|
||||
|
||||
this.fetchedFieldsCache = {
|
||||
time: Date.now(),
|
||||
logGroups,
|
||||
fields,
|
||||
};
|
||||
|
||||
return fields;
|
||||
};
|
||||
|
||||
private handleKeyword = async (context?: TypeaheadContext): Promise<TypeaheadOutput | null> => {
|
||||
const suggs = await this.getFieldCompletionItems(context?.logGroupNames ?? []);
|
||||
|
Loading…
Reference in New Issue
Block a user