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 @@ -192,7 +192,8 @@ public class ReporterConfiguration extends ConfigurationOptionProvider {
.key("metrics_interval")
.tags("added[1.3.0]")
.configurationCategory(REPORTER_CATEGORY)
.description("The interval at which the agent sends metrics to the APM Server.\n" +
.description("The interval at which the agent sends metrics to the APM Server, rounded down to the nearest second (ie 3783ms would be applied as 3000ms).\n" +
"If there is an interval (step) defined in the Meter, that interval (to the nearest second) will instead be used, for that Meter. If the Meter step interval is less than 1 second, the meter will not be reported.\n" +
"Must be at least `1s`.\n" +
"Set to `0s` to deactivate.")
.addValidator(isNotInRange(TimeDuration.of("1ms"), TimeDuration.of("999ms")))
Expand Down Expand Up @@ -292,8 +293,9 @@ public long getApiRequestSize() {
return apiRequestSize.get().getBytes();
}

//Only whole seconds are used, so drop the fractional part at 1 second resolution
public long getMetricsIntervalMs() {
return metricsInterval.get().getMillis();
return (metricsInterval.get().getMillis()/1000L)*1000L;
}

public List<WildcardMatcher> getDisableMetrics() {
Expand Down
1 change: 1 addition & 0 deletions apm-agent-plugins/apm-micrometer-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<!-- micrometer is compiled for java8 -->
<maven.compiler.target>8</maven.compiler.target>
<maven.compiler.source>8</maven.compiler.source>
<animal.sniffer.skip>true</animal.sniffer.skip>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you 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 co.elastic.apm.agent.micrometer;

import co.elastic.apm.agent.bci.TracerAwareInstrumentation;
import co.elastic.apm.agent.impl.GlobalTracer;

import java.util.Collection;
import java.util.Collections;

public abstract class AbstractMicrometerInstrumentation extends TracerAwareInstrumentation {

static final MicrometerMetricsReporter reporter = new MicrometerMetricsReporter(GlobalTracer.requireTracerImpl());

public Collection<String> getInstrumentationGroupNames() {
return Collections.singletonList("micrometer");
}

@Override
public boolean includeWhenInstrumentationIsDisabled() {
return true;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you 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 co.elastic.apm.agent.micrometer;

import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.simple.SimpleConfig;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;

import static net.bytebuddy.matcher.ElementMatchers.isConstructor;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
import static net.bytebuddy.matcher.ElementMatchers.takesNoArguments;

/**
* SimpleMeterRegistry is constructed with a SimpleConfig, but the config is not accessible via
* a config() method because the superclass declares a config() which returns a different config
* private to the superclass, and the SimpleMeterRegistry doesn't override that nor provide a different
* method to access the SimpleConfig. So this instrumentation is just to access that config.
*/
public class MicrometerConfigInstrumentation extends AbstractMicrometerInstrumentation {

@Override
public ElementMatcher<? super TypeDescription> getTypeMatcher() {
return named("io.micrometer.core.instrument.simple.SimpleMeterRegistry");
}

@Override
public ElementMatcher<? super MethodDescription> getMethodMatcher() {
return named("getMetersAsString").and(takesNoArguments()).or(isConstructor().and(takesArgument(0, named("io.micrometer.core.instrument.simple.SimpleConfig"))));
}

public static class AdviceClass {
@Advice.OnMethodExit(suppress = Throwable.class, inline = false)
public static void onExit(@Advice.This MeterRegistry meterRegistry, @Advice.FieldValue("config") SimpleConfig config) {
reporter.addConfig(meterRegistry, config);

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,15 @@
*/
package co.elastic.apm.agent.micrometer;

import co.elastic.apm.agent.bci.TracerAwareInstrumentation;
import co.elastic.apm.agent.impl.GlobalTracer;
import io.micrometer.core.instrument.MeterRegistry;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;

import java.util.Collection;
import java.util.Collections;

import static net.bytebuddy.matcher.ElementMatchers.named;

public class MicrometerInstrumentation extends TracerAwareInstrumentation {

private static final MicrometerMetricsReporter reporter = new MicrometerMetricsReporter(GlobalTracer.requireTracerImpl());
public class MicrometerInstrumentation extends AbstractMicrometerInstrumentation {

@Override
public ElementMatcher<? super TypeDescription> getTypeMatcher() {
Expand All @@ -45,16 +38,6 @@ public ElementMatcher<? super MethodDescription> getMethodMatcher() {
return named("registerMeterIfNecessary");
}

@Override
public Collection<String> getInstrumentationGroupNames() {
return Collections.singletonList("micrometer");
}

@Override
public boolean includeWhenInstrumentationIsDisabled() {
return true;
}

public static class AdviceClass {
@Advice.OnMethodExit(suppress = Throwable.class, inline = false)
public static void onExit(@Advice.This MeterRegistry meterRegistry) {
Expand Down
Loading