/** * For a given glob, gives regex for {@code Locator.METRIC_TOKEN_SEPARATOR} separated tokens * * For example: * globPattern of foo.*.* would produce a regex foo\.[^.]+\.[^.]+ * globPattern of foo.b*.* would produce a regex foo\.b[^.]*\.[^.]+ * * @param globPattern * @return */ protected String getRegexToHandleTokens(GlobPattern globPattern) { String[] queryRegexParts = globPattern.compiled().toString().split("\\\\."); return Arrays.stream(queryRegexParts) .map(this::convertRegexToCaptureUptoNextToken) .collect(joining(Locator.METRIC_TOKEN_SEPARATOR_REGEX)); }
/** * For a given glob, gives regex for {@code Locator.METRIC_TOKEN_SEPARATOR} separated tokens * * For example: * globPattern of foo.*.* would produce a regex foo\.[^.]+\.[^.]+ * globPattern of foo.b*.* would produce a regex foo\.b[^.]*\.[^.]+ * * @param globPattern * @return */ protected String getRegexToHandleTokens(GlobPattern globPattern) { String[] queryRegexParts = globPattern.compiled().toString().split("\\\\."); return Arrays.stream(queryRegexParts) .map(this::convertRegexToCaptureUptoNextToken) .collect(joining(Locator.METRIC_TOKEN_SEPARATOR_REGEX)); }
private String getRegex(String glob) { GlobPattern pattern = new GlobPattern(glob); return pattern.compiled().toString(); }
private String getQueryDslString(String tenantId, List<String> queries){ List<String> mustStrings = new ArrayList<>(); String tenantIdQString = getTermQueryString(ESFieldLabel.tenantId.toString(), tenantId); mustStrings.add(tenantIdQString); String mustValueString = getMustValueString(mustStrings); List<String> shouldStrings = new ArrayList<>(); for(String query : queries) { String metricNameQString; GlobPattern pattern = new GlobPattern(query); if (pattern.hasWildcard()) { String compiledString = pattern.compiled().toString(); // replace one '\' char with two '\\' compiledString = compiledString.replaceAll("\\\\", "\\\\\\\\"); metricNameQString = getRegexpQueryString(ESFieldLabel.metric_name.toString(), compiledString); } else { metricNameQString = getTermQueryString(ESFieldLabel.metric_name.toString(), query); } shouldStrings.add(metricNameQString); } String shouldValueString = getShouldValueString(shouldStrings); String dslString = getBoolQueryString(mustValueString, shouldValueString); return dslString; }
String compiledString = pattern.compiled().toString(); tokenQString = getRegexpQueryString(ESFieldLabel.token.name(), compiledString); } else {