github-vet / github-vet/rangeloop-pointer-findings

vesoft-inc/nebula-stats-exporter: exporter/exporter.go; 47 LoC

Open
#13,306 0 comments 0 reactions 0 assignees View on GitHub
fresh small
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
PR metrics pending

Description

Found a possible issue in [vesoft-inc/nebula-stats-exporter](https://www.github.com/vesoft-inc/nebula-stats-exporter) at [exporter/exporter.go](https://github.com/vesoft-inc/nebula-stats-exporter/blob/f08f7874c23f56961439085e785a302c7562fd7b/exporter/exporter.go#L461-L507)

Below is the message reported by the analyzer for this snippet of code. Beware that the analyzer only reports the first issue it finds, so please do not limit your consideration to the contents of the below message.

> range-loop variable pod used in defer or goroutine at line 485

[Click here to see the code in its original context.](https://github.com/vesoft-inc/nebula-stats-exporter/blob/f08f7874c23f56961439085e785a302c7562fd7b/exporter/exporter.go#L461-L507)

Click here to show the 47 line(s) of Go which triggered the analyzer.

```go
for _, pod := range podLists.Items {
podIpAddress := pod.Status.PodIP
podHttpPort := int32(0)
for _, port := range pod.Spec.Containers[0].Ports {
if port.Name == "http" {
podHttpPort = port.ContainerPort
}
}

if podHttpPort == 0 {
continue
}

nebulaType := ""
if strings.Contains(pod.Name, "metad") {
nebulaType = "metad"
} else if strings.Contains(pod.Name, "storaged") {
nebulaType = "storaged"
} else if strings.Contains(pod.Name, "graphd") {
nebulaType = "graphd"
}

go func() {
defer wg.Done()
klog.Infof("Collect %s %s Metrics ", strings.ToUpper(nebulaType), pod.Name)
metrics, err := getNebulaMetrics(podIpAddress, podHttpPort)
if len(metrics) == 0 {
klog.Infof("metrics from %s:%d was empty", podIpAddress, podHttpPort)
}
if err != nil {
klog.Errorf("get query metrics from %s:%d failed: %v", podIpAddress, podHttpPort, err)
return
}

exporter.CollectMetrics(pod.Name, nebulaType, pod.Namespace, metrics, ch)
}()

statusMetrics, err := getNebulaComponentStatus(podIpAddress, podHttpPort, nebulaType)
if len(statusMetrics) == 0 {
klog.Errorf("could not get status metrics from %s:%d", podIpAddress, podHttpPort)
}
if err != nil {
klog.Errorf("get status metrics from %s:%d failed: %v", podIpAddress, podHttpPort, err)
return
}
exporter.CollectMetrics(pod.Name, nebulaType, pod.Namespace, statusMetrics, ch)
}

```

Leave a reaction on this issue to contribute to the project by classifying this instance as a **Bug** :-1:, **Mitigated** :+1:, or **Desirable Behavior** :rocket:
See the descriptions of the classifications [here](https://github.com/github-vet/rangeclosure-findings#how-can-i-help) for more information.

commit ID: f08f7874c23f56961439085e785a302c7562fd7b

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.