Skip to content

Commit

Permalink
Filter allocator and framework_offers in filterMetrics()
Browse files Browse the repository at this point in the history
  • Loading branch information
branden committed Aug 8, 2019
1 parent effb993 commit 658414e
Show file tree
Hide file tree
Showing 2 changed files with 316 additions and 285 deletions.
67 changes: 38 additions & 29 deletions plugins/inputs/mesos/mesos.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,9 @@ func getMetrics(role Role, group string) []string {
"master/outstanding_offers",
}

// These groups are empty because filtering is done in gatherMainMetrics
// based on presence of "framework_offers"/"allocator" in MasterCols.
// These lines are included to prevent the "unknown" info log below.
// framework_offers and allocator metrics have unpredictable names, so they can't be listed here.
// These empty groups are included to prevent the "unknown metrics group" info log below.
// filterMetrics() filters these metrics by looking for names with the corresponding prefix.
m["framework_offers"] = []string{}
m["allocator"] = []string{}

Expand Down Expand Up @@ -497,17 +497,49 @@ func getMetrics(role Role, group string) []string {
func (m *Mesos) filterMetrics(role Role, metrics *map[string]interface{}) {
var ok bool
var selectedMetrics []string
var includeFrameworkOffers, includeAllocator bool

if role == MASTER {
selectedMetrics = m.MasterCols

// allocator and framework_offers metrics are only provided by masters.
for _, col := range m.MasterCols {
if col == "allocator" {
includeAllocator = true
} else if col == "framework_offers" {
includeFrameworkOffers = true
}
}
} else if role == SLAVE {
selectedMetrics = m.SlaveCols
}

for _, k := range metricsDiff(role, selectedMetrics) {
for _, v := range getMetrics(role, k) {
if _, ok = (*metrics)[v]; ok {
delete((*metrics), v)
switch k {
// allocator and framework_offers metrics have unpredictable names, so we have to identify them by name prefix.
case "allocator":
if !includeAllocator {
for m, _ := range *metrics {
if strings.HasPrefix(m, "allocator/") {
delete((*metrics), m)
}
}
}
case "framework_offers":
if !includeFrameworkOffers {
for m, _ := range *metrics {
if strings.HasPrefix(m, "master/frameworks/") || strings.HasPrefix(m, "frameworks/") {
delete((*metrics), m)
}
}
}

// All other metrics have predictable names. We can use getMetrics() to retrieve them.
default:
for _, v := range getMetrics(role, k) {
if _, ok = (*metrics)[v]; ok {
delete((*metrics), v)
}
}
}
}
Expand Down Expand Up @@ -621,29 +653,6 @@ func (m *Mesos) gatherMainMetrics(u *url.URL, role Role, acc telegraf.Accumulato
}
}

var includeFrameworkOffers, includeAllocator bool
for _, col := range m.MasterCols {
if col == "framework_offers" {
includeFrameworkOffers = true
} else if col == "allocator" {
includeAllocator = true
}
}

for metricName := range jf.Fields {
if !strings.HasPrefix(metricName, "master/frameworks/") && !strings.HasPrefix(metricName, "frameworks/") && !strings.HasPrefix(metricName, "allocator/") {
continue
}

// filter out framework offers/allocator metrics if necessary
if !includeFrameworkOffers &&
(strings.HasPrefix(metricName, "master/frameworks/") || strings.HasPrefix(metricName, "frameworks/")) ||
(!includeAllocator && strings.HasPrefix(metricName, "allocator/")) {
delete(jf.Fields, metricName)
continue
}
}

acc.AddFields("mesos", jf.Fields, tags)

return nil
Expand Down
Loading

0 comments on commit 658414e

Please sign in to comment.