mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 17:05:18 +00:00
Fix bugs in error handling for creation of live queries (#2181)
- Return the correct result type in error cases - Handle nil values for campaign when logging
This commit is contained in:
parent
a83a26b279
commit
ef1d69c371
@ -39,9 +39,9 @@ func makeCreateDistributedQueryCampaignEndpoint(svc kolide.Service) endpoint.End
|
||||
req := request.(createDistributedQueryCampaignRequest)
|
||||
campaign, err := svc.NewDistributedQueryCampaign(ctx, req.Query, req.Selected.Hosts, req.Selected.Labels)
|
||||
if err != nil {
|
||||
return createQueryResponse{Err: err}, nil
|
||||
return createDistributedQueryCampaignResponse{Err: err}, nil
|
||||
}
|
||||
return createDistributedQueryCampaignResponse{campaign, nil}, nil
|
||||
return createDistributedQueryCampaignResponse{Campaign: campaign}, nil
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,9 +64,9 @@ func makeCreateDistributedQueryCampaignByNamesEndpoint(svc kolide.Service) endpo
|
||||
req := request.(createDistributedQueryCampaignByNamesRequest)
|
||||
campaign, err := svc.NewDistributedQueryCampaignByNames(ctx, req.Query, req.Selected.Hosts, req.Selected.Labels)
|
||||
if err != nil {
|
||||
return createQueryResponse{Err: err}, nil
|
||||
return createDistributedQueryCampaignResponse{Err: err}, nil
|
||||
}
|
||||
return createDistributedQueryCampaignResponse{campaign, nil}, nil
|
||||
return createDistributedQueryCampaignResponse{Campaign: campaign}, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,12 +20,16 @@ func (mw loggingMiddleware) NewDistributedQueryCampaign(ctx context.Context, que
|
||||
loggedInUser = vc.Username()
|
||||
}
|
||||
defer func(begin time.Time) {
|
||||
var numHosts uint = 0
|
||||
if campaign != nil {
|
||||
numHosts = campaign.Metrics.TotalHosts
|
||||
}
|
||||
_ = mw.logger.Log(
|
||||
"method", "NewDistributedQueryCampaign",
|
||||
"err", err,
|
||||
"user", loggedInUser,
|
||||
"sql", queryString,
|
||||
"numHosts", campaign.Metrics.TotalHosts,
|
||||
"numHosts", numHosts,
|
||||
"took", time.Since(begin),
|
||||
)
|
||||
}(time.Now())
|
||||
@ -44,11 +48,15 @@ func (mw loggingMiddleware) NewDistributedQueryCampaignByNames(ctx context.Conte
|
||||
loggedInUser = vc.Username()
|
||||
}
|
||||
defer func(begin time.Time) {
|
||||
var numHosts uint = 0
|
||||
if campaign != nil {
|
||||
numHosts = campaign.Metrics.TotalHosts
|
||||
}
|
||||
_ = mw.logger.Log(
|
||||
"method", "NewDistributedQueryCampaignByNames",
|
||||
"err", err,
|
||||
"user", loggedInUser,
|
||||
"numHosts", campaign.Metrics.TotalHosts,
|
||||
"numHosts", numHosts,
|
||||
"took", time.Since(begin),
|
||||
)
|
||||
}(time.Now())
|
||||
|
Loading…
Reference in New Issue
Block a user