Skip to content

Commit

Permalink
apply review
Browse files Browse the repository at this point in the history
  • Loading branch information
heowc committed Apr 24, 2024
1 parent de2ea96 commit 2d6f0b8
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 29 deletions.
9 changes: 4 additions & 5 deletions docs/modules/ROOT/pages/spring-cloud-netflix.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -606,15 +606,14 @@ Spring Cloud Netflix Eureka Server does not support Spring AOT transformations o

=== Metrics

Starting with version 4.1.1, `MultuGuage` listens events related to Eureka instances and creates and updates Eureka instance information in the metrics registry. By default, this setting is disabled, if you want to enable it, you need to change `eureka.server.metrics.enabled` to `true`.
`EurekaInstanceMonitor` listens to events related to Eureka instance registration and creates/updates `Gauge`s for Eureka instance information Micrometer's `MeterRegistry`. By default, this behavior is disabled. Ff you want to enable it, you need to set `eureka.server.metrics.enabled` to `true`.

The multi-gauge is named `eureka.server.instance.status` and has the following tags (value are merged based on tags)
By default, the `Gauge`s are named `eureka.server.instances` and have the following tags:

- `application`: application name
- `status`: instance status (`UP`, `DOWN`, `STARTING`, `OUT_OF_SERVICE`, `UNKNOWN`, see: `com.netflix.appinfo.InstanceInfo.InstanceStatus`)

- `status`: instance status

You can add additional tags by implementing `EurekaInstanceTagsProvider` separately. However, status is added separately because it is always needed.
You can add additional tags by injecting your own implementation of `EurekaInstanceTagsProvider`.

== Configuration properties

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* Default implementation for {@link EurekaInstanceTagsProvider}.
*
* @author Wonchul Heo
* @since 4.1.1
* @since 4.1.2
*/
class DefaultEurekaInstanceTagsProvider implements EurekaInstanceTagsProvider {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
/**
* Auto-configuration for Eureka Instance metrics.
*
* @author wonchul heo
* @since 4.1.1
* @author Wonchul Heo
* @since 4.1.2
*/
@ConditionalOnClass(MeterRegistry.class)
@ConditionalOnBean(MeterRegistry.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* {@link PeerAwareInstanceRegistry}.
*
* @author Wonchul Heo
* @since 4.1.1
* @since 4.1.2
*/
public class EurekaInstanceMonitor implements SmartApplicationListener {

Expand All @@ -52,12 +52,13 @@ public class EurekaInstanceMonitor implements SmartApplicationListener {
this.instanceRegistry = Objects.requireNonNull(instanceRegistry);
this.tagProvider = Objects.requireNonNull(tagProvider);
this.eurekaInstances = MultiGauge.builder("eureka.server.instances")
.description("Count of application instances registered with the Eureka server.")
.description("Number of application instances registered with the Eureka server.")
.register(meterRegistry);
}

@Override
public boolean supportsEventType(Class<? extends ApplicationEvent> eventType) {
// If events that change state are added, an event class must be added.
return EurekaInstanceCanceledEvent.class.isAssignableFrom(eventType)
|| EurekaInstanceRegisteredEvent.class.isAssignableFrom(eventType)
|| EurekaInstanceRenewedEvent.class.isAssignableFrom(eventType);
Expand All @@ -69,6 +70,7 @@ public void onApplicationEvent(ApplicationEvent event) {
.flatMap(application -> application.getInstances().stream())
.collect(Collectors.groupingBy(tagProvider::eurekaInstanceTags, Collectors.counting()));
eurekaInstances.register(aggregatedCounts.entrySet().stream()
.map(it -> MultiGauge.Row.of(it.getKey(), it.getValue())).collect(Collectors.toList()), true);
.map(entry -> MultiGauge.Row.of(entry.getKey(), entry.getValue())).collect(Collectors.toList()), true);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@
package org.springframework.cloud.netflix.eureka.server.metrics;

import com.netflix.appinfo.InstanceInfo;
import io.micrometer.core.instrument.Tag;
import io.micrometer.core.instrument.Tags;

/**
* Provides {@link Tag Tags} for Eureka instance metrics.
* Provides {@link Tags} for Eureka instance metrics.
*
* @author Wonchul Heo
* @since 4.1.1
* @since 4.1.2
*/
public interface EurekaInstanceTagsProvider {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import com.netflix.appinfo.InstanceInfo;
import com.netflix.appinfo.LeaseInfo;

public final class EurekaInstancesFixture {
public final class EurekaInstanceFixture {

private EurekaInstancesFixture() {
private EurekaInstanceFixture() {
}

public static LeaseInfo getLeaseInfo() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Tag;
import io.micrometer.core.instrument.Tags;
import io.micrometer.core.instrument.search.MeterNotFoundException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand All @@ -32,9 +31,8 @@
import org.springframework.context.annotation.Configuration;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.springframework.cloud.netflix.eureka.server.EurekaInstancesFixture.getInstanceInfo;
import static org.springframework.cloud.netflix.eureka.server.EurekaInstancesFixture.getLeaseInfo;
import static org.springframework.cloud.netflix.eureka.server.EurekaInstanceFixture.getInstanceInfo;
import static org.springframework.cloud.netflix.eureka.server.EurekaInstanceFixture.getLeaseInfo;

/**
* @author Wonchul Heo
Expand All @@ -45,6 +43,7 @@
class EurekaInstanceMonitorTests {

private static final String FOO_APP_NAME = "FOO-APP-NAME";

private static final String BAR_APP_NAME = "BAR-APP-NAME";

@Autowired
Expand All @@ -54,8 +53,11 @@ class EurekaInstanceMonitorTests {
private MeterRegistry meterRegistry;

private InstanceInfo fooInstanceInfo;

private InstanceInfo fooInstanceInfo2;

private InstanceInfo barInstanceInfo;

private InstanceInfo barInstanceInfo2;

@BeforeEach
Expand All @@ -70,9 +72,7 @@ void setup() {

@Test
void testNoRegistration() {
assertThatThrownBy(() -> {
meterRegistry.get("eureka.server.instances").meter();
}).isInstanceOf(MeterNotFoundException.class);
assertThat(meterRegistry.find("eureka.server.instances").gauge()).isNull();
}

@Test
Expand Down Expand Up @@ -151,10 +151,9 @@ private static Tags tags(InstanceInfo instanceInfo) {
}

private void assertEurekaInstance(Map<Tags, Long> meterRegistryCounts) {
meterRegistryCounts.forEach((tags, count) -> {
assertThat((long) meterRegistry.get("eureka.server.instances").tags(tags).gauge().value())
.isEqualTo(count);
});
meterRegistryCounts.forEach((tags,
count) -> assertThat((long) meterRegistry.get("eureka.server.instances").tags(tags).gauge().value())
.isEqualTo(count));
}

@Configuration(proxyBeanMethods = false)
Expand All @@ -163,4 +162,5 @@ private void assertEurekaInstance(Map<Tags, Long> meterRegistryCounts) {
protected static class Application {

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
import org.springframework.context.event.SmartApplicationListener;

import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.cloud.netflix.eureka.server.EurekaInstancesFixture.getInstanceInfo;
import static org.springframework.cloud.netflix.eureka.server.EurekaInstancesFixture.getLeaseInfo;
import static org.springframework.cloud.netflix.eureka.server.EurekaInstanceFixture.getInstanceInfo;
import static org.springframework.cloud.netflix.eureka.server.EurekaInstanceFixture.getLeaseInfo;

/**
* @author Bartlomiej Slota
Expand Down

0 comments on commit 2d6f0b8

Please sign in to comment.