Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
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
DEMO
spring-boot
Commits
7be13b28
Commit
7be13b28
authored
May 11, 2015
by
Dave Syer
Committed by
Andy Wilkinson
May 13, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for new features
parent
270d5e32
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
155 additions
and
12 deletions
+155
-12
MetricExportProperties.java
...k/boot/actuate/metrics/export/MetricExportProperties.java
+5
-5
OpenTsdbMetricWriter.java
...k/boot/actuate/metrics/opentsdb/OpenTsdbMetricWriter.java
+6
-5
MetricExportersTests.java
...ork/boot/actuate/metrics/export/MetricExportersTests.java
+60
-0
OpenTsdbMetricWriterTests.java
...t/actuate/metrics/opentsdb/OpenTsdbMetricWriterTests.java
+82
-0
SampleOpenTsdbExportApplication.java
...ple/metrics/opentsdb/SampleOpenTsdbExportApplication.java
+2
-2
No files found.
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/MetricExportProperties.java
View file @
7be13b28
...
...
@@ -63,7 +63,7 @@ public class MetricExportProperties {
}
@PostConstruct
public
void
setDefaults
()
{
public
void
set
Up
Defaults
()
{
Export
defaults
=
null
;
for
(
Entry
<
String
,
Export
>
entry
:
this
.
writers
.
entrySet
())
{
String
key
=
entry
.
getKey
();
...
...
@@ -91,13 +91,13 @@ public class MetricExportProperties {
}
for
(
Export
value
:
this
.
writers
.
values
())
{
if
(
value
.
isIgnoreTimestamps
()
==
null
)
{
value
.
setIgnoreTimestamps
(
false
);
value
.
setIgnoreTimestamps
(
defaults
.
isIgnoreTimestamps
()
);
}
if
(
value
.
isSendLatest
()
==
null
)
{
value
.
setSendLatest
(
true
);
value
.
setSendLatest
(
defaults
.
isSendLatest
()
);
}
if
(
value
.
getDelayMillis
()
==
null
)
{
value
.
setDelayMillis
(
5000
);
value
.
setDelayMillis
(
defaults
.
getDelayMillis
()
);
}
}
}
...
...
@@ -210,6 +210,6 @@ public class MetricExportProperties {
return
value
;
}
}
return
null
;
return
this
.
export
;
}
}
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/opentsdb/OpenTsdb
Http
MetricWriter.java
→
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/opentsdb/OpenTsdbMetricWriter.java
View file @
7be13b28
...
...
@@ -31,6 +31,7 @@ import org.springframework.http.HttpHeaders;
import
org.springframework.http.MediaType
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.web.client.RestOperations
;
import
org.springframework.web.client.RestTemplate
;
/**
...
...
@@ -43,11 +44,11 @@ import org.springframework.web.client.RestTemplate;
*
* @author Dave Syer
*/
public
class
OpenTsdb
Http
MetricWriter
implements
MetricWriter
{
public
class
OpenTsdbMetricWriter
implements
MetricWriter
{
private
static
final
Log
logger
=
LogFactory
.
getLog
(
OpenTsdb
Http
MetricWriter
.
class
);
private
static
final
Log
logger
=
LogFactory
.
getLog
(
OpenTsdbMetricWriter
.
class
);
private
Rest
Template
restTemplate
=
new
RestTemplate
();
private
Rest
Operations
restTemplate
=
new
RestTemplate
();
/**
* URL for POSTing data. Defaults to http://localhost:4242/api/put.
...
...
@@ -69,11 +70,11 @@ public class OpenTsdbHttpMetricWriter implements MetricWriter {
private
OpenTsdbNamingStrategy
namingStrategy
=
new
DefaultOpenTsdbNamingStrategy
();
public
Rest
Template
getRestTemplate
()
{
public
Rest
Operations
getRestTemplate
()
{
return
this
.
restTemplate
;
}
public
void
setRestTemplate
(
Rest
Template
restTemplate
)
{
public
void
setRestTemplate
(
Rest
Operations
restTemplate
)
{
this
.
restTemplate
=
restTemplate
;
}
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/export/MetricExportersTests.java
0 → 100644
View file @
7be13b28
/*
* Copyright 2012-2015 the original author or authors.
*
* Licensed 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
org
.
springframework
.
boot
.
actuate
.
metrics
.
export
;
import
java.util.LinkedHashMap
;
import
java.util.Map
;
import
org.junit.Test
;
import
org.mockito.Mockito
;
import
org.springframework.boot.actuate.metrics.reader.MetricReader
;
import
org.springframework.boot.actuate.metrics.writer.MetricWriter
;
import
org.springframework.scheduling.config.ScheduledTaskRegistrar
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
/**
* @author Dave Syer
*/
public
class
MetricExportersTests
{
private
MetricExporters
exporters
;
private
MetricExportProperties
export
=
new
MetricExportProperties
();
private
Map
<
String
,
MetricWriter
>
writers
=
new
LinkedHashMap
<
String
,
MetricWriter
>();
private
MetricReader
reader
=
Mockito
.
mock
(
MetricReader
.
class
);
private
MetricWriter
writer
=
Mockito
.
mock
(
MetricWriter
.
class
);
@Test
public
void
emptyWriters
()
{
this
.
exporters
=
new
MetricExporters
(
this
.
reader
,
this
.
writers
,
this
.
export
);
this
.
exporters
.
configureTasks
(
new
ScheduledTaskRegistrar
());
assertNotNull
(
this
.
exporters
.
getExporters
());
assertEquals
(
0
,
this
.
exporters
.
getExporters
().
size
());
}
@Test
public
void
oneWriter
()
{
this
.
export
.
setUpDefaults
();
this
.
writers
.
put
(
"foo"
,
this
.
writer
);
this
.
exporters
=
new
MetricExporters
(
this
.
reader
,
this
.
writers
,
this
.
export
);
this
.
exporters
.
configureTasks
(
new
ScheduledTaskRegistrar
());
assertNotNull
(
this
.
exporters
.
getExporters
());
assertEquals
(
1
,
this
.
exporters
.
getExporters
().
size
());
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/opentsdb/OpenTsdbMetricWriterTests.java
0 → 100644
View file @
7be13b28
/*
* Copyright 2012-2015 the original author or authors.
*
* Licensed 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
org
.
springframework
.
boot
.
actuate
.
metrics
.
opentsdb
;
import
java.util.Collections
;
import
java.util.Map
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.mockito.Matchers
;
import
org.mockito.Mockito
;
import
org.springframework.boot.actuate.metrics.Metric
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.client.RestOperations
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Mockito
.
verify
;
/**
* @author Dave Syer
*/
public
class
OpenTsdbMetricWriterTests
{
private
OpenTsdbMetricWriter
writer
;
private
RestOperations
restTemplate
=
Mockito
.
mock
(
RestOperations
.
class
);
@Before
public
void
init
()
{
this
.
writer
=
new
OpenTsdbMetricWriter
();
this
.
writer
.
setRestTemplate
(
this
.
restTemplate
);
}
@Test
public
void
postSuccessfullyOnFlush
()
{
this
.
writer
.
set
(
new
Metric
<
Double
>(
"foo"
,
2.4
));
given
(
this
.
restTemplate
.
postForEntity
(
Matchers
.
anyString
(),
Matchers
.
any
(
Object
.
class
),
anyMap
()))
.
willReturn
(
emptyResponse
());
this
.
writer
.
flush
();
verify
(
this
.
restTemplate
).
postForEntity
(
Matchers
.
anyString
(),
Matchers
.
any
(
Object
.
class
),
anyMap
());
}
@Test
public
void
flushAutomaticlly
()
{
given
(
this
.
restTemplate
.
postForEntity
(
Matchers
.
anyString
(),
Matchers
.
any
(
Object
.
class
),
anyMap
()))
.
willReturn
(
emptyResponse
());
this
.
writer
.
setBufferSize
(
0
);
this
.
writer
.
set
(
new
Metric
<
Double
>(
"foo"
,
2.4
));
verify
(
this
.
restTemplate
).
postForEntity
(
Matchers
.
anyString
(),
Matchers
.
any
(
Object
.
class
),
anyMap
());
}
@SuppressWarnings
(
"rawtypes"
)
private
ResponseEntity
<
Map
>
emptyResponse
()
{
return
new
ResponseEntity
<
Map
>(
Collections
.
emptyMap
(),
HttpStatus
.
OK
);
}
@SuppressWarnings
({
"rawtypes"
,
"unchecked"
})
private
Class
<
Map
>
anyMap
()
{
return
Matchers
.
any
(
Class
.
class
);
}
}
spring-boot-samples/spring-boot-sample-metrics-opentsdb/src/main/java/sample/metrics/opentsdb/SampleOpenTsdbExportApplication.java
View file @
7be13b28
...
...
@@ -18,7 +18,7 @@ package sample.metrics.opentsdb;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.actuate.metrics.opentsdb.DefaultOpenTsdbNamingStrategy
;
import
org.springframework.boot.actuate.metrics.opentsdb.OpenTsdb
Http
MetricWriter
;
import
org.springframework.boot.actuate.metrics.opentsdb.OpenTsdbMetricWriter
;
import
org.springframework.boot.actuate.metrics.opentsdb.OpenTsdbNamingStrategy
;
import
org.springframework.boot.actuate.metrics.writer.MetricWriter
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
...
...
@@ -35,7 +35,7 @@ public class SampleOpenTsdbExportApplication {
@Bean
@ConfigurationProperties
(
"metrics.export"
)
public
MetricWriter
openTsdbMetricWriter
()
{
OpenTsdb
HttpMetricWriter
writer
=
new
OpenTsdbHttp
MetricWriter
();
OpenTsdb
MetricWriter
writer
=
new
OpenTsdb
MetricWriter
();
writer
.
setNamingStrategy
(
namingStrategy
());
return
writer
;
}
...
...
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