Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
telegraf-nftables
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Due to inactivity, this project is scheduled to be deleted on 2035-04-24.
Why is this scheduled?
Show more breadcrumbs
vqgroup
telegraf-nftables
Commits
babecb6d
Commit
babecb6d
authored
9 years ago
by
Sergio Jimenez
Browse files
Options
Downloads
Patches
Plain Diff
feat(timeout): Use timeout setting
* Use timeout as parameter in the http request * A bit of cleanup * More tests
parent
97708029
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
plugins/inputs/mesos/mesos.go
+14
-9
14 additions, 9 deletions
plugins/inputs/mesos/mesos.go
plugins/inputs/mesos/mesos_test.go
+40
-3
40 additions, 3 deletions
plugins/inputs/mesos/mesos_test.go
with
54 additions
and
12 deletions
plugins/inputs/mesos/mesos.go
+
14
−
9
View file @
babecb6d
...
@@ -7,6 +7,7 @@ import (
...
@@ -7,6 +7,7 @@ import (
"log"
"log"
"net"
"net"
"net/http"
"net/http"
"strconv"
"strings"
"strings"
"sync"
"sync"
...
@@ -16,7 +17,7 @@ import (
...
@@ -16,7 +17,7 @@ import (
)
)
type
Mesos
struct
{
type
Mesos
struct
{
Timeout
str
in
g
Timeout
in
t
Servers
[]
string
Servers
[]
string
MetricsCol
[]
string
`toml:"metrics_collection"`
MetricsCol
[]
string
`toml:"metrics_collection"`
}
}
...
@@ -225,7 +226,7 @@ func masterBlocks(g string) []string {
...
@@ -225,7 +226,7 @@ func masterBlocks(g string) []string {
ret
,
ok
:=
m
[
g
]
ret
,
ok
:=
m
[
g
]
if
!
ok
{
if
!
ok
{
log
.
Println
(
"Unkown metrics group: "
,
g
)
log
.
Println
(
"
[mesos]
Unkown metrics group: "
,
g
)
return
[]
string
{}
return
[]
string
{}
}
}
...
@@ -234,7 +235,7 @@ func masterBlocks(g string) []string {
...
@@ -234,7 +235,7 @@ func masterBlocks(g string) []string {
var
sampleConfig
=
`
var
sampleConfig
=
`
# Timeout, in ms.
# Timeout, in ms.
timeout =
20
00
timeout =
1
00
# A list of Mesos masters. e.g. master1:5050, master2:5080, etc.
# A list of Mesos masters. e.g. master1:5050, master2:5080, etc.
# The port can be skipped if using the default (5050)
# The port can be skipped if using the default (5050)
# Default value is localhost:5050.
# Default value is localhost:5050.
...
@@ -244,7 +245,7 @@ var sampleConfig = `
...
@@ -244,7 +245,7 @@ var sampleConfig = `
metrics_collection = ["resources","master","system","slaves","frameworks","messages","evqueue","registrar"]
metrics_collection = ["resources","master","system","slaves","frameworks","messages","evqueue","registrar"]
`
`
// removeGroup(), remove
blacklis
ted groups
// removeGroup(), remove
unwan
ted groups
func
(
m
*
Mesos
)
removeGroup
(
j
*
map
[
string
]
interface
{})
{
func
(
m
*
Mesos
)
removeGroup
(
j
*
map
[
string
]
interface
{})
{
var
ok
bool
var
ok
bool
...
@@ -273,8 +274,14 @@ func (m *Mesos) gatherMetrics(a string, acc telegraf.Accumulator) error {
...
@@ -273,8 +274,14 @@ func (m *Mesos) gatherMetrics(a string, acc telegraf.Accumulator) error {
"server"
:
host
,
"server"
:
host
,
}
}
// TODO: Use Timeout
if
m
.
Timeout
==
0
{
resp
,
err
:=
http
.
Get
(
"http://"
+
a
+
"/metrics/snapshot"
)
log
.
Println
(
"[mesos] Missing timeout value, setting default value (100ms)"
)
m
.
Timeout
=
100
}
ts
:=
strconv
.
Itoa
(
m
.
Timeout
)
+
"ms"
resp
,
err
:=
http
.
Get
(
"http://"
+
a
+
"/metrics/snapshot?timeout="
+
ts
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
@@ -290,9 +297,7 @@ func (m *Mesos) gatherMetrics(a string, acc telegraf.Accumulator) error {
...
@@ -290,9 +297,7 @@ func (m *Mesos) gatherMetrics(a string, acc telegraf.Accumulator) error {
return
errors
.
New
(
"Error decoding JSON response"
)
return
errors
.
New
(
"Error decoding JSON response"
)
}
}
//if len(m.Blacklist) > 0 {
m
.
removeGroup
(
&
jsonOut
)
// m.removeGroup(&jsonOut)
//}
jf
:=
internal
.
JSONFlattener
{}
jf
:=
internal
.
JSONFlattener
{}
...
...
This diff is collapsed.
Click to expand it.
plugins/inputs/mesos/mesos_test.go
+
40
−
3
View file @
babecb6d
...
@@ -6,6 +6,7 @@ import (
...
@@ -6,6 +6,7 @@ import (
"net/http"
"net/http"
"net/http/httptest"
"net/http/httptest"
"os"
"os"
"reflect"
"testing"
"testing"
"github.com/influxdata/telegraf/testutil"
"github.com/influxdata/telegraf/testutil"
...
@@ -86,9 +87,6 @@ func TestMesosMaster(t *testing.T) {
...
@@ -86,9 +87,6 @@ func TestMesosMaster(t *testing.T) {
}
}
func
TestRemoveGroup
(
t
*
testing
.
T
)
{
func
TestRemoveGroup
(
t
*
testing
.
T
)
{
//t.Skip("needs refactoring")
// FIXME: removeGroup() behavior is the opposite as it was,
// this test has to be refactored
generateMetrics
()
generateMetrics
()
m
:=
Mesos
{
m
:=
Mesos
{
...
@@ -111,3 +109,42 @@ func TestRemoveGroup(t *testing.T) {
...
@@ -111,3 +109,42 @@ func TestRemoveGroup(t *testing.T) {
}
}
}
}
}
}
func
TestMasterBlocks
(
t
*
testing
.
T
)
{
a
:=
"wrong_key"
expect
:=
[]
string
{}
got
:=
masterBlocks
(
a
)
if
!
reflect
.
DeepEqual
(
got
,
expect
)
{
t
.
Errorf
(
"Expected empty string slice, got: %v"
,
got
)
}
}
func
TestSampleConfig
(
t
*
testing
.
T
)
{
expect
:=
`
# Timeout, in ms.
timeout = 100
# A list of Mesos masters. e.g. master1:5050, master2:5080, etc.
# The port can be skipped if using the default (5050)
# Default value is localhost:5050.
servers = ["localhost:5050"]
# Metrics groups to be collected.
# Default, all enabled.
metrics_collection = ["resources","master","system","slaves","frameworks","messages","evqueue","registrar"]
`
got
:=
new
(
Mesos
)
.
SampleConfig
()
if
expect
!=
got
{
t
.
Errorf
(
"Got %s"
,
got
)
}
}
func
TestDescription
(
t
*
testing
.
T
)
{
expect
:=
"Telegraf plugin for gathering metrics from N Mesos masters"
got
:=
new
(
Mesos
)
.
Description
()
if
expect
!=
got
{
t
.
Errorf
(
"Got %s"
,
got
)
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment