From e4a19bbf36c1999bd97ac2972ef611a048db02a5 Mon Sep 17 00:00:00 2001
From: Leonardo Di Donato <leodidonato@gmail.com>
Date: Mon, 14 Jan 2019 16:06:17 +0100
Subject: [PATCH] fix(bolt): empty set rather than error when there aren't
 telegraf configs for an org

Fixes #11018
---
 bolt/telegraf.go | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/bolt/telegraf.go b/bolt/telegraf.go
index 0cb1947b50..146a96c14e 100644
--- a/bolt/telegraf.go
+++ b/bolt/telegraf.go
@@ -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