fix(bolt): empty set rather than error when there aren't telegraf configs for an org
Fixes #11018pull/10948/head
parent
1e42e0259e
commit
e4a19bbf36
|
@ -3,7 +3,6 @@ package bolt
|
|||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
bolt "github.com/coreos/bbolt"
|
||||
platform "github.com/influxdata/influxdb"
|
||||
|
@ -49,7 +48,7 @@ func (c *Client) findTelegrafConfigByID(ctx context.Context, tx *bolt.Tx, id pla
|
|||
if d == nil {
|
||||
return nil, &platform.Error{
|
||||
Code: platform.ENotFound,
|
||||
Msg: fmt.Sprintf("telegraf config with ID %v not found", id),
|
||||
Msg: platform.ErrTelegrafConfigNotFound,
|
||||
}
|
||||
}
|
||||
tc := new(platform.TelegrafConfig)
|
||||
|
@ -91,21 +90,18 @@ func (c *Client) findTelegrafConfigs(ctx context.Context, tx *bolt.Tx, filter pl
|
|||
}
|
||||
for _, item := range m {
|
||||
tc, err := c.findTelegrafConfigByID(ctx, tx, item.ResourceID)
|
||||
if err != nil {
|
||||
if err != nil && platform.ErrorCode(err) != platform.ENotFound {
|
||||
return nil, 0, &platform.Error{
|
||||
// return internal error, for any mapping issue
|
||||
Err: err,
|
||||
}
|
||||
}
|
||||
// Restrict results by organization ID, if it has been provided
|
||||
if filter.OrganizationID != nil && filter.OrganizationID.Valid() && tc.OrganizationID != *filter.OrganizationID {
|
||||
continue
|
||||
}
|
||||
tcs = append(tcs, tc)
|
||||
}
|
||||
if len(tcs) == 0 {
|
||||
return nil, 0, &platform.Error{
|
||||
Msg: "inconsistent user resource mapping and telegraf config",
|
||||
if tc != nil {
|
||||
// Restrict results by organization ID, if it has been provided
|
||||
if filter.OrganizationID != nil && filter.OrganizationID.Valid() && tc.OrganizationID != *filter.OrganizationID {
|
||||
continue
|
||||
}
|
||||
tcs = append(tcs, tc)
|
||||
}
|
||||
}
|
||||
return tcs, len(tcs), nil
|
||||
|
|
Loading…
Reference in New Issue