From 7f0d28abf5f4ada537ee1c7f395cea029fe0a62b Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Tue, 20 Apr 2021 13:02:31 +0100 Subject: [PATCH] Fix inefficient regular expression (#33155) (#33159) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit e017de4f061aab133054cf9622392475d80e8d7d) Co-authored-by: Piotr Jamróz --- .../plugins/datasource/graphite/datasource.ts | 29 +++++-------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/public/app/plugins/datasource/graphite/datasource.ts b/public/app/plugins/datasource/graphite/datasource.ts index 3ba6f3a3bb0..a4cf2ae9ced 100644 --- a/public/app/plugins/datasource/graphite/datasource.ts +++ b/public/app/plugins/datasource/graphite/datasource.ts @@ -335,32 +335,17 @@ export class GraphiteDatasource extends DataSourceApi[,]*), this is used for template variables - let matches = interpolatedQuery.match(/^tag_values\(([^,]+)((, *[^,]+)*)\)$/); - if (matches) { - const expressions = []; - const exprRegex = /, *([^,]+)/g; - let match = exprRegex.exec(matches[2]); - while (match !== null) { - expressions.push(match[1]); - match = exprRegex.exec(matches[2]); - } + let allParams = interpolatedQuery.match(/^tag_values\((.*)\)$/); + let expressions = allParams ? allParams[1].split(',').filter((p) => !!p) : undefined; + if (expressions) { options.limit = 10000; - return this.getTagValuesAutoComplete(expressions, matches[1], undefined, options); + return this.getTagValuesAutoComplete(expressions.slice(1), expressions[0], undefined, options); } // special handling for tags([,]*), this is used for template variables - matches = interpolatedQuery.match(/^tags\(([^,]*)((, *[^,]+)*)\)$/); - if (matches) { - const expressions = []; - if (matches[1]) { - expressions.push(matches[1]); - const exprRegex = /, *([^,]+)/g; - let match = exprRegex.exec(matches[2]); - while (match !== null) { - expressions.push(match[1]); - match = exprRegex.exec(matches[2]); - } - } + allParams = interpolatedQuery.match(/^tags\((.*)\)$/); + expressions = allParams ? allParams[1].split(',').filter((p) => !!p) : undefined; + if (expressions) { options.limit = 10000; return this.getTagsAutoComplete(expressions, undefined, options); }