fix: resolve jolokia2 panic on null response (#11397)
This commit is contained in:
parent
b89a254ace
commit
eb77bddde2
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Reference in New Issue