-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into add-e2e-tests
- Loading branch information
Showing
10 changed files
with
216 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.16.7 | ||
1.16.8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/main/groovy/io/seqera/wave/configuration/ProxyCacheConfig.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/main/groovy/io/seqera/wave/filter/TraceContextFilter.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,8 +22,9 @@ import java.time.Duration | |
|
||
import com.squareup.moshi.adapters.PolymorphicJsonAdapterFactory | ||
import groovy.transform.CompileStatic | ||
import io.micronaut.context.annotation.Value | ||
import groovy.util.logging.Slf4j | ||
import io.micronaut.core.annotation.Nullable | ||
import io.seqera.wave.configuration.ProxyCacheConfig | ||
import io.seqera.wave.encoder.MoshiEncodeStrategy | ||
import io.seqera.wave.encoder.MoshiExchange | ||
import io.seqera.wave.store.cache.AbstractTieredCache | ||
|
@@ -34,18 +35,17 @@ import jakarta.inject.Singleton | |
* | ||
* @author Paolo Di Tommaso <[email protected]> | ||
*/ | ||
@Slf4j | ||
@Singleton | ||
@CompileStatic | ||
class ProxyCache extends AbstractTieredCache<DelegateResponse> { | ||
|
||
@Value('${wave.proxy-cache.duration:30m}') | ||
private Duration duration | ||
private ProxyCacheConfig config | ||
|
||
@Value('${wave.proxy-cache.max-size:10000}') | ||
private int maxSize | ||
|
||
ProxyCache(@Nullable L2TieredCache l2) { | ||
ProxyCache(@Nullable L2TieredCache l2, ProxyCacheConfig config) { | ||
super(l2, encoder()) | ||
this.config = config | ||
log.info "+ Creating Proxy-cache - config=${config}" | ||
} | ||
|
||
static MoshiEncodeStrategy encoder() { | ||
|
@@ -69,11 +69,15 @@ class ProxyCache extends AbstractTieredCache<DelegateResponse> { | |
|
||
@Override | ||
int getMaxSize() { | ||
return maxSize | ||
return config.maxSize | ||
} | ||
|
||
Duration getDuration() { | ||
return duration | ||
return config.duration | ||
} | ||
|
||
boolean getEnabled() { | ||
return config.enabled | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/test/groovy/io/seqera/wave/filter/TraceContextFilterTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* 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 spock.lang.Specification | ||
|
||
/** | ||
* | ||
* @author Paolo Di Tommaso <[email protected]> | ||
*/ | ||
class TraceContextFilterTest extends Specification { | ||
|
||
def 'should validate request id regex' () { | ||
expect: | ||
TraceContextFilter.getRequestId(PATH) == EXPECTED | ||
where: | ||
PATH | EXPECTED | ||
'/foo/bar' | null | ||
'/v2/wt/1234' | '1234' | ||
'/v2/wt/12ab/x/y/z' | '12ab' | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters