@Test public void testRegexLevel2() { List<String> terms = Arrays.asList("foo", "bar", "baz", "foo.bar", "foo.bar.baz", "foo.bar.baz.qux", "foo.bar.baz.qux.quux"); List<String> matchingTerms = new ArrayList<>(); Pattern patternToGet2Levels = Pattern.compile(elasticTokensIO.getRegexToHandleTokens(new GlobPattern("foo.bar.*"))); for (String term: terms) { Matcher matcher = patternToGet2Levels.matcher(term); if (matcher.matches()) { matchingTerms.add(term); } } assertEquals(1, matchingTerms.size()); assertEquals("foo.bar.baz", matchingTerms.get(0)); }
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)); }
ElasticTokensIO implements TokenDiscoveryIO { 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)); } }
ElasticTokensIO implements TokenDiscoveryIO { 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)); } ElasticTokensIO(); }
ElasticTokensIO implements TokenDiscoveryIO { 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)); } ElasticTokensIO(); @Override void insertDiscovery(Token token); @Override void insertDiscovery(List<Token> tokens); @Override List<MetricName> getMetricNames(String tenantId, String query); }
ElasticTokensIO implements TokenDiscoveryIO { 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)); } ElasticTokensIO(); @Override void insertDiscovery(Token token); @Override void insertDiscovery(List<Token> tokens); @Override List<MetricName> getMetricNames(String tenantId, String query); static final String ES_DOCUMENT_TYPE; static String ELASTICSEARCH_TOKEN_INDEX_NAME_WRITE; static String ELASTICSEARCH_TOKEN_INDEX_NAME_READ; public ElasticsearchRestHelper elasticsearchRestHelper; }