lint: mark false positive or fix gocritic append lint errors.

This commit is contained in:
James Rasell 2021-09-06 10:49:44 +02:00
parent 994bd11a2e
commit d4a333e9b5
No known key found for this signature in database
GPG Key ID: AA7D460F5C8377AA
6 changed files with 20 additions and 9 deletions

View File

@ -174,7 +174,10 @@ func expandNamespacePolicy(policy string) []string {
NamespaceCapabilityReadScalingPolicy,
}
write := append(read, []string{
write := make([]string, len(read))
copy(write, read)
write = append(write, []string{
NamespaceCapabilityScaleJob,
NamespaceCapabilitySubmitJob,
NamespaceCapabilityDispatchJob,

View File

@ -2833,8 +2833,12 @@ func (c *Client) setGaugeForMemoryStats(nodeID string, hStats *stats.HostStats,
// setGaugeForCPUStats proxies metrics for CPU specific statistics
func (c *Client) setGaugeForCPUStats(nodeID string, hStats *stats.HostStats, baseLabels []metrics.Label) {
labels := make([]metrics.Label, len(baseLabels))
copy(labels, baseLabels)
for _, cpu := range hStats.CPU {
labels := append(baseLabels, metrics.Label{
labels := append(labels, metrics.Label{
Name: "cpu",
Value: cpu.CPU,
})
@ -2848,8 +2852,12 @@ func (c *Client) setGaugeForCPUStats(nodeID string, hStats *stats.HostStats, bas
// setGaugeForDiskStats proxies metrics for disk specific statistics
func (c *Client) setGaugeForDiskStats(nodeID string, hStats *stats.HostStats, baseLabels []metrics.Label) {
labels := make([]metrics.Label, len(baseLabels))
copy(labels, baseLabels)
for _, disk := range hStats.DiskStats {
labels := append(baseLabels, metrics.Label{
labels := append(labels, metrics.Label{
Name: "disk",
Value: disk.Device,
})
@ -2877,7 +2885,7 @@ func (c *Client) setGaugeForAllocationStats(nodeID string, baseLabels []metrics.
metrics.SetGaugeWithLabels([]string{"client", "allocated", "cpu"}, float32(allocated.Flattened.Cpu.CpuShares), baseLabels)
for _, n := range allocated.Flattened.Networks {
labels := append(baseLabels, metrics.Label{
labels := append(baseLabels, metrics.Label{ //nolint:gocritic
Name: "device",
Value: n.Device,
})
@ -2903,7 +2911,7 @@ func (c *Client) setGaugeForAllocationStats(nodeID string, baseLabels []metrics.
}
unallocatedMbits := n.MBits - usedMbits
labels := append(baseLabels, metrics.Label{
labels := append(baseLabels, metrics.Label{ //nolint:gocritic
Name: "device",
Value: n.Device,
})

View File

@ -258,7 +258,7 @@ func (m *manager) waitForFirstFingerprint(ctx context.Context, cancel context.Ca
mu.Lock()
defer mu.Unlock()
updated := append(driversByStatus[lastHeath], name)
updated := append(driversByStatus[lastHeath], name) //nolint:gocritic
driversByStatus[lastHeath] = updated
}

View File

@ -556,7 +556,7 @@ func (c *AllocStatusCommand) outputTaskResources(alloc *api.Allocation, task str
c.Ui.Output("Task Resources")
var addr []string
for _, nw := range resource.Networks {
ports := append(nw.DynamicPorts, nw.ReservedPorts...)
ports := append(nw.DynamicPorts, nw.ReservedPorts...) //nolint:gocritic
for _, port := range ports {
addr = append(addr, fmt.Sprintf("%v: %v:%v\n", port.Label, nw.IP, port.Value))
}

View File

@ -131,7 +131,7 @@ func (w *NoXSSResponseWriter) Write(p []byte) (int, error) {
}
// >= 512 bytes available, set the Content-Type and flush.
all := append(w.buf, p...)
all := append(w.buf, p...) //nolint:gocritic
contentType := http.DetectContentType(all)
// Prefix match to exclude the character set which may be user

View File

@ -238,7 +238,7 @@ func diffSystemAllocs(
// Build a mapping of nodes to all their allocs.
nodeAllocs := make(map[string][]*structs.Allocation, len(allocs))
for _, alloc := range allocs {
nallocs := append(nodeAllocs[alloc.NodeID], alloc)
nallocs := append(nodeAllocs[alloc.NodeID], alloc) //nolint:gocritic
nodeAllocs[alloc.NodeID] = nallocs
}