review-followup Wave 3: 설정 prefix app.* 통일(P20), Wave 3 종료
- 결정 16: `ca-skeleton.*`·`backend.graphql` 등 → `app.*`(APP_* env 키 이름 유지), selector 키 상수 하나(`CapabilitySelectors`), 바인딩만 되던 `streaming-idle` 삭제 - `StrictSettingsBinder`가 env 오타까지 거부 — 모든 capability(graphql·websocket·mongo는 edge 제약으로 파일만 strict), httpclient 리플렉션 `HttpClientEnvironmentKeys` 삭제 - persistence-jpa가 `APP_DATASOURCE_PASSWORD` secret 요구를 기여(bootstrap이 JPA 스위치를 읽지 않음), Redis ACL fixture에서 pub/sub 권한 제거 - 결함 수정: SMTP 설정 env 이름 충돌(P20-new-1), `bindExcept`가 system env까지 filter(P20-new-2), graphql 빈 deployment-mode 메시지(P20-new-6) - 통합: P30과 충돌 11건(P30의 명시적 bean 구조 유지), P30 코드의 옛 키를 app.*로, persistence-jpa 포맷 - 현황표: 소유자 결정 36(persistence-jpa 설정은 플랫폼 키만 app.persistence-jpa.*로, 공유 기능 트리 예외), 재개 문서에 일시 정지 상태 Wave 3 종료 검증: check · ci verifyDependencyLocks --warning-mode=fail(714 task) · mainCheck · architectureCheck verifyPublicPathSnapshot :app-bootstrap:verifyEnvKeys configContractCheck · :app-bootstrap:integrationTest :sample-portfolio:integrationTest :sample-portfolio:systemTest · integrationCheck · -p build-logic test · -p optional-platforms ci · :app-bootstrap:qualificationBootJar releaseCheck 통과 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
8bbf1bf01d
commit
27f23add08
@@ -18,7 +18,7 @@ composition:idempotency
|
||||
```
|
||||
|
||||
- 저장소는 포트(`IdempotencyStorePort`)다. Redis는 `adapter:outbound:cache-redis`, PostgreSQL은
|
||||
`adapter:outbound:persistence-jpa`가 `ca-skeleton.capabilities.idempotency.provider`에 따라 하나를
|
||||
`adapter:outbound:persistence-jpa`가 `app.capabilities.idempotency.provider`에 따라 하나를
|
||||
기여한다. 선택한 provider의 저장소가 정확히 하나가 아니면(0개: 모듈이 없거나 꺼짐, 2개: 다른
|
||||
곳이 하나 더 등록) 기동이 개수와 함께 실패한다.
|
||||
- 켜기와 끄기: 모듈이 있어도 `provider=disabled`(기본)면 아무것도 바인딩하거나 만들지 않는다.
|
||||
@@ -66,7 +66,7 @@ executor, 설정 기본값이 함께 빠진다(그때 KEYED use case는 executor
|
||||
`disabled` 나 `redis` 를 쓴다.
|
||||
|
||||
### IdempotencySettings
|
||||
- `ca-skeleton.capabilities.idempotency` 에 바인딩되는 유일한 설정 record 다(값은
|
||||
- `app.capabilities.idempotency` 에 바인딩되는 유일한 설정 record 다(값은
|
||||
`config/module-defaults/idempotency.yml`).
|
||||
|
||||
| 키 | env | 기본값 | 상한 |
|
||||
|
||||
+11
-7
@@ -1,5 +1,6 @@
|
||||
package dev.caskeleton.composition.idempotency;
|
||||
|
||||
import dev.caskeleton.adapter.outbound.support.CapabilitySelectors;
|
||||
import dev.caskeleton.adapter.outbound.support.startup.StartupFailures;
|
||||
import dev.caskeleton.application.idempotency.IdempotencyExecutor;
|
||||
import dev.caskeleton.application.idempotency.IdempotencyStorePort;
|
||||
@@ -16,11 +17,11 @@ import org.springframework.core.env.Environment;
|
||||
*
|
||||
* <p>Providers contribute only an {@link IdempotencyStorePort}: Redis from {@code
|
||||
* adapter:outbound:cache-redis}, PostgreSQL from {@code adapter:outbound:persistence-jpa}, each
|
||||
* conditional on {@code ca-skeleton.capabilities.idempotency.provider}. The lifecycle policy —
|
||||
* lease, replay TTL, retention, codec id, policy revision — is the same whichever store holds the
|
||||
* records, so it lives in one {@link IdempotencySettings} record and the executor is built here
|
||||
* from it. Every composition root that serves idempotent requests takes this module rather than a
|
||||
* copy of it: the application and the sample build the same executor from the same checks.
|
||||
* conditional on {@code app.capabilities.idempotency.provider}. The lifecycle policy — lease,
|
||||
* replay TTL, retention, codec id, policy revision — is the same whichever store holds the records,
|
||||
* so it lives in one {@link IdempotencySettings} record and the executor is built here from it.
|
||||
* Every composition root that serves idempotent requests takes this module rather than a copy of
|
||||
* it: the application and the sample build the same executor from the same checks.
|
||||
*
|
||||
* <p>A selected provider must yield exactly one store. None means the provider's module is not on
|
||||
* the runtime classpath or its switch is off; two means something else registered one (a scan-found
|
||||
@@ -33,7 +34,9 @@ import org.springframework.core.env.Environment;
|
||||
*/
|
||||
@AutoConfiguration
|
||||
@ConditionalOnExpression(
|
||||
"!'${ca-skeleton.capabilities.idempotency.provider:disabled}'.trim()"
|
||||
"!'${"
|
||||
+ CapabilitySelectors.IDEMPOTENCY_PROVIDER
|
||||
+ ":disabled}'.trim()"
|
||||
+ ".equalsIgnoreCase('disabled')")
|
||||
public class IdempotencyAutoConfiguration {
|
||||
|
||||
@@ -48,7 +51,8 @@ public class IdempotencyAutoConfiguration {
|
||||
List<IdempotencyStorePort> found = stores.orderedStream().toList();
|
||||
if (found.size() != 1) {
|
||||
throw StartupFailures.requiredAdapterDisabled(
|
||||
"ca-skeleton.capabilities.idempotency.provider="
|
||||
CapabilitySelectors.IDEMPOTENCY_PROVIDER
|
||||
+ "="
|
||||
+ settings.provider().name().toLowerCase(Locale.ROOT)
|
||||
+ " needs exactly one IdempotencyStorePort, but found "
|
||||
+ found.size()
|
||||
|
||||
+4
-5
@@ -7,10 +7,9 @@ import java.util.Set;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
/**
|
||||
* The one settings record for request idempotency, bound at {@code
|
||||
* ca-skeleton.capabilities.idempotency}. The executor is built from it once, whichever provider
|
||||
* supplies the store. Every value is checked here, so a bad value fails startup rather than the
|
||||
* first request.
|
||||
* The one settings record for request idempotency, bound at {@code app.capabilities.idempotency}.
|
||||
* The executor is built from it once, whichever provider supplies the store. Every value is checked
|
||||
* here, so a bad value fails startup rather than the first request.
|
||||
*
|
||||
* <p>The Redis store reads its own two knobs ({@code key-version}, {@code command-timeout}) under
|
||||
* the same prefix; they are store tuning, not lifecycle policy, so they are not repeated here. The
|
||||
@@ -34,7 +33,7 @@ public record IdempotencySettings(
|
||||
Integer policyRevision,
|
||||
Duration reaperInterval) {
|
||||
|
||||
static final String PREFIX = "ca-skeleton.capabilities.idempotency";
|
||||
static final String PREFIX = "app.capabilities.idempotency";
|
||||
|
||||
/** Keys under the prefix that the Redis store binds for itself. */
|
||||
static final Set<String> STORE_OWNED_KEYS = Set.of("key-version", "command-timeout");
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
# adapter:outbound:support 의 ModuleDefaultsEnvironmentPostProcessor 가 읽는다. 우선순위는 가장 낮아서
|
||||
# application*.yml, 환경 변수, 시스템 속성이 항상 이긴다. 이 모듈을 빌드에서 빼면 이 파일도 함께
|
||||
# 빠진다.
|
||||
ca-skeleton:
|
||||
app:
|
||||
capabilities:
|
||||
idempotency:
|
||||
# disabled | redis | postgresql. Exactly one store; the executor is built once over it from
|
||||
|
||||
+6
-6
@@ -37,12 +37,12 @@ class IdempotencyAutoConfigurationTest {
|
||||
.withBean(JdbcOperations.class, () -> org.mockito.Mockito.mock(JdbcOperations.class))
|
||||
.withBean(Clock.class, Clock::systemUTC)
|
||||
// The schema stream talks to a real database; its own integration test covers it.
|
||||
.withPropertyValues("ca-skeleton.runtime.migration-on-startup=false");
|
||||
.withPropertyValues("app.runtime.migration-on-startup=false");
|
||||
|
||||
@Test
|
||||
void disabledComposesNoExecutorEvenWithAStorePresent() {
|
||||
runner
|
||||
.withPropertyValues("ca-skeleton.capabilities.idempotency.provider=disabled")
|
||||
.withPropertyValues("app.capabilities.idempotency.provider=disabled")
|
||||
.withBean(IdempotencyStorePort.class, InMemoryIdempotencyStore::new)
|
||||
.run(
|
||||
context ->
|
||||
@@ -52,7 +52,7 @@ class IdempotencyAutoConfigurationTest {
|
||||
@Test
|
||||
void redisComposesOneExecutorOverTheRedisStoreAlone() {
|
||||
runner
|
||||
.withPropertyValues("ca-skeleton.capabilities.idempotency.provider=redis")
|
||||
.withPropertyValues("app.capabilities.idempotency.provider=redis")
|
||||
.withBean(IdempotencyStorePort.class, InMemoryIdempotencyStore::new)
|
||||
.run(
|
||||
context ->
|
||||
@@ -66,7 +66,7 @@ class IdempotencyAutoConfigurationTest {
|
||||
@Test
|
||||
void postgresqlComposesOneExecutorOverThePersistenceJpaStore() {
|
||||
runner
|
||||
.withPropertyValues("ca-skeleton.capabilities.idempotency.provider=postgresql")
|
||||
.withPropertyValues("app.capabilities.idempotency.provider=postgresql")
|
||||
.run(
|
||||
context ->
|
||||
assertThat(context)
|
||||
@@ -81,7 +81,7 @@ class IdempotencyAutoConfigurationTest {
|
||||
@DisplayName("a selected provider whose module contributed no store fails startup with the count")
|
||||
void selectedProviderWithoutAStoreFailsStartup() {
|
||||
runner
|
||||
.withPropertyValues("ca-skeleton.capabilities.idempotency.provider=redis")
|
||||
.withPropertyValues("app.capabilities.idempotency.provider=redis")
|
||||
.run(
|
||||
context ->
|
||||
assertThat(context)
|
||||
@@ -96,7 +96,7 @@ class IdempotencyAutoConfigurationTest {
|
||||
@DisplayName("a second store beside the selected one fails startup with the count")
|
||||
void secondStoreBesideTheSelectedOneFailsStartup() {
|
||||
runner
|
||||
.withPropertyValues("ca-skeleton.capabilities.idempotency.provider=postgresql")
|
||||
.withPropertyValues("app.capabilities.idempotency.provider=postgresql")
|
||||
.withBean("strayStore", IdempotencyStorePort.class, InMemoryIdempotencyStore::new)
|
||||
.run(
|
||||
context ->
|
||||
|
||||
+2
-2
@@ -28,7 +28,7 @@ class IdempotencyModuleDefaultsTest {
|
||||
StandardEnvironment environment = processed(Map.of());
|
||||
|
||||
// then
|
||||
assertThat(environment.getProperty("ca-skeleton.capabilities.idempotency.provider"))
|
||||
assertThat(environment.getProperty("app.capabilities.idempotency.provider"))
|
||||
.isEqualTo("disabled");
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ class IdempotencyModuleDefaultsTest {
|
||||
StandardEnvironment environment = processed(Map.of("APP_IDEMPOTENCY_PROVIDER", "postgresql"));
|
||||
|
||||
// then
|
||||
assertThat(environment.getProperty("ca-skeleton.capabilities.idempotency.provider"))
|
||||
assertThat(environment.getProperty("app.capabilities.idempotency.provider"))
|
||||
.isEqualTo("postgresql");
|
||||
}
|
||||
|
||||
|
||||
+5
-6
@@ -15,7 +15,7 @@ import org.springframework.mock.env.MockEnvironment;
|
||||
|
||||
class IdempotencySettingsTest {
|
||||
|
||||
private static final String PREFIX = "ca-skeleton.capabilities.idempotency.";
|
||||
private static final String PREFIX = "app.capabilities.idempotency.";
|
||||
|
||||
@Test
|
||||
void absentLifecycleKeysBindToTheDocumentedDefaults() {
|
||||
@@ -80,7 +80,7 @@ class IdempotencySettingsTest {
|
||||
// then
|
||||
assertThat(thrown)
|
||||
.isInstanceOf(BindException.class)
|
||||
.hasStackTraceContaining("ca-skeleton.capabilities.idempotency.provider");
|
||||
.hasStackTraceContaining("app.capabilities.idempotency.provider");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -148,7 +148,7 @@ class IdempotencySettingsTest {
|
||||
.isInstanceOfSatisfying(
|
||||
StartupFailureException.class,
|
||||
e -> assertThat(e.errorCode()).isEqualTo(StartupErrorCode.STARTUP_VALIDATION_FAILED))
|
||||
.hasMessageContaining("ca-skeleton.capabilities.idempotency." + message);
|
||||
.hasMessageContaining("app.capabilities.idempotency." + message);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@@ -166,7 +166,7 @@ class IdempotencySettingsTest {
|
||||
.isInstanceOfSatisfying(
|
||||
StartupFailureException.class,
|
||||
e -> assertThat(e.errorCode()).isEqualTo(StartupErrorCode.STARTUP_VALIDATION_FAILED))
|
||||
.hasMessageContaining("ca-skeleton.capabilities.idempotency." + message);
|
||||
.hasMessageContaining("app.capabilities.idempotency." + message);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -183,7 +183,6 @@ class IdempotencySettingsTest {
|
||||
.isInstanceOfSatisfying(
|
||||
StartupFailureException.class,
|
||||
e -> assertThat(e.errorCode()).isEqualTo(StartupErrorCode.STARTUP_VALIDATION_FAILED))
|
||||
.hasMessageContaining(
|
||||
"ca-skeleton.capabilities.idempotency.policy-revision must be positive");
|
||||
.hasMessageContaining("app.capabilities.idempotency.policy-revision must be positive");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ runtimeOnly project(':composition:notification-platform') // 알림 (저
|
||||
|
||||
## 켜기와 끄기
|
||||
|
||||
모듈이 있으면 켜진다. `ca-skeleton.notification.platform.enabled`(`APP_NOTIFICATION_PLATFORM_ENABLED`,
|
||||
모듈이 있으면 켜진다. `app.notification.platform.enabled`(`APP_NOTIFICATION_PLATFORM_ENABLED`,
|
||||
기본 `true`)를 `false`로 줄 때만 꺼지고, 그때는 아무것도 바인딩하지 않는다. 켜진 상태에서는 아래
|
||||
"항상" 키가 없으면 기동이 거부된다.
|
||||
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ import org.springframework.context.annotation.Import;
|
||||
afterName =
|
||||
"dev.caskeleton.adapter.outbound.notification.platform.autoconfigure.NotificationPlatformAutoConfiguration")
|
||||
@ConditionalOnProperty(
|
||||
prefix = "ca-skeleton.notification.platform",
|
||||
prefix = "app.notification.platform",
|
||||
name = "enabled",
|
||||
havingValue = "true",
|
||||
matchIfMissing = true)
|
||||
|
||||
+1
-1
@@ -88,7 +88,7 @@ class NotificationSubmissionConfiguration {
|
||||
PlanFingerprint fingerprints,
|
||||
TransactionPort transactions,
|
||||
Clock clock,
|
||||
@Value("${ca-skeleton.notification.platform.default-locale:ko-KR}") String defaultLocale) {
|
||||
@Value("${app.notification.platform.default-locale:ko-KR}") String defaultLocale) {
|
||||
return new AcceptNotificationApplicationUseCase(
|
||||
submit,
|
||||
contactPoints,
|
||||
|
||||
+4
-6
@@ -18,9 +18,9 @@
|
||||
info:
|
||||
capabilities:
|
||||
notification:
|
||||
enabled: ${ca-skeleton.notification.platform.enabled:true}
|
||||
enabled: ${app.notification.platform.enabled:true}
|
||||
|
||||
ca-skeleton:
|
||||
app:
|
||||
notification:
|
||||
platform:
|
||||
# The capability switch. False binds nothing at all.
|
||||
@@ -133,7 +133,7 @@ ca-skeleton:
|
||||
# to set one gets a traceable bounce rather than mail apparently from an address it does not
|
||||
# own.
|
||||
sender-identity: ${APP_NOTIFICATION_PLATFORM_SMTP_SENDER_IDENTITY:no-reply@example.invalid}
|
||||
max-concurrency: ${APP_NOTIFICATION_PLATFORM_SMTP_DISPATCH_CONCURRENCY:4}
|
||||
dispatch-concurrency: ${APP_NOTIFICATION_PLATFORM_SMTP_DISPATCH_CONCURRENCY:4}
|
||||
# ---- Key material -------------------------------------------------------
|
||||
# Seven purposes, seven keys, each base64 of at least 32 bytes and each distinct from every
|
||||
# other. The platform decodes them at startup and refuses to boot if one is blank, short or
|
||||
@@ -176,12 +176,10 @@ ca-skeleton:
|
||||
# none. See docs/notification/at-rest-threat-model.md for the rotation sequence.
|
||||
historical-keys: {}
|
||||
|
||||
app:
|
||||
notification:
|
||||
# R0 compatibility provider gates. These booleans are the properties the provider
|
||||
# configurations actually consume; the removed provider-id selectors were never read.
|
||||
# This is the R0 legacy seam. The delivery platform is the separate
|
||||
# ca-skeleton.notification.platform tree below.
|
||||
# app.notification.platform tree above.
|
||||
slack-webhook:
|
||||
enabled: ${APP_NOTIFICATION_SLACK_WEBHOOK_ENABLED:false}
|
||||
google-email:
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ class NotificationApplicationCompositionAutoConfigurationTest {
|
||||
new ApplicationContextRunner()
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(NotificationApplicationCompositionAutoConfiguration.class))
|
||||
.withPropertyValues("ca-skeleton.notification.platform.enabled=false")
|
||||
.withPropertyValues("app.notification.platform.enabled=false")
|
||||
.run(
|
||||
context ->
|
||||
assertThat(context)
|
||||
|
||||
+6
-10
@@ -18,10 +18,8 @@ class NotificationModuleDefaultsTest {
|
||||
void theShippedDefaultsTurnThePlatformOnWhileTheModuleIsPresent() {
|
||||
StandardEnvironment environment = processed(Map.of());
|
||||
|
||||
assertThat(environment.getProperty("ca-skeleton.notification.platform.enabled"))
|
||||
.isEqualTo("true");
|
||||
assertThat(environment.getProperty("ca-skeleton.notification.platform.mode"))
|
||||
.isEqualTo("SERVING");
|
||||
assertThat(environment.getProperty("app.notification.platform.enabled")).isEqualTo("true");
|
||||
assertThat(environment.getProperty("app.notification.platform.mode")).isEqualTo("SERVING");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -29,24 +27,22 @@ class NotificationModuleDefaultsTest {
|
||||
StandardEnvironment environment =
|
||||
processed(Map.of("APP_NOTIFICATION_PLATFORM_ENABLED", "false"));
|
||||
|
||||
assertThat(environment.getProperty("ca-skeleton.notification.platform.enabled"))
|
||||
.isEqualTo("false");
|
||||
assertThat(environment.getProperty("app.notification.platform.enabled")).isEqualTo("false");
|
||||
}
|
||||
|
||||
@Test
|
||||
void aDeploymentValueOutranksTheShippedDefault() {
|
||||
StandardEnvironment environment =
|
||||
processed(Map.of("ca-skeleton.notification.platform.mode", "INGEST_ONLY"));
|
||||
processed(Map.of("app.notification.platform.mode", "INGEST_ONLY"));
|
||||
|
||||
assertThat(environment.getProperty("ca-skeleton.notification.platform.mode"))
|
||||
.isEqualTo("INGEST_ONLY");
|
||||
assertThat(environment.getProperty("app.notification.platform.mode")).isEqualTo("INGEST_ONLY");
|
||||
}
|
||||
|
||||
@Test
|
||||
void bothNotificationTreesShipInTheOneFile() {
|
||||
StandardEnvironment environment = processed(Map.of());
|
||||
|
||||
assertThat(environment.getProperty("ca-skeleton.notification.platform.dispatch.lease-duration"))
|
||||
assertThat(environment.getProperty("app.notification.platform.dispatch.lease-duration"))
|
||||
.isEqualTo("2m");
|
||||
assertThat(environment.getProperty("app.notification.slack-webhook.enabled"))
|
||||
.isEqualTo("false");
|
||||
|
||||
@@ -12,8 +12,8 @@ use case는 `OutboxAppendPort`로 append만 하고, relay가 나머지를 한다
|
||||
|
||||
```
|
||||
composition:outbox-relay
|
||||
└─ OutboxRelayAutoConfiguration ca-skeleton.outbox.enabled=true + OutboxStorePort 가 있을 때만
|
||||
├─ OutboxSettings ca-skeleton.outbox.* strict 바인딩(오타는 기동 실패)
|
||||
└─ OutboxRelayAutoConfiguration app.outbox.enabled=true + OutboxStorePort 가 있을 때만
|
||||
├─ OutboxSettings app.outbox.* strict 바인딩(오타는 기동 실패)
|
||||
├─ OutboxRelayScheduler relay-enabled=true + OutboxMessagePublishPort 가 있을 때만,
|
||||
│ PublishPendingOutboxEventsUseCase 를 fixed-delay 로 구동
|
||||
├─ OutboxMetrics outbox.pending.size / outbox.publisher.lag / published.total
|
||||
@@ -27,7 +27,7 @@ composition:outbox-relay
|
||||
둔다(대역 publisher로 DEAD까지 소진하지 않는다).
|
||||
- persistence-jpa 안이 아니라 여기 있는 이유: driven adapter는 use case를 만들거나 부르지 않는다
|
||||
(ArchUnit `PERSISTENCE_DOES_NOT_DEPEND_ON_APPLICATION_SERVICES`).
|
||||
- 설정 기본값: `ca-skeleton.outbox.*`의 기본값은 store를 가진 persistence-jpa가
|
||||
- 설정 기본값: `app.outbox.*`의 기본값은 store를 가진 persistence-jpa가
|
||||
`config/module-defaults/persistence-jpa.yml`로 싣는다(store와 reaper도 `enabled`,
|
||||
`reaper-interval`, `published-retention`을 읽는다). 키의 선언과 검증은 이 모듈의 `OutboxSettings`
|
||||
하나다.
|
||||
@@ -51,7 +51,7 @@ runtimeOnly project(':composition:outbox-relay') // outbox relay
|
||||
| 항상 | persistence-jpa 줄과 그 연결 env, `APP_OUTBOX_ENABLED=true` |
|
||||
| relay를 돌릴 때 | `APP_OUTBOX_RELAY_ENABLED=true`, 그리고 발행 capability(`adapter:outbound:messaging-kafka` 줄과 `APP_MESSAGING_PRODUCER_ID`, `APP_MESSAGING_KAFKA_BROKERS`) |
|
||||
|
||||
poll 주기·batch 크기·in-flight timeout·보존 기간은 env 키 없이 `ca-skeleton.outbox.*` 기본값으로
|
||||
poll 주기·batch 크기·in-flight timeout·보존 기간은 env 키 없이 `app.outbox.*` 기본값으로
|
||||
동작한다.
|
||||
|
||||
## 설계 결정 참조 (app-bootstrap에서 옮김)
|
||||
@@ -72,7 +72,7 @@ poll 주기·batch 크기·in-flight timeout·보존 기간은 env 키 없이 `c
|
||||
감싼다. 그런데 use case 가 `final` 클래스라 프록시 생성 자체가 실패하고, 설령 된다 해도 스케줄러
|
||||
스레드에는 `Authentication`이 없어 매 릴레이 틱이 fail-closed 로 거부된다. 그래서 빈으로 올리지
|
||||
않고, `outbox:relay` 권한 확인은 스케줄러 컨텍스트에서 관례로 둔다.
|
||||
- **`outboxRelayScheduler` 빈은 `ca-skeleton.outbox.relay-enabled=true`일 때만 만든다(기본
|
||||
- **`outboxRelayScheduler` 빈은 `app.outbox.relay-enabled=true`일 때만 만든다(기본
|
||||
false).** 키가 없으면 꺼진 것으로 본다. 모듈 기본값(`persistence-jpa.yml`의
|
||||
`${APP_OUTBOX_RELAY_ENABLED:false}`), `@ConditionalOnProperty`, `OutboxSettings`의 null 기본값이
|
||||
모두 false로 같다.
|
||||
@@ -133,5 +133,5 @@ poll 주기·batch 크기·in-flight timeout·보존 기간은 env 키 없이 `c
|
||||
`PT5M`, `PT10M`, `P7D`)을 채운다.
|
||||
- **`reaper-interval`과 `published-retention`은 `adapter-persistence`의 `OutboxReaper`도 property
|
||||
문자열로 읽는다.** 두 모듈이 같은 키를 공유하지만, 이 settings record 가 일곱 값 전체를 선언
|
||||
하는 단일 지점(single place) 역할을 한다. strict 바인딩이라 prefix 아래 모르는 키는 기동 실패다. 기본값 yml(`ca-skeleton.outbox.*`)은 store를 가진
|
||||
하는 단일 지점(single place) 역할을 한다. strict 바인딩이라 prefix 아래 모르는 키는 기동 실패다. 기본값 yml(`app.outbox.*`)은 store를 가진
|
||||
persistence-jpa 모듈이 `config/module-defaults/persistence-jpa.yml`로 가져온다.
|
||||
|
||||
@@ -9,7 +9,7 @@ plugins {
|
||||
//
|
||||
// It builds the relay use case over the outbox store and the publish port and drives it on a
|
||||
// timer, with its metrics. It names no module: the store (persistence-jpa, with
|
||||
// ca-skeleton.outbox.enabled) and the publish port (the messaging bridge) are ports, and the relay
|
||||
// app.outbox.enabled) and the publish port (the messaging bridge) are ports, and the relay
|
||||
// assembles nothing until both exist. It lives here rather than in persistence-jpa because a
|
||||
// driven adapter must not construct or call a use case.
|
||||
//
|
||||
|
||||
+6
-6
@@ -29,10 +29,10 @@ import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
* PERSISTENCE_DOES_NOT_DEPEND_ON_APPLICATION_SERVICES}). It names no module type, only ports, and
|
||||
* turns itself on from what the selected modules provide.
|
||||
*
|
||||
* <p>{@code ca-skeleton.outbox.enabled} is the capability switch; {@code relay-enabled} only
|
||||
* decides whether the scheduler runs. The store port exists only while the persistence-jpa module
|
||||
* is selected and its outbox is on, so this configuration waits for it: removing that module's
|
||||
* build line removes the relay with it.
|
||||
* <p>{@code app.outbox.enabled} is the capability switch; {@code relay-enabled} only decides
|
||||
* whether the scheduler runs. The store port exists only while the persistence-jpa module is
|
||||
* selected and its outbox is on, so this configuration waits for it: removing that module's build
|
||||
* line removes the relay with it.
|
||||
*
|
||||
* <p>The scheduler additionally needs somewhere to publish. It is created only when an {@link
|
||||
* OutboxMessagePublishPort} bean exists — the messaging bridge contributes one — so a deployment
|
||||
@@ -45,7 +45,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
"dev.caskeleton.adapter.outbound.persistence.autoconfigure.PersistenceJpaAutoConfiguration",
|
||||
"dev.caskeleton.adapter.outbound.messaging.autoconfigure.MessagingBridgeRootAutoConfiguration"
|
||||
})
|
||||
@ConditionalOnProperty(prefix = "ca-skeleton.outbox", name = "enabled", havingValue = "true")
|
||||
@ConditionalOnProperty(prefix = "app.outbox", name = "enabled", havingValue = "true")
|
||||
@ConditionalOnBean(OutboxStorePort.class)
|
||||
// The relay is @Scheduled. It must switch scheduling on itself rather than rely on another
|
||||
// capability (the PostgreSQL idempotency provider also does), or the relay runs only by accident.
|
||||
@@ -60,7 +60,7 @@ public class OutboxRelayAutoConfiguration {
|
||||
|
||||
/** Relay use case is assembled manually here (not a bean) from {@link OutboxSettings} values. */
|
||||
@Bean
|
||||
@ConditionalOnProperty(name = "ca-skeleton.outbox.relay-enabled", havingValue = "true")
|
||||
@ConditionalOnProperty(name = "app.outbox.relay-enabled", havingValue = "true")
|
||||
@ConditionalOnBean(OutboxMessagePublishPort.class)
|
||||
public OutboxRelayScheduler outboxRelayScheduler(
|
||||
OutboxStorePort store,
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ public class OutboxRelayScheduler {
|
||||
* Unexpected exceptions are caught (not propagated) so the scheduler thread stays alive for the
|
||||
* next tick.
|
||||
*/
|
||||
@Scheduled(fixedDelayString = "${ca-skeleton.outbox.poll-interval:PT5S}")
|
||||
@Scheduled(fixedDelayString = "${app.outbox.poll-interval:PT5S}")
|
||||
public void relay() {
|
||||
try {
|
||||
OutboxRelayResult result = relayUseCase.handle(PublishPendingOutboxEventsCommand.INSTANCE);
|
||||
|
||||
+4
-4
@@ -6,9 +6,9 @@ import java.time.Duration;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
/**
|
||||
* The outbox capability's settings, bound strictly from {@code ca-skeleton.outbox.*}: every key
|
||||
* under the prefix is one of these, so a misspelt one fails startup instead of leaving a default in
|
||||
* force. The persistence module reads {@code enabled}, {@code reaper-interval} and {@code
|
||||
* The outbox capability's settings, bound strictly from {@code app.outbox.*}: every key under the
|
||||
* prefix is one of these, so a misspelt one fails startup instead of leaving a default in force.
|
||||
* The persistence module reads {@code enabled}, {@code reaper-interval} and {@code
|
||||
* published-retention} too — the store and its reaper — but the keys are declared and validated
|
||||
* once, here.
|
||||
*
|
||||
@@ -30,7 +30,7 @@ public record OutboxSettings(
|
||||
Duration reaperInterval,
|
||||
Duration publishedRetention) {
|
||||
|
||||
static final String PREFIX = "ca-skeleton.outbox";
|
||||
static final String PREFIX = "app.outbox";
|
||||
|
||||
public OutboxSettings {
|
||||
if (enabled == null) {
|
||||
|
||||
+8
-11
@@ -41,12 +41,10 @@ class OutboxRelayAutoConfigurationTest {
|
||||
new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(OutboxRelayAutoConfiguration.class))
|
||||
.withBean(OutboxStorePort.class, OutboxRelayAutoConfigurationTest::unusedStore)
|
||||
.withPropertyValues("ca-skeleton.outbox.enabled=true", "ca-skeleton.outbox.batch-sise=500")
|
||||
.withPropertyValues("app.outbox.enabled=true", "app.outbox.batch-sise=500")
|
||||
.run(
|
||||
context ->
|
||||
assertThat(context)
|
||||
.getFailure()
|
||||
.hasStackTraceContaining("ca-skeleton.outbox.batch-sise"));
|
||||
assertThat(context).getFailure().hasStackTraceContaining("app.outbox.batch-sise"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -57,9 +55,9 @@ class OutboxRelayAutoConfigurationTest {
|
||||
.withConfiguration(AutoConfigurations.of(OutboxRelayAutoConfiguration.class))
|
||||
.withBean(OutboxStorePort.class, OutboxRelayAutoConfigurationTest::unusedStore)
|
||||
.withPropertyValues(
|
||||
"ca-skeleton.outbox.enabled=true",
|
||||
"ca-skeleton.outbox.relay-enabled=false",
|
||||
"ca-skeleton.capabilities.idempotency.provider=disabled");
|
||||
"app.outbox.enabled=true",
|
||||
"app.outbox.relay-enabled=false",
|
||||
"app.capabilities.idempotency.provider=disabled");
|
||||
|
||||
// when & then
|
||||
runner.run(
|
||||
@@ -77,8 +75,7 @@ class OutboxRelayAutoConfigurationTest {
|
||||
.withBean(OutboxRelayFailureReportPort.class, () -> report -> {})
|
||||
.withBean(TransactionPort.class, () -> mock(TransactionPort.class))
|
||||
.withBean(Clock.class, Clock::systemUTC)
|
||||
.withPropertyValues(
|
||||
"ca-skeleton.outbox.enabled=true", "ca-skeleton.outbox.relay-enabled=true");
|
||||
.withPropertyValues("app.outbox.enabled=true", "app.outbox.relay-enabled=true");
|
||||
|
||||
// No publish port: PENDING rows stay PENDING rather than being failed to DEAD.
|
||||
relayOn.run(context -> assertThat(context).doesNotHaveBean(OutboxRelayScheduler.class));
|
||||
@@ -96,7 +93,7 @@ class OutboxRelayAutoConfigurationTest {
|
||||
.withBean(TransactionPort.class, () -> mock(TransactionPort.class))
|
||||
.withBean(Clock.class, Clock::systemUTC)
|
||||
.withBean(OutboxMessagePublishPort.class, () -> mock(OutboxMessagePublishPort.class))
|
||||
.withPropertyValues("ca-skeleton.outbox.enabled=true")
|
||||
.withPropertyValues("app.outbox.enabled=true")
|
||||
.run(
|
||||
context ->
|
||||
assertThat(context)
|
||||
@@ -108,7 +105,7 @@ class OutboxRelayAutoConfigurationTest {
|
||||
void withoutTheRelationalStoreTheOutboxAssemblesNothing() {
|
||||
new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(OutboxRelayAutoConfiguration.class))
|
||||
.withPropertyValues("ca-skeleton.outbox.enabled=true")
|
||||
.withPropertyValues("app.outbox.enabled=true")
|
||||
.run(context -> assertThat(context).doesNotHaveBean(OutboxMetrics.class));
|
||||
}
|
||||
|
||||
|
||||
+9
-9
@@ -37,13 +37,13 @@ class OutboxSettingsTest {
|
||||
// given
|
||||
MockEnvironment environment =
|
||||
new MockEnvironment()
|
||||
.withProperty("ca-skeleton.outbox.enabled", "true")
|
||||
.withProperty("ca-skeleton.outbox.relay-enabled", "true")
|
||||
.withProperty("ca-skeleton.outbox.poll-interval", "10s")
|
||||
.withProperty("ca-skeleton.outbox.batch-size", "50")
|
||||
.withProperty("ca-skeleton.outbox.in-flight-timeout", "2m")
|
||||
.withProperty("ca-skeleton.outbox.reaper-interval", "1h")
|
||||
.withProperty("ca-skeleton.outbox.published-retention", "14d");
|
||||
.withProperty("app.outbox.enabled", "true")
|
||||
.withProperty("app.outbox.relay-enabled", "true")
|
||||
.withProperty("app.outbox.poll-interval", "10s")
|
||||
.withProperty("app.outbox.batch-size", "50")
|
||||
.withProperty("app.outbox.in-flight-timeout", "2m")
|
||||
.withProperty("app.outbox.reaper-interval", "1h")
|
||||
.withProperty("app.outbox.published-retention", "14d");
|
||||
|
||||
// when
|
||||
OutboxSettings settings = OutboxSettings.bind(environment);
|
||||
@@ -73,7 +73,7 @@ class OutboxSettingsTest {
|
||||
.isInstanceOfSatisfying(
|
||||
StartupFailureException.class,
|
||||
e -> assertThat(e.errorCode()).isEqualTo(StartupErrorCode.STARTUP_VALIDATION_FAILED))
|
||||
.hasMessageContaining("ca-skeleton.outbox." + message);
|
||||
.hasMessageContaining("app.outbox." + message);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@@ -97,6 +97,6 @@ class OutboxSettingsTest {
|
||||
.isInstanceOfSatisfying(
|
||||
StartupFailureException.class,
|
||||
e -> assertThat(e.errorCode()).isEqualTo(StartupErrorCode.STARTUP_VALIDATION_FAILED))
|
||||
.hasMessageContaining("ca-skeleton.outbox." + message);
|
||||
.hasMessageContaining("app.outbox." + message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ composition:service-runtime
|
||||
|
||||
- 모두 이 모듈의 `AutoConfiguration.imports`로 등록된다(sampling bridge는 `spring.factories`의
|
||||
`EnvironmentPostProcessor`). 구성 루트의 component scan에 기대지 않는다.
|
||||
- 설정 키는 옮기지 않았다: `ca-skeleton.tracing.*`, `ca-skeleton.privacy.*`. 값은 각 구성 루트의 `application.yml`/`config/observability.yml`에 있다.
|
||||
- 설정 키는 옮기지 않았다: `app.tracing.*`, `app.privacy.*`. 값은 각 구성 루트의 `application.yml`/`config/observability.yml`에 있다.
|
||||
- actuator chain은 servlet 웹 애플리케이션에서만 만들어지고, 구성 루트가 같은 이름
|
||||
`actuatorSecurityFilterChain`의 bean을 두면 물러난다. sample-portfolio는 공개 데모라 그렇게
|
||||
모든 요청을 허용하는 자기 chain을 둔다.
|
||||
@@ -81,7 +81,7 @@ runtimeOnly project(':composition:service-runtime')
|
||||
등록되었는지" 검사할 수 있게 하는 bootstrap 내부 전용 장치다.
|
||||
|
||||
#### TracingSettings
|
||||
- **`ca-skeleton.tracing.*` 바인딩 `@ConfigurationProperties` record.** 세 env 키가 들어온다:
|
||||
- **`app.tracing.*` 바인딩 `@ConfigurationProperties` record.** 세 env 키가 들어온다:
|
||||
`APP_TRACING_ENABLED` → `enabled`, `APP_TRACING_SAMPLE_RATE` → `sampleRate`,
|
||||
`OTEL_EXPORTER_OTLP_ENDPOINT` → `exporter.otlpEndpoint`.
|
||||
- **`sampleRate`가 blank 이면 숫자 검증을 건너뛴다.** blank 는 "값이 잘못됐다"가 아니라 "프로파일별
|
||||
@@ -119,7 +119,7 @@ runtimeOnly project(':composition:service-runtime')
|
||||
단일화(브리지)하는 `EnvironmentPostProcessor`다.** 이를 통해 "프로파일별 기본값 + env override"라는
|
||||
우리 규약을 Spring Boot 의 기본 샘플링 메커니즘에 그대로 연결한다.
|
||||
- **브리지 우선순위.** (1) 사용자가 `management.tracing.sampling.probability`를 이미 명시했으면
|
||||
덮어쓰지 않고 그대로 둔다, (2) `ca-skeleton.tracing.sample-rate`가 non-blank 면 그 값 사용, (3)
|
||||
덮어쓰지 않고 그대로 둔다, (2) `app.tracing.sample-rate`가 non-blank 면 그 값 사용, (3)
|
||||
blank 면 `TracingSampleRateResolver.defaultRateForProfile(...)`로 active profile 기본값 적용.
|
||||
- **`META-INF/spring.factories`에 `org.springframework.boot.EnvironmentPostProcessor` 키로 등록된다.**
|
||||
`EnvironmentPostProcessor`는 ApplicationContext 가 생성되기 전에 실행되므로 일반 빈이 아니라
|
||||
@@ -211,7 +211,7 @@ runtimeOnly project(':composition:service-runtime')
|
||||
|
||||
#### PrivacySettings
|
||||
- **보안/감사 로그에서 `user_principal`을 가명화하는 데 쓰는 HMAC salt 를 보관한다.**
|
||||
`ca-skeleton.privacy.*` 바인딩(원천 `APP_PRIVACY_PSEUDONYMIZATION_SALT`). 알고리즘은 HMAC-SHA-256
|
||||
`app.privacy.*` 바인딩(원천 `APP_PRIVACY_PSEUDONYMIZATION_SALT`). 알고리즘은 HMAC-SHA-256
|
||||
+ 90일 회전 salt 이고, 이 salt 는 `secret`-tier 값이라 prod 에서는 반드시 secret manager 에서
|
||||
공급되어야 한다.
|
||||
- **검증은 `LoggingSettings`와 일관되게 "warn-and-default"다.** blank salt 는 경고를 남기고, 명확히
|
||||
|
||||
+18
-6
@@ -1,18 +1,20 @@
|
||||
package dev.caskeleton.composition.runtime.logging;
|
||||
|
||||
import dev.caskeleton.adapter.outbound.support.StrictSettingsBinder;
|
||||
import dev.caskeleton.adapter.outbound.support.startup.RuntimeWarnings;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
/**
|
||||
* Privacy settings bound from {@code ca-skeleton.privacy.*}. Holds the HMAC salt used to
|
||||
* pseudonymize {@code user_principal} in security/audit logs. A blank salt is "warn-and-default":
|
||||
* it logs a warning and falls back to a dev sentinel so local/test runs never fail to start. See
|
||||
* README for the design rationale.
|
||||
* Privacy settings bound from {@code app.privacy.*}. Holds the HMAC salt used to pseudonymize
|
||||
* {@code user_principal} in security/audit logs. A blank salt is "warn-and-default": it logs a
|
||||
* warning and falls back to a dev sentinel so local/test runs never fail to start. See README for
|
||||
* the design rationale.
|
||||
*/
|
||||
@ConfigurationProperties(prefix = "ca-skeleton.privacy")
|
||||
public record PrivacySettings(String pseudonymizationSalt) {
|
||||
|
||||
static final String PREFIX = "app.privacy";
|
||||
|
||||
/** Dev/local fallback salt — the {@code __LOCAL_DEV_} prefix is the prod-unsafe sentinel. */
|
||||
static final String DEV_SENTINEL_SALT = "__LOCAL_DEV_pseudonymization_salt";
|
||||
|
||||
@@ -27,6 +29,16 @@ public record PrivacySettings(String pseudonymizationSalt) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds {@link #PREFIX} strictly.
|
||||
*
|
||||
* @param environment the environment to bind from
|
||||
* @return the bound settings
|
||||
*/
|
||||
static PrivacySettings bind(Environment environment) {
|
||||
return StrictSettingsBinder.bind(environment, PREFIX, PrivacySettings.class);
|
||||
}
|
||||
|
||||
public byte[] saltBytes() {
|
||||
return pseudonymizationSalt.getBytes(StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
+6
-2
@@ -4,8 +4,8 @@ import dev.caskeleton.adapter.outbound.identifier.HmacUserPrincipalPseudonymizer
|
||||
import dev.caskeleton.application.observability.UserPrincipalPseudonymizerPort;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
/**
|
||||
* Composition-root wiring for {@code user_principal} pseudonymization.
|
||||
@@ -13,9 +13,13 @@ import org.springframework.context.annotation.Bean;
|
||||
* README for the design rationale.
|
||||
*/
|
||||
@AutoConfiguration
|
||||
@EnableConfigurationProperties(PrivacySettings.class)
|
||||
public class PseudonymizationConfig {
|
||||
|
||||
@Bean
|
||||
PrivacySettings privacySettings(Environment environment) {
|
||||
return PrivacySettings.bind(environment);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
UserPrincipalPseudonymizerPort userPrincipalPseudonymizer(PrivacySettings privacySettings) {
|
||||
|
||||
+12
-3
@@ -16,15 +16,24 @@ import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
/** Composition-root wiring for distributed tracing. See README for the design rationale. */
|
||||
@AutoConfiguration
|
||||
@EnableConfigurationProperties(TracingSettings.class)
|
||||
public class TracingConfig {
|
||||
|
||||
/**
|
||||
* The tracing settings, bound strictly. Static: this configuration takes them in its constructor.
|
||||
*
|
||||
* @param environment the environment to bind from
|
||||
* @return the bound settings
|
||||
*/
|
||||
@Bean
|
||||
static TracingSettings tracingSettings(Environment environment) {
|
||||
return TracingSettings.bind(environment);
|
||||
}
|
||||
|
||||
private final TracingSettings properties;
|
||||
private final Environment environment;
|
||||
private final ObjectProvider<MeterRegistry> meterRegistryProvider;
|
||||
@@ -58,7 +67,7 @@ public class TracingConfig {
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(Tracer.class)
|
||||
@ConditionalOnProperty(
|
||||
prefix = "ca-skeleton.tracing",
|
||||
prefix = "app.tracing",
|
||||
name = "enabled",
|
||||
havingValue = "true",
|
||||
matchIfMissing = true)
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ import org.springframework.core.env.MapPropertySource;
|
||||
public class TracingSamplingEnvironmentPostProcessor implements EnvironmentPostProcessor, Ordered {
|
||||
|
||||
private static final String NATIVE_KEY = "management.tracing.sampling.probability";
|
||||
private static final String CA_SAMPLE_RATE_KEY = "ca-skeleton.tracing.sample-rate";
|
||||
private static final String CA_SAMPLE_RATE_KEY = "app.tracing.sample-rate";
|
||||
|
||||
private final TracingSampleRateResolver resolver = new TracingSampleRateResolver();
|
||||
|
||||
|
||||
+16
-6
@@ -1,18 +1,28 @@
|
||||
package dev.caskeleton.composition.runtime.tracing;
|
||||
|
||||
import dev.caskeleton.adapter.outbound.support.StrictSettingsBinder;
|
||||
import dev.caskeleton.adapter.outbound.support.startup.StartupFailures;
|
||||
import java.net.URI;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
/**
|
||||
* Tracing settings bound from {@code ca-skeleton.tracing.*}. A blank {@code sampleRate} means
|
||||
* "defer to the per-profile default". See README for the design rationale.
|
||||
* Tracing settings bound from {@code app.tracing.*}. A blank {@code sampleRate} means "defer to the
|
||||
* per-profile default". See README for the design rationale.
|
||||
*/
|
||||
@ConfigurationProperties(prefix = "ca-skeleton.tracing")
|
||||
@Validated
|
||||
public record TracingSettings(boolean enabled, String sampleRate, Exporter exporter) {
|
||||
|
||||
static final String PREFIX = "app.tracing";
|
||||
|
||||
/**
|
||||
* Binds {@link #PREFIX} strictly.
|
||||
*
|
||||
* @param environment the environment to bind from
|
||||
* @return the bound settings
|
||||
*/
|
||||
static TracingSettings bind(Environment environment) {
|
||||
return StrictSettingsBinder.bind(environment, PREFIX, TracingSettings.class);
|
||||
}
|
||||
|
||||
/** Nested properties for the OTLP exporter endpoint. */
|
||||
public record Exporter(String otlpEndpoint) {
|
||||
|
||||
|
||||
+24
-1
@@ -15,7 +15,10 @@ import dev.caskeleton.shared.tracing.SpanErrorRecorder;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.context.annotation.ImportCandidates;
|
||||
@@ -72,13 +75,33 @@ class ServiceRuntimeRegistrationTest {
|
||||
assertThat(order).isEqualTo(StartupOrder.TRACING_SAMPLING);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"app.privacy.pseudonymisation-salt=typo", "app.tracing.sample-rat=0.5"})
|
||||
@DisplayName("app.privacy·app.tracing 아래 오타 키는 기동을 실패시킨다")
|
||||
void aMisspelledRuntimeKeyFailsStartup(String misspelled) {
|
||||
// given
|
||||
ApplicationContextRunner runner =
|
||||
new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(ROOTS.toArray(Class<?>[]::new)))
|
||||
.withPropertyValues("app.privacy.pseudonymization-salt=test-salt", misspelled);
|
||||
|
||||
// when
|
||||
runner.run(
|
||||
context -> {
|
||||
// then
|
||||
assertThat(context).hasFailed();
|
||||
assertThat(context.getStartupFailure())
|
||||
.hasStackTraceContaining(misspelled.substring(0, misspelled.indexOf('=')));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void aNonWebContextGetsTheRuntimeBeansWithoutAnActuatorChain() {
|
||||
// given
|
||||
ApplicationContextRunner runner =
|
||||
new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(ROOTS.toArray(Class<?>[]::new)))
|
||||
.withPropertyValues("ca-skeleton.privacy.pseudonymization-salt=test-salt");
|
||||
.withPropertyValues("app.privacy.pseudonymization-salt=test-salt");
|
||||
|
||||
// when
|
||||
runner.run(
|
||||
|
||||
+11
-5
@@ -11,9 +11,10 @@ import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
class PrivacySettingsTest {
|
||||
|
||||
@@ -51,7 +52,7 @@ class PrivacySettingsTest {
|
||||
@Test
|
||||
void blankSaltWarnsAndFallsBackToDevSentinel() {
|
||||
runner
|
||||
.withPropertyValues("ca-skeleton.privacy.pseudonymization-salt=")
|
||||
.withPropertyValues("app.privacy.pseudonymization-salt=")
|
||||
.run(
|
||||
context -> {
|
||||
assertThat(context).hasNotFailed();
|
||||
@@ -70,7 +71,7 @@ class PrivacySettingsTest {
|
||||
@Test
|
||||
void realSaltIsUsedAndExposedAsUtf8Bytes() {
|
||||
runner
|
||||
.withPropertyValues("ca-skeleton.privacy.pseudonymization-salt=prod-salt-9f")
|
||||
.withPropertyValues("app.privacy.pseudonymization-salt=prod-salt-9f")
|
||||
.run(
|
||||
context -> {
|
||||
assertThat(context).hasNotFailed();
|
||||
@@ -86,6 +87,11 @@ class PrivacySettingsTest {
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(PrivacySettings.class)
|
||||
static class EnableProperties {}
|
||||
static class EnableProperties {
|
||||
|
||||
@Bean
|
||||
PrivacySettings settings(Environment environment) {
|
||||
return PrivacySettings.bind(environment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ class PseudonymizationConfigTest {
|
||||
@Test
|
||||
void wiresAnHmacPseudonymizerThatRedactsThePrincipal() {
|
||||
runner
|
||||
.withPropertyValues("ca-skeleton.privacy.pseudonymization-salt=unit-salt-7c")
|
||||
.withPropertyValues("app.privacy.pseudonymization-salt=unit-salt-7c")
|
||||
.run(
|
||||
context -> {
|
||||
assertThat(context).hasNotFailed();
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ class TracingSamplingEnvironmentPostProcessorTest {
|
||||
void explicitRateWins() {
|
||||
MockEnvironment env = new MockEnvironment();
|
||||
env.setActiveProfiles("prod");
|
||||
env.setProperty("ca-skeleton.tracing.sample-rate", "0.25");
|
||||
env.setProperty("app.tracing.sample-rate", "0.25");
|
||||
|
||||
epp.postProcessEnvironment(env, new SpringApplication());
|
||||
|
||||
|
||||
+42
-36
@@ -7,9 +7,10 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import dev.caskeleton.adapter.outbound.support.startup.StartupErrorCode;
|
||||
import dev.caskeleton.adapter.outbound.support.startup.StartupFailureException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
/**
|
||||
* Settings binding + validation tests for {@link TracingSettings}
|
||||
@@ -28,9 +29,9 @@ class TracingSettingsTest {
|
||||
void validSampleRateIsBoundAndParseable() {
|
||||
runner
|
||||
.withPropertyValues(
|
||||
"ca-skeleton.tracing.enabled=true",
|
||||
"ca-skeleton.tracing.sample-rate=0.5",
|
||||
"ca-skeleton.tracing.exporter.otlp-endpoint=")
|
||||
"app.tracing.enabled=true",
|
||||
"app.tracing.sample-rate=0.5",
|
||||
"app.tracing.exporter.otlp-endpoint=")
|
||||
.run(
|
||||
ctx -> {
|
||||
assertThat(ctx).hasNotFailed();
|
||||
@@ -44,9 +45,9 @@ class TracingSettingsTest {
|
||||
void sampleRateZeroIsValidBoundary() {
|
||||
runner
|
||||
.withPropertyValues(
|
||||
"ca-skeleton.tracing.enabled=false",
|
||||
"ca-skeleton.tracing.sample-rate=0.0",
|
||||
"ca-skeleton.tracing.exporter.otlp-endpoint=")
|
||||
"app.tracing.enabled=false",
|
||||
"app.tracing.sample-rate=0.0",
|
||||
"app.tracing.exporter.otlp-endpoint=")
|
||||
.run(
|
||||
ctx -> {
|
||||
assertThat(ctx).hasNotFailed();
|
||||
@@ -58,9 +59,9 @@ class TracingSettingsTest {
|
||||
void sampleRateOneIsValidBoundary() {
|
||||
runner
|
||||
.withPropertyValues(
|
||||
"ca-skeleton.tracing.enabled=true",
|
||||
"ca-skeleton.tracing.sample-rate=1.0",
|
||||
"ca-skeleton.tracing.exporter.otlp-endpoint=")
|
||||
"app.tracing.enabled=true",
|
||||
"app.tracing.sample-rate=1.0",
|
||||
"app.tracing.exporter.otlp-endpoint=")
|
||||
.run(
|
||||
ctx -> {
|
||||
assertThat(ctx).hasNotFailed();
|
||||
@@ -73,9 +74,9 @@ class TracingSettingsTest {
|
||||
// required_test: tracing-contract:exporter-endpoint-resolvable (sampleRate sub-case)
|
||||
runner
|
||||
.withPropertyValues(
|
||||
"ca-skeleton.tracing.enabled=true",
|
||||
"ca-skeleton.tracing.sample-rate=1.5",
|
||||
"ca-skeleton.tracing.exporter.otlp-endpoint=")
|
||||
"app.tracing.enabled=true",
|
||||
"app.tracing.sample-rate=1.5",
|
||||
"app.tracing.exporter.otlp-endpoint=")
|
||||
.run(ctx -> assertThat(ctx).hasFailed());
|
||||
}
|
||||
|
||||
@@ -83,9 +84,9 @@ class TracingSettingsTest {
|
||||
void invalidSampleRateNonNumericFailsStartup() {
|
||||
runner
|
||||
.withPropertyValues(
|
||||
"ca-skeleton.tracing.enabled=true",
|
||||
"ca-skeleton.tracing.sample-rate=not-a-number",
|
||||
"ca-skeleton.tracing.exporter.otlp-endpoint=")
|
||||
"app.tracing.enabled=true",
|
||||
"app.tracing.sample-rate=not-a-number",
|
||||
"app.tracing.exporter.otlp-endpoint=")
|
||||
.run(ctx -> assertThat(ctx).hasFailed());
|
||||
}
|
||||
|
||||
@@ -93,9 +94,9 @@ class TracingSettingsTest {
|
||||
void negativeSampleRateFailsStartup() {
|
||||
runner
|
||||
.withPropertyValues(
|
||||
"ca-skeleton.tracing.enabled=true",
|
||||
"ca-skeleton.tracing.sample-rate=-0.1",
|
||||
"ca-skeleton.tracing.exporter.otlp-endpoint=")
|
||||
"app.tracing.enabled=true",
|
||||
"app.tracing.sample-rate=-0.1",
|
||||
"app.tracing.exporter.otlp-endpoint=")
|
||||
.run(ctx -> assertThat(ctx).hasFailed());
|
||||
}
|
||||
|
||||
@@ -107,9 +108,9 @@ class TracingSettingsTest {
|
||||
// required_test: tracing-contract:exporter-endpoint-resolvable (empty = exporter off)
|
||||
runner
|
||||
.withPropertyValues(
|
||||
"ca-skeleton.tracing.enabled=true",
|
||||
"ca-skeleton.tracing.sample-rate=1.0",
|
||||
"ca-skeleton.tracing.exporter.otlp-endpoint=")
|
||||
"app.tracing.enabled=true",
|
||||
"app.tracing.sample-rate=1.0",
|
||||
"app.tracing.exporter.otlp-endpoint=")
|
||||
.run(
|
||||
ctx -> {
|
||||
assertThat(ctx).hasNotFailed();
|
||||
@@ -122,9 +123,9 @@ class TracingSettingsTest {
|
||||
// required_test: tracing-contract:exporter-endpoint-resolvable (valid URL)
|
||||
runner
|
||||
.withPropertyValues(
|
||||
"ca-skeleton.tracing.enabled=true",
|
||||
"ca-skeleton.tracing.sample-rate=1.0",
|
||||
"ca-skeleton.tracing.exporter.otlp-endpoint=http://otel-collector:4317")
|
||||
"app.tracing.enabled=true",
|
||||
"app.tracing.sample-rate=1.0",
|
||||
"app.tracing.exporter.otlp-endpoint=http://otel-collector:4317")
|
||||
.run(
|
||||
ctx -> {
|
||||
assertThat(ctx).hasNotFailed();
|
||||
@@ -138,9 +139,9 @@ class TracingSettingsTest {
|
||||
// required_test: tracing-contract:exporter-endpoint-resolvable (malformed URL)
|
||||
runner
|
||||
.withPropertyValues(
|
||||
"ca-skeleton.tracing.enabled=true",
|
||||
"ca-skeleton.tracing.sample-rate=1.0",
|
||||
"ca-skeleton.tracing.exporter.otlp-endpoint=not a valid url$$")
|
||||
"app.tracing.enabled=true",
|
||||
"app.tracing.sample-rate=1.0",
|
||||
"app.tracing.exporter.otlp-endpoint=not a valid url$$")
|
||||
.run(ctx -> assertThat(ctx).hasFailed());
|
||||
}
|
||||
|
||||
@@ -149,9 +150,9 @@ class TracingSettingsTest {
|
||||
// url_or_empty: URI.create throws on illegal characters (spaces)
|
||||
runner
|
||||
.withPropertyValues(
|
||||
"ca-skeleton.tracing.enabled=true",
|
||||
"ca-skeleton.tracing.sample-rate=1.0",
|
||||
"ca-skeleton.tracing.exporter.otlp-endpoint=not valid url")
|
||||
"app.tracing.enabled=true",
|
||||
"app.tracing.sample-rate=1.0",
|
||||
"app.tracing.exporter.otlp-endpoint=not valid url")
|
||||
.run(ctx -> assertThat(ctx).hasFailed());
|
||||
}
|
||||
|
||||
@@ -159,9 +160,9 @@ class TracingSettingsTest {
|
||||
void enabledFlagIsBoundCorrectly() {
|
||||
runner
|
||||
.withPropertyValues(
|
||||
"ca-skeleton.tracing.enabled=false",
|
||||
"ca-skeleton.tracing.sample-rate=1.0",
|
||||
"ca-skeleton.tracing.exporter.otlp-endpoint=")
|
||||
"app.tracing.enabled=false",
|
||||
"app.tracing.sample-rate=1.0",
|
||||
"app.tracing.exporter.otlp-endpoint=")
|
||||
.run(
|
||||
ctx -> {
|
||||
assertThat(ctx).hasNotFailed();
|
||||
@@ -209,6 +210,11 @@ class TracingSettingsTest {
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(TracingSettings.class)
|
||||
static class EnableProperties {}
|
||||
static class EnableProperties {
|
||||
|
||||
@Bean
|
||||
TracingSettings settings(Environment environment) {
|
||||
return TracingSettings.bind(environment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user