Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,18 @@ public final class ReportingConfigImpl implements ReportingConfig {
private final Opa opa;
private final Config.Reporting reporting;

public ReportingConfigImpl(final Config.Reporting reporting) {
this.opa = new OpaImpl(reporting.getOpa());
this.reporting = reporting;
/**
* This constructor is required in order to be instantiated by the {@link java.util.ServiceLoader}
* API.
*/
@SuppressWarnings("unused")
public ReportingConfigImpl() {
this(HypertraceConfig.get().getReporting());
}

public ReportingConfigImpl(final Config.Reporting reportingConfig) {
this.reporting = reportingConfig;
this.opa = new OpaImpl(reportingConfig.getOpa());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright The Hypertrace Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.hypertrace.agent.otel.extensions.config;

import static org.junit.jupiter.api.Assertions.*;

import com.google.protobuf.BoolValue;
import java.util.Iterator;
import java.util.ServiceLoader;
import org.hypertrace.agent.config.Config.Opa;
import org.hypertrace.agent.config.Config.Reporting;
import org.hypertrace.agent.config.Config.Reporting.Builder;
import org.hypertrace.agent.core.config.ReportingConfig;
import org.junit.jupiter.api.Test;

final class ReportingConfigImplTest {

@Test
void instantiateViaServiceLoaderApi() {
final ServiceLoader<ReportingConfig> reportingConfigs =
ServiceLoader.load(ReportingConfig.class);
final Iterator<ReportingConfig> iterator = reportingConfigs.iterator();
assertTrue(iterator.hasNext());
final ReportingConfig reportingConfig = iterator.next();
assertNotNull(reportingConfig);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could check the config type.

assertFalse(iterator.hasNext());
}

@Test
void opaEnabledIfNotProvided() {
final ReportingConfigImpl reportingConfig =
new ReportingConfigImpl(Reporting.getDefaultInstance());
assertTrue(reportingConfig.opa().enabled());
}

@Test
void opaDisabledIfExplicitlySet() {
final Builder reportingBuilder = Reporting.getDefaultInstance().toBuilder();
final Opa explicitOpaConfig =
reportingBuilder.getOpaBuilder().setEnabled(BoolValue.of(false)).build();
final ReportingConfigImpl reportingConfig =
new ReportingConfigImpl(reportingBuilder.setOpa(explicitOpaConfig).build());
assertFalse(reportingConfig.opa().enabled());
}
}