@Test void testMerge() { TracingConfig older = TracingConfig.create(config.get("unit3.tracing-older")); TracingConfig newer = TracingConfig.create(config.get("unit3.tracing-newer")); TracingConfig merged = TracingConfig.merge(older, newer); assertThat(older.enabled(), is(true)); assertThat(newer.isEnabled(), is(EMPTY)); assertThat(merged.enabled(), is(true)); ComponentTracingConfig ws = older.component("web-server"); assertThat(ws.enabled(), is(true)); ws = newer.component("web-server"); assertThat(ws.enabled(), is(false)); ws = merged.component("web-server"); assertThat(ws.enabled(), is(false)); Optional<ComponentTracingConfig> component = older.getComponent("security"); assertThat(component, is(EMPTY)); component = newer.getComponent("security"); assertThat(component, not(EMPTY)); ComponentTracingConfig security = component.get(); assertThat(security.isEnabled(), is(EMPTY)); Optional<SpanTracingConfig> tracedSpan = security.getSpan("security:atn"); assertThat(tracedSpan, not(EMPTY)); SpanTracingConfig span = tracedSpan.get(); assertThat(span.enabled(), is(false)); component = merged.getComponent("security"); assertThat(component, not(EMPTY)); security = component.get(); assertThat(security.isEnabled(), is(EMPTY)); tracedSpan = security.getSpan("security:atn"); assertThat(tracedSpan, not(EMPTY)); span = tracedSpan.get(); assertThat(span.enabled(), is(false)); assertThat(span.logEnabled("any", true), is(false)); }
public static TracingConfig merge(TracingConfig older, TracingConfig newer) { return new TracingConfig(newer.name()) { @Override public Optional<ComponentTracingConfig> getComponent(String componentName) { Optional<ComponentTracingConfig> newerComponent = newer.getComponent(componentName); Optional<ComponentTracingConfig> olderComponent = older.getComponent(componentName); if (newerComponent.isPresent() && olderComponent.isPresent()) { return Optional.of(ComponentTracingConfig.merge(olderComponent.get(), newerComponent.get())); } if (newerComponent.isPresent()) { return newerComponent; } return olderComponent; } @Override public Optional<Boolean> isEnabled() { return newer.isEnabled() .or(older::isEnabled); } }; }
TracingConfig extends Traceable { public static TracingConfig merge(TracingConfig older, TracingConfig newer) { return new TracingConfig(newer.name()) { @Override public Optional<ComponentTracingConfig> getComponent(String componentName) { Optional<ComponentTracingConfig> newerComponent = newer.getComponent(componentName); Optional<ComponentTracingConfig> olderComponent = older.getComponent(componentName); if (newerComponent.isPresent() && olderComponent.isPresent()) { return Optional.of(ComponentTracingConfig.merge(olderComponent.get(), newerComponent.get())); } if (newerComponent.isPresent()) { return newerComponent; } return olderComponent; } @Override public Optional<Boolean> isEnabled() { return newer.isEnabled() .or(older::isEnabled); } }; } }
TracingConfig extends Traceable { public static TracingConfig merge(TracingConfig older, TracingConfig newer) { return new TracingConfig(newer.name()) { @Override public Optional<ComponentTracingConfig> getComponent(String componentName) { Optional<ComponentTracingConfig> newerComponent = newer.getComponent(componentName); Optional<ComponentTracingConfig> olderComponent = older.getComponent(componentName); if (newerComponent.isPresent() && olderComponent.isPresent()) { return Optional.of(ComponentTracingConfig.merge(olderComponent.get(), newerComponent.get())); } if (newerComponent.isPresent()) { return newerComponent; } return olderComponent; } @Override public Optional<Boolean> isEnabled() { return newer.isEnabled() .or(older::isEnabled); } }; } protected  TracingConfig(String name); }
TracingConfig extends Traceable { public static TracingConfig merge(TracingConfig older, TracingConfig newer) { return new TracingConfig(newer.name()) { @Override public Optional<ComponentTracingConfig> getComponent(String componentName) { Optional<ComponentTracingConfig> newerComponent = newer.getComponent(componentName); Optional<ComponentTracingConfig> olderComponent = older.getComponent(componentName); if (newerComponent.isPresent() && olderComponent.isPresent()) { return Optional.of(ComponentTracingConfig.merge(olderComponent.get(), newerComponent.get())); } if (newerComponent.isPresent()) { return newerComponent; } return olderComponent; } @Override public Optional<Boolean> isEnabled() { return newer.isEnabled() .or(older::isEnabled); } }; } protected  TracingConfig(String name); ComponentTracingConfig component(String componentName); ComponentTracingConfig component(String componentName, boolean enabledByDefault); @Override String toString(); static TracingConfig create(Config config); static Builder builder(); static TracingConfig merge(TracingConfig older, TracingConfig newer); SpanTracingConfig spanConfig(String component, String spanName); }
TracingConfig extends Traceable { public static TracingConfig merge(TracingConfig older, TracingConfig newer) { return new TracingConfig(newer.name()) { @Override public Optional<ComponentTracingConfig> getComponent(String componentName) { Optional<ComponentTracingConfig> newerComponent = newer.getComponent(componentName); Optional<ComponentTracingConfig> olderComponent = older.getComponent(componentName); if (newerComponent.isPresent() && olderComponent.isPresent()) { return Optional.of(ComponentTracingConfig.merge(olderComponent.get(), newerComponent.get())); } if (newerComponent.isPresent()) { return newerComponent; } return olderComponent; } @Override public Optional<Boolean> isEnabled() { return newer.isEnabled() .or(older::isEnabled); } }; } protected  TracingConfig(String name); ComponentTracingConfig component(String componentName); ComponentTracingConfig component(String componentName, boolean enabledByDefault); @Override String toString(); static TracingConfig create(Config config); static Builder builder(); static TracingConfig merge(TracingConfig older, TracingConfig newer); SpanTracingConfig spanConfig(String component, String spanName); static final TracingConfig ENABLED; static final TracingConfig DISABLED; }