Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evict wave usage metrics after 120 days #565

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
909bda1
added deleteAllMatchingEntries
munishchouhan Jul 15, 2024
0c986e5
Merge branch 'master' into 562-evict-metrics-from-redis-after-120-days
munishchouhan Jul 16, 2024
6da3b49
test for expiry
munishchouhan Jul 16, 2024
e787bc6
test for expiry
munishchouhan Jul 16, 2024
f58f28c
corrected tests
munishchouhan Jul 16, 2024
636a90f
bump redis.clients:jedis:5.1.3
munishchouhan Jul 16, 2024
ac6dc7d
added failing and success expire test
munishchouhan Jul 17, 2024
abd522a
minor change [ci skip]
munishchouhan Jul 17, 2024
cf6dce8
Merge branch 'master' into 562-evict-metrics-from-redis-after-120-days
munishchouhan Jul 22, 2024
936568b
Merge branch 'master' into 562-evict-metrics-from-redis-after-120-days
munishchouhan Aug 2, 2024
8a096aa
Merge branch 'master' into 562-evict-metrics-from-redis-after-120-days
munishchouhan Aug 14, 2024
d695686
added hexpire and bumped jedis to 5.2.0-beta4
munishchouhan Aug 14, 2024
3399bd2
bump jedis to 5.2.0-beta4
munishchouhan Aug 14, 2024
f8849d7
only date metrics expire
munishchouhan Aug 14, 2024
99eab0f
Merge branch 'master' into 562-evict-metrics-from-redis-after-120-days
munishchouhan Aug 20, 2024
cb27396
Merge branch 'master' into 562-evict-metrics-from-redis-after-120-days
munishchouhan Aug 28, 2024
8e963c8
bump redis.clients:jedis:5.2.0-beta5
munishchouhan Sep 24, 2024
0336b1b
Merge branch 'master' into 562-evict-metrics-from-redis-after-120-days
munishchouhan Sep 24, 2024
a0f273f
Merge branch 'master' into 562-evict-metrics-from-redis-after-120-days
munishchouhan Oct 2, 2024
afb801b
bump redis.clients:jedis:5.2.0
munishchouhan Oct 2, 2024
c99f246
Merge branch 'master' into 562-evict-metrics-from-redis-after-120-days
munishchouhan Oct 2, 2024
88d1f28
Merge branch 'master' into 562-evict-metrics-from-redis-after-120-days
munishchouhan Oct 8, 2024
413aa46
Merge branch 'master' into 562-evict-metrics-from-redis-after-120-days
munishchouhan Oct 8, 2024
df09602
Merge branch 'master' into 562-evict-metrics-from-redis-after-120-days
munishchouhan Oct 10, 2024
2ff6cb5
Merge branch 'master' into 562-evict-metrics-from-redis-after-120-days
munishchouhan Oct 15, 2024
e844f47
Merge branch 'master' into 562-evict-metrics-from-redis-after-120-days
munishchouhan Oct 17, 2024
b0f899f
Merge branch 'master' into 562-evict-metrics-from-redis-after-120-days
munishchouhan Oct 22, 2024
44dbf80
Merge branch 'master' into 562-evict-metrics-from-redis-after-120-days
munishchouhan Nov 6, 2024
759f074
Merge branch 'master' into 562-evict-metrics-from-redis-after-120-days
munishchouhan Nov 19, 2024
70e3ba4
Merge branch 'master' into 562-evict-metrics-from-redis-after-120-days
munishchouhan Dec 4, 2024
46880e2
Merge branch 'master' into 562-evict-metrics-from-redis-after-120-days
munishchouhan Jan 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ dependencies {
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml'
implementation 'com.squareup.moshi:moshi:1.15.1'
implementation 'com.squareup.moshi:moshi-adapters:1.15.1'
implementation 'redis.clients:jedis:5.1.3'
implementation 'redis.clients:jedis:5.2.0'
implementation 'io.github.resilience4j:resilience4j-ratelimiter:0.17.0'
implementation 'io.micronaut:micronaut-retry'
// caching deps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,9 @@ abstract class AbstractCounterStore implements CounterStore {
Map<String, Long> getAllMatchingEntries(String pattern) {
provider.getAllMatchingEntries(getPrefix(), pattern)
}

@Override
void deleteAllMatchingEntries(String pattern) {
provider.getAllMatchingEntries(getPrefix(), pattern)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,10 @@ interface CounterStore {
* @return all the entries whose field matches 'pattern'
*/
Map<String, Long> getAllMatchingEntries(String pattern)

/**
* @param pattern
* @return void
*/
void deleteAllMatchingEntries(String pattern)
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ interface CounterProvider {
* @return all the entries whose field matches 'pattern'
*/
Map<String, Long> getAllMatchingEntries(String key, String pattern)

}
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,5 @@ class LocalCounterProvider implements CounterProvider {
}
return result
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

package io.seqera.wave.service.counter.impl

import java.time.Duration

import groovy.transform.CompileStatic
import io.micronaut.context.annotation.Requires
import io.micronaut.context.annotation.Value
Expand All @@ -42,10 +44,21 @@ class RedisCounterProvider implements CounterProvider {
@Value('${redis.hscan.count:10000}')
private Integer hscanCount

@Value('${redis.key.expiry:1s}')
private Duration keyExpiry

final private static String DATE_PATTERN = /\b\d{4}-\d{2}-\d{2}\b/

static boolean isMetricPerDate(String field) {
return field =~ DATE_PATTERN
}
@Override
long inc(String key, String field, long value) {
try(Jedis conn=pool.getResource() ) {
return conn.hincrBy(key, field, value)
long count = conn.hincrBy(key, field, value)
if(isMetricPerDate(field))
conn.hexpire(key, keyExpiry.toSeconds(), field)
return count
}
}

Expand All @@ -70,4 +83,5 @@ class RedisCounterProvider implements CounterProvider {
return result
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class RedisCounterProviderTest extends Specification implements RedisTestContain
def setup() {
applicationContext = ApplicationContext.run([
REDIS_HOST : redisHostName,
REDIS_PORT : redisPort
REDIS_PORT : redisPort,
'redis.key.expiry': '1s'
], 'test', 'redis')
redisCounterProvider = applicationContext.getBean(RedisCounterProvider)
sleep(500) // workaround to wait for Redis connection
Expand Down Expand Up @@ -85,9 +86,22 @@ class RedisCounterProviderTest extends Specification implements RedisTestContain
then:
redisCounterProvider.getAllMatchingEntries('metrics/v1', 'pulls/o/*') ==
['pulls/o/abc.in':3, 'pulls/o/bar.es':2, 'pulls/o/foo.it':1, 'pulls/o/abc.com.au/d/2024-05-30':1, 'pulls/o/abc.com.au/d/2024-05-31':1]
}

def 'should expire the hash'(){
when:
redisCounterProvider.inc('metrics/v1', 'pulls/o/abc.com.au', 1)
redisCounterProvider.inc('metrics/v1', 'pulls/o/abc.com.au/d/2024-07-14', 1)
sleep(500)
redisCounterProvider.inc('metrics/v1', 'pulls/o/abc.com.au/d/2024-07-15', 1)
sleep(500)
then:'this value should be one, because foo should be expired'
redisCounterProvider.get('metrics/v1', 'pulls/o/abc.com.au/d/2024-07-14') == null
sleep(500)
and:
redisCounterProvider.getAllMatchingEntries('metrics/v1', 'pulls/o/*/d/2024-05-30') ==
['pulls/o/abc.com.au/d/2024-05-30':1]
redisCounterProvider.get('metrics/v1', 'pulls/o/abc.com.au/d/2024-07-15') == null
and: 'this value should be one, because org metric should not expire'
redisCounterProvider.get('metrics/v1', 'pulls/o/abc.com.au') == 1
}

def 'should get correct org count for mirror and scan' () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ trait RedisTestContainer {

def setupSpec() {
log.debug "Starting Redis test container"
redisContainer = new GenericContainer(DockerImageName.parse("redis:7.0.4-alpine"))
redisContainer = new GenericContainer(DockerImageName.parse("redis:7.4.0-alpine"))
.withExposedPorts(6379)
.waitingFor(Wait.forLogMessage(".*Ready to accept connections.*\\n", 1))
redisContainer.start()
Expand Down
Loading