Skip to content

Commit

Permalink
Adding version tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eyalkoren committed Nov 21, 2021
1 parent 0a79cb9 commit fec7104
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 23 deletions.
1 change: 1 addition & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ updates:
- dependency-name: "com.squareup.okhttp3:okhttp"
- dependency-name: "com.datastax.cassandra:cassandra-driver-core"
- dependency-name: "com.datastax.oss:java-driver-core"
- dependency-name: "io.micrometer:*"
ignore:
- dependency-name: "net.bytebuddy:byte-buddy-agent"
# We deliberately want to keep this older version of Byte Buddy for our runtime attach test
Expand Down
9 changes: 3 additions & 6 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,12 @@ endif::[]
=== Unreleased
[[release-notes-1.28.0]]
==== 1.28.0 - YYYY/MM/DD
[float]
===== Features
* Add support to Jakarta EE for JSF - {pull}2254[#2254]
[[release-notes-1.27.1]]
==== 1.27.1 - YYYY/MM/DD
[float]
===== Bug fixes
* Fixing missing Micrometer metrics in Spring boot due to premature initialization - {pull}2255[#2255]
[[release-notes-1.x]]
=== Java Agent version 1.x
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/**
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler (version 1.42.0)",
value = "by gRPC proto compiler (version 1.42.1)",
comments = "Source: rpc.proto")
@io.grpc.stub.annotations.GrpcGenerated
public final class HelloGrpc {
Expand Down
7 changes: 6 additions & 1 deletion apm-agent-plugins/apm-micrometer-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
<version>1.0.1</version>
<version>1.8.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.ivy</groupId>
<artifactId>ivy</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -28,47 +28,47 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import net.bytebuddy.agent.ByteBuddyAgent;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.stagemonitor.configuration.ConfigurationRegistry;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.doReturn;

class MicrometerInstrumentationTest {
public class MicrometerInstrumentationTest {

private MockReporter reporter;
private ConfigurationRegistry config;
private int lastMeasuredMetricSetNumber;
private int lastFooSamples;

@BeforeEach
void setUp() {
@Before
public void setUp() {
config = SpyConfiguration.createSpyConfig();
doReturn(50L).when(config.getConfig(ReporterConfiguration.class)).getMetricsIntervalMs();
reporter = new MockReporter();
lastMeasuredMetricSetNumber = 0;
lastFooSamples = 0;
}

@AfterEach
void tearDown() {
@After
public void tearDown() {
ElasticApmAgent.reset();
}

@Test
void testRegisterMeterRegistry() {
public void testRegisterMeterRegistry() {
ElasticApmAgent.initInstrumentation(MockTracer.createRealTracer(reporter, config), ByteBuddyAgent.install());
SimpleMeterRegistry registry = new SimpleMeterRegistry();
registry.counter("foo").increment();
reporter.awaitUntilAsserted(() -> assertThat(countFooSamples()).isGreaterThanOrEqualTo(1));
}

@Test
void testReportedWhenInstrumentConfigDisabled() {
public void testReportedWhenInstrumentConfigDisabled() {
doReturn(false).when(config.getConfig(CoreConfiguration.class)).isInstrument();
ElasticApmAgent.initInstrumentation(MockTracer.createRealTracer(reporter, config), ByteBuddyAgent.install());
SimpleMeterRegistry registry = new SimpleMeterRegistry();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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.TestClassWithDependencyRunner;
import org.junit.Test;

public class MicrometerInstrumentationVersionsIT {

private final TestClassWithDependencyRunner runner;

public MicrometerInstrumentationVersionsIT() throws Exception {
this.runner = new TestClassWithDependencyRunner("io.micrometer", "micrometer-core", "1.0.1",
MicrometerInstrumentationTest.class
);
}

@Test
public void testOldVersion() {
runner.run();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,6 @@ void testExclusionOfFailedGauge_singleGauge() {
.isEmpty();

getMetricSets();
assertThat(metricsReporter.getFailedMeters().iterator().next().getId().getName()).isEqualTo("gauge1");
}

@Test
Expand All @@ -386,7 +385,6 @@ void testExclusionOfFailedGauge_firstFails() {

// serialization should handle ignoring the 1st value
assertThat(metricSet.get("metricset").get("samples").get("gauge2").get("value").doubleValue()).isEqualTo(42D);
assertThat(metricsReporter.getFailedMeters().iterator().next().getId().getName()).isEqualTo("gauge1");
}

@Test
Expand All @@ -405,8 +403,6 @@ void testExclusionOfFailedGauge_secondFails() {
assertThat(metricSet.get("metricset").get("samples").get("gauge2"))
.describedAs("value of %s is not expected to be written to json", "gauge1")
.isNull();

assertThat(metricsReporter.getFailedMeters().iterator().next().getId().getName()).isEqualTo("gauge2");
}

@Test
Expand Down Expand Up @@ -441,7 +437,7 @@ void testNotReportingEmptySamples() {

@Test
void tryToSerializeInvalidTimerValues() {
for (Double invalidValue : Arrays.asList(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, Double.NaN)) {
for (Double invalidValue : Arrays.asList(Double.POSITIVE_INFINITY, Double.NaN)) {
List<Tag> tags = List.of(Tag.of("foo", "bar"));
meterRegistry.more().timer("custom-timer-1", tags, 42, v -> 42L, v -> invalidValue, TimeUnit.MICROSECONDS);
meterRegistry.more().timer("custom-timer-2", tags, 42, v -> 42L, v -> 42D, TimeUnit.MICROSECONDS);
Expand Down

0 comments on commit fec7104

Please sign in to comment.