Add missing return to ingestKubequeryInfo (#8178)

* Add missing return to ingestKubequeryInfo

* No need to log error twice
This commit is contained in:
Lucas Manuel Rodriguez 2022-10-12 09:00:49 -03:00 committed by GitHub
parent 8de3e9f258
commit 42c47a6fa7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 2 deletions

View File

@ -0,0 +1 @@
- Fixed panic in `ingestKubequeryInfo` query ingestion.

View File

@ -1201,8 +1201,7 @@ func directIngestMunkiInfo(ctx context.Context, logger log.Logger, host *fleet.H
func ingestKubequeryInfo(ctx context.Context, logger log.Logger, host *fleet.Host, rows []map[string]string) error {
if len(rows) != 1 {
logger.Log("component", "service", "method", "ingestKubequeryInfo", "warn",
fmt.Sprintf("kubernetes_info expected single result got %d", len(rows)))
return fmt.Errorf("kubernetes_info expected single result got: %d", len(rows))
}
host.Hostname = fmt.Sprintf("kubequery %s", rows[0]["cluster_name"])

View File

@ -813,3 +813,16 @@ func TestDirectIngestWindowsUpdateHistory(t *testing.T) {
require.NoError(t, err)
require.True(t, ds.InsertWindowsUpdatesFuncInvoked)
}
func TestIngestKubequeryInfo(t *testing.T) {
err := ingestKubequeryInfo(context.Background(), log.NewNopLogger(), &fleet.Host{}, nil)
require.Error(t, err)
err = ingestKubequeryInfo(context.Background(), log.NewNopLogger(), &fleet.Host{}, []map[string]string{})
require.Error(t, err)
err = ingestKubequeryInfo(context.Background(), log.NewNopLogger(), &fleet.Host{}, []map[string]string{
{
"cluster_name": "foo",
},
})
require.NoError(t, err)
}