Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spring-cloud-netflix
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
spring-cloud-netflix
Commits
c544f4ae
Unverified
Commit
c544f4ae
authored
Sep 28, 2017
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move zuul metrics to micrometer.
fixes gh-2317
parent
0ce21c4b
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
50 additions
and
58 deletions
+50
-58
pom.xml
spring-cloud-netflix-core/pom.xml
+5
-0
ZuulServerAutoConfiguration.java
...ework/cloud/netflix/zuul/ZuulServerAutoConfiguration.java
+6
-5
DefaultCounterFactory.java
...ork/cloud/netflix/zuul/metrics/DefaultCounterFactory.java
+7
-6
DefaultCounterFactoryTests.java
...loud/netflix/zuul/metrics/DefaultCounterFactoryTests.java
+11
-3
ZuulEmptyMetricsApplicationTests.java
...etflix/zuul/metrics/ZuulEmptyMetricsApplicationTests.java
+4
-7
ZuulMetricsApplicationTests.java
...oud/netflix/zuul/metrics/ZuulMetricsApplicationTests.java
+17
-37
No files found.
spring-cloud-netflix-core/pom.xml
View file @
c544f4ae
...
@@ -187,6 +187,11 @@
...
@@ -187,6 +187,11 @@
<optional>
true
</optional>
<optional>
true
</optional>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
io.micrometer
</groupId>
<artifactId>
micrometer-core
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
<scope>
test
</scope>
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/ZuulServerAutoConfiguration.java
View file @
c544f4ae
...
@@ -64,6 +64,8 @@ import com.netflix.zuul.http.ZuulServlet;
...
@@ -64,6 +64,8 @@ import com.netflix.zuul.http.ZuulServlet;
import
com.netflix.zuul.monitoring.CounterFactory
;
import
com.netflix.zuul.monitoring.CounterFactory
;
import
com.netflix.zuul.monitoring.TracerFactory
;
import
com.netflix.zuul.monitoring.TracerFactory
;
import
io.micrometer.core.instrument.MeterRegistry
;
/**
/**
* @author Spencer Gibb
* @author Spencer Gibb
* @author Dave Syer
* @author Dave Syer
...
@@ -197,14 +199,13 @@ public class ZuulServerAutoConfiguration {
...
@@ -197,14 +199,13 @@ public class ZuulServerAutoConfiguration {
}
}
@Configuration
@Configuration
//FIXME: 2.0.0
@ConditionalOnClass
(
MeterRegistry
.
class
)
// @ConditionalOnClass(CounterService.class)
protected
static
class
ZuulCounterFactoryConfiguration
{
protected
static
class
ZuulCounterFactoryConfiguration
{
@Bean
@Bean
// @ConditionalOnBean(CounterService
.class)
@ConditionalOnBean
(
MeterRegistry
.
class
)
public
CounterFactory
counterFactory
(
/*CounterService counterService*/
)
{
public
CounterFactory
counterFactory
(
MeterRegistry
meterRegistry
)
{
return
new
DefaultCounterFactory
(
/*counterService*/
);
return
new
DefaultCounterFactory
(
meterRegistry
);
}
}
}
}
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/metrics/DefaultCounterFactory.java
View file @
c544f4ae
...
@@ -18,22 +18,23 @@ package org.springframework.cloud.netflix.zuul.metrics;
...
@@ -18,22 +18,23 @@ package org.springframework.cloud.netflix.zuul.metrics;
import
com.netflix.zuul.monitoring.CounterFactory
;
import
com.netflix.zuul.monitoring.CounterFactory
;
import
io.micrometer.core.instrument.MeterRegistry
;
/**
/**
* A counter based monitoring factory that uses {@link
CounterService
} to increment counters.
* A counter based monitoring factory that uses {@link
MeterRegistry
} to increment counters.
*
*
* @author Anastasiia Smirnova
* @author Anastasiia Smirnova
*/
*/
public
class
DefaultCounterFactory
extends
CounterFactory
{
public
class
DefaultCounterFactory
extends
CounterFactory
{
//FIXME: 2.0.0
private
final
MeterRegistry
meterRegistry
;
// private final CounterService counterService;
public
DefaultCounterFactory
(
/*CounterService counterService*/
)
{
public
DefaultCounterFactory
(
MeterRegistry
meterRegistry
)
{
/*this.counterService = counterService;*/
this
.
meterRegistry
=
meterRegistry
;
}
}
@Override
@Override
public
void
increment
(
String
name
)
{
public
void
increment
(
String
name
)
{
// counterService.increment(name
);
this
.
meterRegistry
.
counter
(
name
).
increment
(
);
}
}
}
}
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/metrics/DefaultCounterFactoryTests.java
View file @
c544f4ae
...
@@ -19,21 +19,28 @@ package org.springframework.cloud.netflix.zuul.metrics;
...
@@ -19,21 +19,28 @@ package org.springframework.cloud.netflix.zuul.metrics;
import
com.netflix.zuul.monitoring.CounterFactory
;
import
com.netflix.zuul.monitoring.CounterFactory
;
import
io.micrometer.core.instrument.Counter
;
import
io.micrometer.core.instrument.MeterRegistry
;
import
org.junit.Test
;
import
org.junit.Test
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
public
class
DefaultCounterFactoryTests
{
public
class
DefaultCounterFactoryTests
{
private
static
final
String
NAME
=
"my-super-metric-name"
;
private
static
final
String
NAME
=
"my-super-metric-name"
;
// private final CounterService counterService = mock(CounterService.class);
private
final
CounterFactory
factory
=
new
DefaultCounterFactory
(
/*counterService*/
);
@Test
@Test
public
void
shouldIncrement
()
throws
Exception
{
public
void
shouldIncrement
()
throws
Exception
{
MeterRegistry
meterRegistry
=
mock
(
MeterRegistry
.
class
);
CounterFactory
factory
=
new
DefaultCounterFactory
(
meterRegistry
);
Counter
counter
=
mock
(
Counter
.
class
);
when
(
meterRegistry
.
counter
(
NAME
)).
thenReturn
(
counter
);
factory
.
increment
(
NAME
);
factory
.
increment
(
NAME
);
//FIXME 2.0.0 verify(counterService).increment(NAME
);
verify
(
counter
).
increment
(
);
}
}
}
}
\ No newline at end of file
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/metrics/ZuulEmptyMetricsApplicationTests.java
View file @
c544f4ae
...
@@ -17,11 +17,13 @@
...
@@ -17,11 +17,13 @@
package
org
.
springframework
.
cloud
.
netflix
.
zuul
.
metrics
;
package
org
.
springframework
.
cloud
.
netflix
.
zuul
.
metrics
;
import
org.junit.Ignore
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.springframework.boot.autoconfigure.web.ServerProperties
;
import
org.springframework.boot.autoconfigure.web.ServerProperties
;
import
org.springframework.cloud.test.ClassPathExclusions
;
import
org.springframework.cloud.netflix.zuul.ZuulServerAutoConfiguration
;
import
org.springframework.cloud.netflix.zuul.ZuulServerAutoConfiguration
;
import
org.springframework.cloud.netflix.zuul.ZuulServerMarkerConfiguration
;
import
org.springframework.cloud.netflix.zuul.ZuulServerMarkerConfiguration
;
import
org.springframework.cloud.test.ClassPathExclusions
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
...
@@ -29,10 +31,6 @@ import org.springframework.context.annotation.Configuration;
...
@@ -29,10 +31,6 @@ import org.springframework.context.annotation.Configuration;
import
com.netflix.zuul.monitoring.CounterFactory
;
import
com.netflix.zuul.monitoring.CounterFactory
;
import
com.netflix.zuul.monitoring.TracerFactory
;
import
com.netflix.zuul.monitoring.TracerFactory
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
@ClassPathExclusions
({
"spring-boot-starter-actuator-*.jar"
,
@ClassPathExclusions
({
"spring-boot-starter-actuator-*.jar"
,
...
@@ -59,7 +57,6 @@ public class ZuulEmptyMetricsApplicationTests {
...
@@ -59,7 +57,6 @@ public class ZuulEmptyMetricsApplicationTests {
}
}
@Test
@Test
@Ignore
//FIXME: 2.0.0
public
void
shouldSetupDefaultCounterFactoryIfCounterServiceIsPresent
()
public
void
shouldSetupDefaultCounterFactoryIfCounterServiceIsPresent
()
throws
Exception
{
throws
Exception
{
CounterFactory
factory
=
this
.
context
.
getBean
(
CounterFactory
.
class
);
CounterFactory
factory
=
this
.
context
.
getBean
(
CounterFactory
.
class
);
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/metrics/ZuulMetricsApplicationTests.java
View file @
c544f4ae
...
@@ -17,10 +17,8 @@
...
@@ -17,10 +17,8 @@
package
org
.
springframework
.
cloud
.
netflix
.
zuul
.
metrics
;
package
org
.
springframework
.
cloud
.
netflix
.
zuul
.
metrics
;
import
java.util.HashMap
;
import
org.junit.Test
;
import
java.util.Map
;
import
org.junit.runner.RunWith
;
import
org.junit.Ignore
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.context.SpringBootTest
;
...
@@ -34,12 +32,12 @@ import com.netflix.zuul.exception.ZuulException;
...
@@ -34,12 +32,12 @@ import com.netflix.zuul.exception.ZuulException;
import
com.netflix.zuul.monitoring.CounterFactory
;
import
com.netflix.zuul.monitoring.CounterFactory
;
import
com.netflix.zuul.monitoring.TracerFactory
;
import
com.netflix.zuul.monitoring.TracerFactory
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
springframework
.
boot
.
test
.
context
.
SpringBootTest
.
WebEnvironment
.
RANDOM_PORT
;
import
static
org
.
springframework
.
boot
.
test
.
context
.
SpringBootTest
.
WebEnvironment
.
RANDOM_PORT
;
import
io.micrometer.core.instrument.MeterRegistry
;
import
io.micrometer.core.instrument.simple.SimpleMeterRegistry
;
@RunWith
(
SpringRunner
.
class
)
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
(
classes
=
{
@SpringBootTest
(
classes
=
{
ZuulMetricsApplicationTests
.
ZuulMetricsApplicationTestsConfiguration
.
class
,
ZuulMetricsApplicationTests
.
ZuulMetricsApplicationTestsConfiguration
.
class
,
...
@@ -47,12 +45,12 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
...
@@ -47,12 +45,12 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
@DirtiesContext
@DirtiesContext
public
class
ZuulMetricsApplicationTests
{
public
class
ZuulMetricsApplicationTests
{
private
static
final
Map
<
String
,
Long
>
counters
=
new
HashMap
<>();
@Autowired
@Autowired
CounterFactory
counterFactory
;
private
CounterFactory
counterFactory
;
@Autowired
private
TracerFactory
tracerFactory
;
@Autowired
@Autowired
TracerFactory
tracerFacto
ry
;
private
MeterRegistry
meterRegist
ry
;
@Test
@Test
public
void
shouldSetupDefaultCounterFactoryIfCounterServiceIsPresent
()
public
void
shouldSetupDefaultCounterFactoryIfCounterServiceIsPresent
()
...
@@ -66,18 +64,19 @@ public class ZuulMetricsApplicationTests {
...
@@ -66,18 +64,19 @@ public class ZuulMetricsApplicationTests {
}
}
@Test
@Test
@Ignore
//FIXME: 2.0.0
public
void
shouldIncrementCounters
()
throws
Exception
{
public
void
shouldIncrementCounters
()
throws
Exception
{
new
ZuulException
(
"any"
,
500
,
"cause"
);
new
ZuulException
(
"any"
,
500
,
"cause"
);
new
ZuulException
(
"any"
,
500
,
"cause"
);
new
ZuulException
(
"any"
,
500
,
"cause"
);
assertEquals
((
long
)
counters
.
get
(
"ZUUL::EXCEPTION:cause:500"
),
2L
);
Double
count
=
meterRegistry
.
counter
(
"ZUUL::EXCEPTION:cause:500"
).
count
();
assertEquals
(
count
.
longValue
(),
2L
);
new
ZuulException
(
"any"
,
404
,
"cause2"
);
new
ZuulException
(
"any"
,
404
,
"cause2"
);
new
ZuulException
(
"any"
,
404
,
"cause2"
);
new
ZuulException
(
"any"
,
404
,
"cause2"
);
new
ZuulException
(
"any"
,
404
,
"cause2"
);
new
ZuulException
(
"any"
,
404
,
"cause2"
);
assertEquals
((
long
)
counters
.
get
(
"ZUUL::EXCEPTION:cause2:404"
),
3L
);
count
=
meterRegistry
.
counter
(
"ZUUL::EXCEPTION:cause2:404"
).
count
();
assertEquals
(
count
.
longValue
(),
3L
);
}
}
// Don't use @SpringBootApplication because we don't want to component scan
// Don't use @SpringBootApplication because we don't want to component scan
...
@@ -91,28 +90,9 @@ public class ZuulMetricsApplicationTests {
...
@@ -91,28 +90,9 @@ public class ZuulMetricsApplicationTests {
@Configuration
@Configuration
static
class
ZuulMetricsApplicationTestsConfiguration
{
static
class
ZuulMetricsApplicationTestsConfiguration
{
//FIXME: 2.0.0
@Bean
/*@Bean
public
MeterRegistry
meterRegistry
()
{
public CounterService counterService() {
return
new
SimpleMeterRegistry
();
return new CounterService() {
}
// not thread safe, but we are ok with it in tests
@Override
public void increment(String metricName) {
Long counter = counters.get(metricName);
if (counter == null) {
counter = 0L;
}
counters.put(metricName, ++counter);
}
@Override
public void decrement(String metricName) {
}
@Override
public void reset(String metricName) {
}
};
}*/
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment