Skip to content

Commit

Permalink
Allow concurrent metrics collection (ClickHouse#28)
Browse files Browse the repository at this point in the history
There is no reason to hold a lock, as nothing is shared. Also, clean up dead code.
  • Loading branch information
nvartolomei authored and f1yegor committed Mar 15, 2019
1 parent 1038e72 commit fc3a556
Showing 1 changed file with 0 additions and 27 deletions.
27 changes: 0 additions & 27 deletions exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"net/url"
"strconv"
"strings"
"sync"
"time"
"unicode"

Expand All @@ -27,14 +26,10 @@ type Exporter struct {
asyncMetricsURI string
eventsURI string
partsURI string
mutex sync.RWMutex
client *http.Client

scrapeFailures prometheus.Counter

gauges []*prometheus.GaugeVec
counters []*prometheus.CounterVec

user string
password string
}
Expand Down Expand Up @@ -68,8 +63,6 @@ func NewExporter(uri url.URL, insecure bool, user, password string) *Exporter {
Name: "exporter_scrape_failures_total",
Help: "Number of errors while scraping clickhouse.",
}),
gauges: make([]*prometheus.GaugeVec, 0, 20),
counters: make([]*prometheus.CounterVec, 0, 20),
client: &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: insecure},
Expand Down Expand Up @@ -295,31 +288,11 @@ func (e *Exporter) parsePartsResponse(uri string) ([]partsResult, error) {
// Collect fetches the stats from configured clickhouse location and delivers them
// as Prometheus metrics. It implements prometheus.Collector.
func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
e.mutex.Lock() // To protect metrics from concurrent collects.
defer e.mutex.Unlock()
if err := e.collect(ch); err != nil {
log.Printf("Error scraping clickhouse: %s", err)
e.scrapeFailures.Inc()
e.scrapeFailures.Collect(ch)
}
// Reset metrics.
for _, vec := range e.gauges {
vec.Reset()
}

for _, vec := range e.counters {
vec.Reset()
}

for _, vec := range e.gauges {
vec.Collect(ch)
}

for _, vec := range e.counters {
vec.Collect(ch)
}

return
}

func metricName(in string) string {
Expand Down

0 comments on commit fc3a556

Please sign in to comment.