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
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
49 additions
and
57 deletions
+49
-57
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
+16
-36
No files found.
spring-cloud-netflix-core/pom.xml
View file @
c544f4ae
...
...
@@ -187,6 +187,11 @@
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
io.micrometer
</groupId>
<artifactId>
micrometer-core
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<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;
import
com.netflix.zuul.monitoring.CounterFactory
;
import
com.netflix.zuul.monitoring.TracerFactory
;
import
io.micrometer.core.instrument.MeterRegistry
;
/**
* @author Spencer Gibb
* @author Dave Syer
...
...
@@ -197,14 +199,13 @@ public class ZuulServerAutoConfiguration {
}
@Configuration
//FIXME: 2.0.0
// @ConditionalOnClass(CounterService.class)
@ConditionalOnClass
(
MeterRegistry
.
class
)
protected
static
class
ZuulCounterFactoryConfiguration
{
@Bean
// @ConditionalOnBean(CounterService
.class)
public
CounterFactory
counterFactory
(
/*CounterService counterService*/
)
{
return
new
DefaultCounterFactory
(
/*counterService*/
);
@ConditionalOnBean
(
MeterRegistry
.
class
)
public
CounterFactory
counterFactory
(
MeterRegistry
meterRegistry
)
{
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;
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
*/
public
class
DefaultCounterFactory
extends
CounterFactory
{
//FIXME: 2.0.0
// private final CounterService counterService;
private
final
MeterRegistry
meterRegistry
;
public
DefaultCounterFactory
(
/*CounterService counterService*/
)
{
/*this.counterService = counterService;*/
public
DefaultCounterFactory
(
MeterRegistry
meterRegistry
)
{
this
.
meterRegistry
=
meterRegistry
;
}
@Override
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;
import
com.netflix.zuul.monitoring.CounterFactory
;
import
io.micrometer.core.instrument.Counter
;
import
io.micrometer.core.instrument.MeterRegistry
;
import
org.junit.Test
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
public
class
DefaultCounterFactoryTests
{
private
static
final
String
NAME
=
"my-super-metric-name"
;
// private final CounterService counterService = mock(CounterService.class);
private
final
CounterFactory
factory
=
new
DefaultCounterFactory
(
/*counterService*/
);
@Test
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
);
//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 @@
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.cloud.test.ClassPathExclusions
;
import
org.springframework.cloud.netflix.zuul.ZuulServerAutoConfiguration
;
import
org.springframework.cloud.netflix.zuul.ZuulServerMarkerConfiguration
;
import
org.springframework.cloud.test.ClassPathExclusions
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.context.annotation.Bean
;
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.TracerFactory
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
@ClassPathExclusions
({
"spring-boot-starter-actuator-*.jar"
,
...
...
@@ -59,7 +57,6 @@ public class ZuulEmptyMetricsApplicationTests {
}
@Test
@Ignore
//FIXME: 2.0.0
public
void
shouldSetupDefaultCounterFactoryIfCounterServiceIsPresent
()
throws
Exception
{
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 @@
package
org
.
springframework
.
cloud
.
netflix
.
zuul
.
metrics
;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.junit.Ignore
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.test.context.SpringBootTest
;
...
...
@@ -34,12 +32,12 @@ import com.netflix.zuul.exception.ZuulException;
import
com.netflix.zuul.monitoring.CounterFactory
;
import
com.netflix.zuul.monitoring.TracerFactory
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
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
)
@SpringBootTest
(
classes
=
{
ZuulMetricsApplicationTests
.
ZuulMetricsApplicationTestsConfiguration
.
class
,
...
...
@@ -47,12 +45,12 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
@DirtiesContext
public
class
ZuulMetricsApplicationTests
{
private
static
final
Map
<
String
,
Long
>
counters
=
new
HashMap
<>();
@Autowired
CounterFactory
counterFactory
;
private
CounterFactory
counterFactory
;
@Autowired
private
TracerFactory
tracerFactory
;
@Autowired
TracerFactory
tracerFacto
ry
;
private
MeterRegistry
meterRegist
ry
;
@Test
public
void
shouldSetupDefaultCounterFactoryIfCounterServiceIsPresent
()
...
...
@@ -66,18 +64,19 @@ public class ZuulMetricsApplicationTests {
}
@Test
@Ignore
//FIXME: 2.0.0
public
void
shouldIncrementCounters
()
throws
Exception
{
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"
);
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
...
...
@@ -91,28 +90,9 @@ public class ZuulMetricsApplicationTests {
@Configuration
static
class
ZuulMetricsApplicationTestsConfiguration
{
//FIXME: 2.0.0
/*@Bean
public CounterService counterService() {
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) {
@Bean
public
MeterRegistry
meterRegistry
()
{
return
new
SimpleMeterRegistry
();
}
};
}*/
}
}
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