Skip to content

Commit

Permalink
fix(bigpanda): fields of alerting data point should be serialized as …
Browse files Browse the repository at this point in the history
…a string (#2596)

* fix(bigpanda): fields of alerting data point should be serialized as a string

* docs: update CHANGELOG.md
  • Loading branch information
bednar authored Jul 20, 2021
1 parent 3b27448 commit 2bd467c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

### Bugfixes
- [#2585](https://github.com/influxdata/kapacitor/pull/2585):Make DeleteGroupMessage align with GroupInfoer interface, thanks @prashanthjbabu!
- [#2592](https://github.com/influxdata/kapacitor/pull/2592): Fix: payload serialization for BigPanda
- [#2596](https://github.com/influxdata/kapacitor/pull/2596): Fix: payload serialization for BigPanda

## v1.6.0 [2021-06-28]

Expand Down
11 changes: 10 additions & 1 deletion services/bigpanda/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,16 @@ func (s *Service) preparePost(id string, message string, details string, level a
}

for k, v := range data.Fields {
bpData[k] = v
switch value := v.(type) {
case string:
bpData[k] = value
default:
b, err := json.Marshal(value)
if err != nil {
return nil, err
}
bpData[k] = string(b)
}
}

var post bytes.Buffer
Expand Down
16 changes: 14 additions & 2 deletions services/bigpanda/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,27 @@ func TestService_SerializeEventData(t *testing.T) {
}{
{
fields: map[string]interface{}{"primitive_type": 10},
expBody: "{\"app_key\":\"key\",\"check\":\"id\",\"description\":\"message\",\"details\":\"details\",\"primitive_type\":10,\"status\":\"ok\",\"task\":\":test\",\"timestamp\":31536038}\n",
expBody: "{\"app_key\":\"key\",\"check\":\"id\",\"description\":\"message\",\"details\":\"details\",\"primitive_type\":\"10\",\"status\":\"ok\",\"task\":\":test\",\"timestamp\":31536038}\n",
},
{
fields: map[string]interface{}{"primitive_type": "string"},
expBody: "{\"app_key\":\"key\",\"check\":\"id\",\"description\":\"message\",\"details\":\"details\",\"primitive_type\":\"string\",\"status\":\"ok\",\"task\":\":test\",\"timestamp\":31536038}\n",
},
{
fields: map[string]interface{}{"primitive_type": true},
expBody: "{\"app_key\":\"key\",\"check\":\"id\",\"description\":\"message\",\"details\":\"details\",\"primitive_type\":\"true\",\"status\":\"ok\",\"task\":\":test\",\"timestamp\":31536038}\n",
},
{
fields: map[string]interface{}{"primitive_type": 123.45},
expBody: "{\"app_key\":\"key\",\"check\":\"id\",\"description\":\"message\",\"details\":\"details\",\"primitive_type\":\"123.45\",\"status\":\"ok\",\"task\":\":test\",\"timestamp\":31536038}\n",
},
{
fields: map[string]interface{}{"escape": "\n"},
expBody: "{\"app_key\":\"key\",\"check\":\"id\",\"description\":\"message\",\"details\":\"details\",\"escape\":\"\\n\",\"status\":\"ok\",\"task\":\":test\",\"timestamp\":31536038}\n",
},
{
fields: map[string]interface{}{"array": []interface{}{10, true, "string value"}},
expBody: "{\"app_key\":\"key\",\"array\":[10,true,\"string value\"],\"check\":\"id\",\"description\":\"message\",\"details\":\"details\",\"status\":\"ok\",\"task\":\":test\",\"timestamp\":31536038}\n",
expBody: "{\"app_key\":\"key\",\"array\":\"[10,true,\\\"string value\\\"]\",\"check\":\"id\",\"description\":\"message\",\"details\":\"details\",\"status\":\"ok\",\"task\":\":test\",\"timestamp\":31536038}\n",
},
}

Expand Down

0 comments on commit 2bd467c

Please sign in to comment.