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
@@ -0,0 +1,47 @@
/**
* Copyright 2021 VMware, Inc.
* <p>
* 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
* <p>
* https://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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 io.micrometer.dynatrace;

import io.micrometer.core.instrument.Clock;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.ipc.http.HttpSender;

import javax.annotation.Nonnull;
import java.util.concurrent.TimeUnit;

/**
* Base class for implementations of Dynatrace exporters.
*
* @author Georg Pirklbauer
*/
public abstract class AbstractDynatraceExporter {

protected DynatraceConfig config;
protected Clock clock;
protected HttpSender httpClient;

public abstract void export(@Nonnull MeterRegistry registry);

public TimeUnit getBaseTimeUnit() {
return TimeUnit.MILLISECONDS;
}

public AbstractDynatraceExporter(DynatraceConfig config, Clock clock, HttpSender httpClient) {
this.config = config;
this.clock = clock;
this.httpClient = httpClient;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Copyright 2021 VMware, Inc.
* <p>
* 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
* <p>
* https://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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 io.micrometer.dynatrace;

/**
* An enum containing valid Dynatrace API versions.
*/
public enum DynatraceApiVersion {
V1,
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* Configuration for {@link DynatraceMeterRegistry}
*
* @author Oriol Barcelona
* @author Georg Pirklbauer
*/
public interface DynatraceConfig extends StepRegistryConfig {

Expand All @@ -49,7 +50,7 @@ default String deviceId() {

default String technologyType() {
return getSecret(this, "technologyType")
.map(v -> StringUtils.isEmpty(v) ? "java" : v)
.map(val -> StringUtils.isEmpty(val) ? "java" : val)
.get();
}

Expand All @@ -64,8 +65,28 @@ default String group() {
return get(prefix() + ".group");
}

/**
* Return the version of the target Dynatrace API.
*
* @return a {@link DynatraceApiVersion} containing the version of the targeted Dynatrace API.
*/
default DynatraceApiVersion apiVersion() {
// if not specified, defaults to v1 for backwards compatibility.
return getEnum(this, DynatraceApiVersion.class, "apiVersion")
.orElse(DynatraceApiVersion.V1);
}

@Override
default Validated<?> validate() {
Validated<DynatraceApiVersion> apiVersionValidation = checkRequired("apiVersion", DynatraceConfig::apiVersion).apply(this);
if (apiVersionValidation.isInvalid()) {
return apiVersionValidation;
}

return validateV1();
}

default Validated<?> validateV1() {
return checkAll(this,
c -> StepRegistryConfig.validate(c),
checkRequired("apiToken", DynatraceConfig::apiToken),
Expand Down
Loading