Skip to content

Commit

Permalink
Merge branch 'master' into 562-evict-metrics-from-redis-after-120-days
Browse files Browse the repository at this point in the history
  • Loading branch information
munishchouhan authored Jan 29, 2025
2 parents 46880e2 + d3dfee9 commit cdfcbb2
Show file tree
Hide file tree
Showing 33 changed files with 455 additions and 76 deletions.
19 changes: 18 additions & 1 deletion .github/workflows/typespec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ on:
- '**'
paths :
- 'typespec/**'
- VERSION
pull_request:
types: [opened, reopened, synchronize]
paths:
- 'typespec/**'
- VERSION

permissions:
contents: read
Expand All @@ -30,11 +32,26 @@ jobs:
node-version : '20.9.0'

- name : Install tsp
run : npm install -g @typespec/compiler
run : npm install -g @typespec/compiler@0.64.0

- name : Validate tsp files
run : |
cd typespec
tsp install
tsp compile .
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{secrets.TOWER_CI_AWS_ACCESS}}
aws-secret-access-key: ${{secrets.TOWER_CI_AWS_SECRET}}
aws-region: eu-west-1

- name : Login to Amazon ECR
id : login-ecr
uses : aws-actions/amazon-ecr-login@v1

- name: Release OpenAPI docs
if: "contains(github.event.head_commit.message, '[release]')"
run: |
bash typespec/tag-and-push-openapi.sh
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.16.6
1.16.8
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ dependencies {
compileOnly 'io.micronaut:micronaut-inject-groovy'
compileOnly 'io.micronaut:micronaut-http-validation'
implementation 'jakarta.persistence:jakarta.persistence-api:3.0.0'
api 'io.seqera:lib-mail:1.2.1'
api 'io.seqera:lib-pool:1.0.0'
api 'io.seqera:wave-api:0.14.0'
api 'io.seqera:wave-utils:0.15.0'
implementation 'io.seqera:lib-mail:1.2.1'
implementation 'io.seqera:lib-pool:1.0.0'
implementation 'io.seqera:wave-api:0.14.0'
implementation 'io.seqera:wave-utils:0.15.0'
implementation 'io.seqera:lib-crypto:1.0.0'
implementation 'io.micronaut:micronaut-http-client'
implementation 'io.micronaut:micronaut-jackson-databind'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,12 @@ repositories {
}

java {
// these settings apply to all jvm tooling, including groovy
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}

compileJava {
options.release.set(17)
}

tasks.withType(GroovyCompile).configureEach {
sourceCompatibility = '17'
targetCompatibility = '17'
sourceCompatibility = 17
targetCompatibility = 17
}

group = 'io.seqera'
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,12 @@ repositories {
}

java {
// these settings apply to all jvm tooling, including groovy
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}

compileJava {
options.release.set(17)
}

tasks.withType(GroovyCompile).configureEach {
sourceCompatibility = '17'
targetCompatibility = '17'
sourceCompatibility = 17
targetCompatibility = 17
}

test {
Expand Down
10 changes: 10 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
# Wave changelog
1.16.8 - 20 Jab 2025
- Add TraceContextFilter logging context propagation [396c10c2]
- Improve Proxy cache configuration [163e605f]
- Improve logging pattern [0ab87164]
- Improve request caching logic [a95153be]
- Bump MN 4.7.4 [4ce2a139]

1.16.7 - 10 Jan 2025
- Improve logging on pairing websocket error [21861dbe]

1.16.6 - 7 Jan 2025
- Fix Use caffeine for tiered cache lock cache (#785) [bb5f4dd0]
- Tune trace timeouts [d6bf2236]
Expand Down
6 changes: 3 additions & 3 deletions configuration.md → docs/configuration.mdx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Wave Application Configuration

Set Wave configuration values using environment variables or in [`config.yml`](./config.yml) configuration file
Set Wave configuration values using environment variables or in [`config.yml`](https://github.com/seqeralabs/wave/blob/master/config.yml) configuration file

### config.yml configuration

Declare YAML configuration values in [`config.yml`](./config.yml)
Declare YAML configuration values in [`config.yml`](https://github.com/seqeralabs/wave/blob/master/config.yml)
```
wave:
mail:
Expand Down Expand Up @@ -39,7 +39,7 @@ The generic format for the attributes is `wave.registries.<registry_name>.userna
You need to specify all the repositories you will use in the respective wave installation.
Below are the standard format for known registries, but you can change registry name `(azurecr.io)` to specific one like `seqeralabs.azurecr.io `.

**Note**: Container registry credentials can be defined in [`config.yml`](./config.yml) too. These configurations are important for the wave authentication to the repositories used to push or pull artifacts.
**Note**: Container registry credentials can be defined in [`config.yml`](https://github.com/seqeralabs/wave/blob/master/config.yml) too. These configurations are important for the wave authentication to the repositories used to push or pull artifacts.

- **`wave.registries.default`**: the default Docker registry for Wave. The default is `docker.io`, and it represents the Docker Hub. *Optional*.

Expand Down
4 changes: 1 addition & 3 deletions docs/metrics.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
---
title: Usage metrics
---
# Usage metrics

Wave uses Redis to store its usage metrics for a specific date and/or a specific organization.

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#

micronautVersion=4.7.2
micronautVersion=4.7.4
micronautEnvs=dev,h2,mail,aws-ses
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Wave, containers provisioning service
* Copyright (c) 2023-2024, Seqera Labs
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package io.seqera.wave.configuration

import java.time.Duration

import groovy.transform.CompileStatic
import groovy.transform.ToString
import io.micronaut.context.annotation.Value
import jakarta.inject.Singleton

/**
* Model {@link io.seqera.wave.proxy.ProxyCache} configuration settings
*
* @author Paolo Di Tommaso <[email protected]>
*/
@Singleton
@CompileStatic
@ToString(includeNames = true, includePackage = false)
class ProxyCacheConfig {

@Value('${wave.proxy-cache.duration:4m}')
private Duration duration

@Value('${wave.proxy-cache.max-size:10000}')
private int maxSize

@Value('${wave.proxy-cache.enabled:true}')
private boolean enabled

Duration getDuration() {
return duration
}

int getMaxSize() {
return maxSize
}

boolean getEnabled() {
return enabled
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,9 @@ class ServiceInfoController {
: HttpResponse.badRequest()
}

@Get(uri = "/openapi")
HttpResponse getOpenAPI() {
HttpResponse.redirect(URI.create("/openapi/"))
}

}
35 changes: 26 additions & 9 deletions src/main/groovy/io/seqera/wave/core/RegistryProxyService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ class RegistryProxyService {
'Accept-Encoding',
'Authorization',
'Cache-Control',
'Connection',
'Content-Type',
'Content-Length',
'Content-Range',
Expand All @@ -173,9 +174,12 @@ class RegistryProxyService {
'If-None-Match',
'If-None-Match',
'Etag',
'Host',
'Location',
'Last-Modified',
'User-Agent',
'Range',
'X-Registry-Auth'
]

static protected boolean isCacheableHeader(String key) {
Expand All @@ -196,8 +200,13 @@ class RegistryProxyService {
if( !headers )
headers = Map.of()
for( Map.Entry<String,List<String>> entry : headers ) {
if( !isCacheableHeader(entry.key) )
if( "Cache-Control".equalsIgnoreCase(entry.key) ) {
// ignore caching when cache-control header is provided
return null
}
if( !isCacheableHeader(entry.key) ) {
continue
}
hasher.putUnencodedChars(entry.key)
for( String it : entry.value ) {
if( it )
Expand All @@ -218,14 +227,22 @@ class RegistryProxyService {
}

DelegateResponse handleRequest(RoutePath route, Map<String,List<String>> headers) {
return cache.getOrCompute(
requestKey(route, headers),
(String k)-> {
final resp = handleRequest0(route, headers)
// when the response is not cacheable, return null as TTL
final ttl = route.isDigest() && resp.isCacheable() ? cache.duration : null
return new Tuple2<DelegateResponse, Duration>(resp, ttl)
})
if( !cache.enabled ) {
return handleRequest0(route, headers)
}
final key = requestKey(route, headers)
if( !key ) {
log.debug "Bypass cache for requrst route=${route}; headers=${headers}"
return handleRequest0(route, headers)
}
else {
return cache.getOrCompute(key,(String k)-> {
final resp = handleRequest0(route, headers)
// when the response is not cacheable, return null as TTL
final ttl = route.isDigest() && resp.isCacheable() ? cache.duration : null
return new Tuple2<DelegateResponse, Duration>(resp, ttl)
})
}
}

@TraceElapsedTime(thresholdMillis = '${wave.trace.proxy-service.threshold:1000}')
Expand Down
63 changes: 63 additions & 0 deletions src/main/groovy/io/seqera/wave/filter/TraceContextFilter.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Wave, containers provisioning service
* Copyright (c) 2023-2024, Seqera Labs
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package io.seqera.wave.filter

import java.util.regex.Pattern

import groovy.transform.CompileStatic
import io.micronaut.context.propagation.slf4j.MdcPropagationContext
import io.micronaut.core.propagation.MutablePropagatedContext
import io.micronaut.http.HttpRequest
import io.micronaut.http.annotation.RequestFilter
import io.micronaut.http.annotation.ServerFilter
import org.slf4j.MDC
import static io.micronaut.http.annotation.ServerFilter.MATCH_ALL_PATTERN

/**
* HTTP filter to trace and propagate request metadata in the MDC logging context
*
* @author Paolo Di Tommaso <[email protected]>
*/
@CompileStatic
@ServerFilter(MATCH_ALL_PATTERN)
class TraceContextFilter {

static final Pattern REGEX = ~/^\/v2\/wt\/([a-z0-9]+).*/

@RequestFilter
void requestFilter(HttpRequest<?> request, MutablePropagatedContext mutablePropagatedContext) {
try {
final requestId = getRequestId(request.path)
MDC.put("requestId", requestId)
MDC.put("requestPath", request.path)
MDC.put("requestMethod", request.methodName)
mutablePropagatedContext.add(new MdcPropagationContext())
} finally {
MDC.remove("requestId")
MDC.remove("requestPath")
MDC.remove("requestMethod")
}
}

static String getRequestId(String path) {
final m = REGEX.matcher(path)
return m.matches() ? m.group(1) : null
}

}
Loading

0 comments on commit cdfcbb2

Please sign in to comment.