Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove jolokia2 panic info #11397

Merged
merged 1 commit into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion plugins/inputs/jolokia2/common/gatherer.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,13 @@ func (g *Gatherer) generatePoints(metric Metric, responses []ReadResponse) ([]po
}

pb := NewPointBuilder(metric, response.RequestAttributes, response.RequestPath)
for _, point := range pb.Build(metric.Mbean, response.Value) {
ps, err := pb.Build(metric.Mbean, response.Value)
if err != nil {
errors = append(errors, err)
continue
}

for _, point := range ps {
if response.RequestTarget != "" {
point.Tags["jolokia_agent_url"] = response.RequestTarget
}
Expand Down
10 changes: 5 additions & 5 deletions plugins/inputs/jolokia2/common/point_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ func NewPointBuilder(metric Metric, attributes []string, path string) *pointBuil
}

// Build generates a point for a given mbean name/pattern and value object.
func (pb *pointBuilder) Build(mbean string, value interface{}) []point {
func (pb *pointBuilder) Build(mbean string, value interface{}) ([]point, error) {
hasPattern := strings.Contains(mbean, "*")
if !hasPattern {
if !hasPattern || value == nil {
value = map[string]interface{}{mbean: value}
}

valueMap, ok := value.(map[string]interface{})
if !ok { // FIXME: log it and move on.
panic(fmt.Sprintf("There should be a map here for %s!\n", mbean))
if !ok {
return nil, fmt.Errorf("the response of %s's value should be a map", mbean)
}

points := make([]point, 0)
Expand All @@ -46,7 +46,7 @@ func (pb *pointBuilder) Build(mbean string, value interface{}) []point {
})
}

return compactPoints(points)
return compactPoints(points), nil
}

// extractTags generates the map of tags for a given mbean name/pattern.
Expand Down