grafana / vmware_exporter

Apache License 2.0
4 stars 5 forks source link

discovery interval data race #33

Closed rlankfo closed 2 years ago

rlankfo commented 2 years ago

A race is detected when setting the object discovery interval to a non-zero value.

go test -v -race ./...
?       github.com/grafana/vmware_exporter      [no test files]
=== RUN   TestExporter
2022/07/28 11:06:54 http: TLS handshake error from 127.0.0.1:50863: EOF
==================
WARNING: DATA RACE
Write at 0x00c0001e5c48 by goroutine 62:
  github.com/grafana/vmware_exporter/vsphere.(*endpoint).discover()
      /Users/robertlankford/code/grafana/vmware_exporter/vsphere/endpoint.go:256 +0x16f7
  github.com/grafana/vmware_exporter/vsphere.(*endpoint).startDiscovery.func1()
      /Users/robertlankford/code/grafana/vmware_exporter/vsphere/endpoint.go:171 +0x164

Previous read at 0x00c0001e5c48 by goroutine 73:
  github.com/grafana/vmware_exporter/vsphere.(*vsphereCollector).collectResource()
      /Users/robertlankford/code/grafana/vmware_exporter/vsphere/collector.go:80 +0x4e6
  github.com/grafana/vmware_exporter/vsphere.(*vsphereCollector).Collect.func1()
      /Users/robertlankford/code/grafana/vmware_exporter/vsphere/collector.go:56 +0x15b
  github.com/grafana/vmware_exporter/vsphere.(*vsphereCollector).Collect·dwrap·2()
      /Users/robertlankford/code/grafana/vmware_exporter/vsphere/collector.go:57 +0x66

Goroutine 62 (running) created at:
  github.com/grafana/vmware_exporter/vsphere.(*endpoint).startDiscovery()
      /Users/robertlankford/code/grafana/vmware_exporter/vsphere/endpoint.go:167 +0x15b
  github.com/grafana/vmware_exporter/vsphere.(*endpoint).initialDiscovery()
      /Users/robertlankford/code/grafana/vmware_exporter/vsphere/endpoint.go:162 +0x43a
  github.com/grafana/vmware_exporter/vsphere.(*endpoint).init()
      /Users/robertlankford/code/grafana/vmware_exporter/vsphere/endpoint.go:151 +0xc8
  github.com/grafana/vmware_exporter/vsphere.newVSphereCollector()
      /Users/robertlankford/code/grafana/vmware_exporter/vsphere/collector.go:232 +0x4f
  github.com/grafana/vmware_exporter/vsphere.NewExporter()
      /Users/robertlankford/code/grafana/vmware_exporter/vsphere/exporter.go:50 +0x5c6
  github.com/grafana/vmware_exporter/vsphere.TestExporter()
      /Users/robertlankford/code/grafana/vmware_exporter/vsphere/exporter_test.go:49 +0x352
  testing.tRunner()
      /Users/robertlankford/.gvm/gos/go1.17.7/src/testing/testing.go:1259 +0x22f
  testing.(*T).Run·dwrap·21()
      /Users/robertlankford/.gvm/gos/go1.17.7/src/testing/testing.go:1306 +0x47

Goroutine 73 (running) created at:
  github.com/grafana/vmware_exporter/vsphere.(*vsphereCollector).Collect()
      /Users/robertlankford/code/grafana/vmware_exporter/vsphere/collector.go:54 +0x1253
  github.com/prometheus/client_golang/prometheus.(*Registry).Gather.func1()
      /Users/robertlankford/code/grafana/vmware_exporter/vendor/github.com/prometheus/client_golang/prometheus/registry.go:448 +0x14d
==================
    exporter_test.go:81: Expected metrics to contain 'vsphere_VirtualMachine_disk_maxTotalLatency_latest'
    testing.go:1152: race detected during execution of test
--- FAIL: TestExporter (3.68s)
=== CONT
    testing.go:1152: race detected during execution of test
FAIL
FAIL    github.com/grafana/vmware_exporter/vsphere      4.004s
FAIL
make: *** [Makefile:23: test] Error 1