From a3c9d79641e62369f85abea267383b257b5df921 Mon Sep 17 00:00:00 2001 From: munishchouhan Date: Thu, 25 Apr 2024 11:22:52 +0200 Subject: [PATCH] pattern moved to MetricsServiceImpl --- .../counter/impl/LocalCounterProvider.groovy | 4 +--- .../counter/impl/RedisCounterProvider.groovy | 2 +- .../metric/impl/MetricsServiceImpl.groovy | 4 +--- .../impl/LocalCounterProviderTest.groovy | 18 +++++++++--------- .../impl/RedisCounterProviderTest.groovy | 18 +++++++++--------- 5 files changed, 21 insertions(+), 25 deletions(-) diff --git a/src/main/groovy/io/seqera/wave/service/counter/impl/LocalCounterProvider.groovy b/src/main/groovy/io/seqera/wave/service/counter/impl/LocalCounterProvider.groovy index 8b94fe4da..0b563deb5 100644 --- a/src/main/groovy/io/seqera/wave/service/counter/impl/LocalCounterProvider.groovy +++ b/src/main/groovy/io/seqera/wave/service/counter/impl/LocalCounterProvider.groovy @@ -50,9 +50,7 @@ class LocalCounterProvider implements CounterProvider { @Override Map getAllMatchingEntries(String key, String pattern) { def keyStore = store.get(key) - def matchingPairs = keyStore.findAll { k, v -> - k.contains(pattern) - } + def matchingPairs = keyStore.findAll { k, v -> k =~pattern} Map result = [:] matchingPairs.each { k, v -> result.put(k, v as Long) diff --git a/src/main/groovy/io/seqera/wave/service/counter/impl/RedisCounterProvider.groovy b/src/main/groovy/io/seqera/wave/service/counter/impl/RedisCounterProvider.groovy index 873bf25f9..2635664dc 100644 --- a/src/main/groovy/io/seqera/wave/service/counter/impl/RedisCounterProvider.groovy +++ b/src/main/groovy/io/seqera/wave/service/counter/impl/RedisCounterProvider.groovy @@ -57,7 +57,7 @@ class RedisCounterProvider implements CounterProvider { Map getAllMatchingEntries(String key, String pattern) { try(Jedis conn=pool.getResource() ) { Map result = [:] - def scanResult = conn.hscan(key, "0", new ScanParams().match("$pattern*")) + def scanResult = conn.hscan(key, "0", new ScanParams().match(pattern)) for(String entry : scanResult.result) { def parts = entry.split('=') result.put(parts[0], parts[1] as Long) diff --git a/src/main/groovy/io/seqera/wave/service/metric/impl/MetricsServiceImpl.groovy b/src/main/groovy/io/seqera/wave/service/metric/impl/MetricsServiceImpl.groovy index a000c63a0..9f870b089 100644 --- a/src/main/groovy/io/seqera/wave/service/metric/impl/MetricsServiceImpl.groovy +++ b/src/main/groovy/io/seqera/wave/service/metric/impl/MetricsServiceImpl.groovy @@ -63,10 +63,8 @@ class MetricsServiceImpl implements MetricsService { @Override GetOrgCountResponse getOrgCount(String metrics){ GetOrgCountResponse response = new GetOrgCountResponse(metrics, 0, [:]) - def orgCounts = metricsCounterStore.getAllMatchingEntries("$metrics/$MetricConstants.PREFIX_ORG") - log.info("Found ${orgCounts.size()} orgs for key: $metrics/$MetricConstants.PREFIX_ORG") + def orgCounts = metricsCounterStore.getAllMatchingEntries("$metrics/$MetricConstants.PREFIX_ORG/*") for(def entry : orgCounts) { - log.info(entry.key+" -> "+entry.value) if(!entry.key.contains("/$MetricConstants.PREFIX_DAY/")) { response.count += entry.value response.orgs.put(entry.key.split("/$MetricConstants.PREFIX_ORG/").last(), entry.value) diff --git a/src/test/groovy/io/seqera/wave/service/counter/impl/LocalCounterProviderTest.groovy b/src/test/groovy/io/seqera/wave/service/counter/impl/LocalCounterProviderTest.groovy index 1ca388b60..5573377fe 100644 --- a/src/test/groovy/io/seqera/wave/service/counter/impl/LocalCounterProviderTest.groovy +++ b/src/test/groovy/io/seqera/wave/service/counter/impl/LocalCounterProviderTest.groovy @@ -56,17 +56,17 @@ class LocalCounterProviderTest extends Specification { def 'should get correct org count' () { when: - localCounterProvider.inc('metrics/v1', '/builds/o/foo', 1) - localCounterProvider.inc('metrics/v1', '/builds/o/bar', 1) - localCounterProvider.inc('metrics/v1', '/builds/o/abc', 2) - localCounterProvider.inc('metrics/v1', '/pulls/o/foo', 1) - localCounterProvider.inc('metrics/v1', '/pulls/o/bar', 2) - localCounterProvider.inc('metrics/v1', '/pulls/o/abc', 3) - localCounterProvider.inc('metrics/v1', '/pulls/o/abc/date/yyyy-mm-dd', 1) + localCounterProvider.inc('metrics/v1', 'builds/o/foo.com', 1) + localCounterProvider.inc('metrics/v1', 'builds/o/bar.io', 1) + localCounterProvider.inc('metrics/v1', 'builds/o/abc.org', 2) + localCounterProvider.inc('metrics/v1', 'pulls/o/foo.it', 1) + localCounterProvider.inc('metrics/v1', 'pulls/o/bar.es', 2) + localCounterProvider.inc('metrics/v1', 'pulls/o/abc.in', 3) + localCounterProvider.inc('metrics/v1', 'pulls/o/abc.com.au/date/yyyy-mm-dd', 1) then: - localCounterProvider.getAllMatchingEntries('metrics/v1', '/pulls/o') == - ['/pulls/o/foo':1, '/pulls/o/bar':2, '/pulls/o/abc':3, '/pulls/o/abc/date/yyyy-mm-dd': 1] + localCounterProvider.getAllMatchingEntries('metrics/v1', 'pulls/o/*') == + ['pulls/o/foo.it':1, 'pulls/o/bar.es':2, 'pulls/o/abc.in':3, 'pulls/o/abc/date/yyyy-mm-dd': 1] } } diff --git a/src/test/groovy/io/seqera/wave/service/counter/impl/RedisCounterProviderTest.groovy b/src/test/groovy/io/seqera/wave/service/counter/impl/RedisCounterProviderTest.groovy index cb263e7e5..954df128c 100644 --- a/src/test/groovy/io/seqera/wave/service/counter/impl/RedisCounterProviderTest.groovy +++ b/src/test/groovy/io/seqera/wave/service/counter/impl/RedisCounterProviderTest.groovy @@ -66,16 +66,16 @@ class RedisCounterProviderTest extends Specification implements RedisTestContain def 'should get correct org count' () { when: - redisCounterProvider.inc('metrics/v1', 'builds/o/foo', 1) - redisCounterProvider.inc('metrics/v1', 'builds/o/bar', 1) - redisCounterProvider.inc('metrics/v1', 'builds/o/abc', 2) - redisCounterProvider.inc('metrics/v1', 'pulls/o/foo', 1) - redisCounterProvider.inc('metrics/v1', 'pulls/o/bar', 2) - redisCounterProvider.inc('metrics/v1', 'pulls/o/abc', 3) - redisCounterProvider.inc('metrics/v1', 'pulls/o/abc/date/yyyy-mm-dd', 1) + redisCounterProvider.inc('metrics/v1', 'builds/o/foo.com', 1) + redisCounterProvider.inc('metrics/v1', 'builds/o/bar.org', 1) + redisCounterProvider.inc('metrics/v1', 'builds/o/abc.it', 2) + redisCounterProvider.inc('metrics/v1', 'pulls/o/foo.es', 1) + redisCounterProvider.inc('metrics/v1', 'pulls/o/bar.in', 2) + redisCounterProvider.inc('metrics/v1', 'pulls/o/abc.au', 3) + redisCounterProvider.inc('metrics/v1', 'pulls/o/abc.com/date/yyyy-mm-dd', 1) then: - redisCounterProvider.getAllMatchingEntries('metrics/v1', 'pulls/o') == - ['pulls/o/foo':1, 'pulls/o/bar':2, 'pulls/o/abc':3, 'pulls/o/abc/date/yyyy-mm-dd': 1] + redisCounterProvider.getAllMatchingEntries('metrics/v1', 'pulls/o/*') == + ['pulls/o/foo.es':1, 'pulls/o/bar.in':2, 'pulls/o/abc.au':3, 'pulls/o/abc.com/date/yyyy-mm-dd': 1] } }