temp commit
This commit is contained in:
221
vendor/github.com/prometheus/client_golang/api/prometheus/v1/api.go
generated
vendored
221
vendor/github.com/prometheus/client_golang/api/prometheus/v1/api.go
generated
vendored
@@ -20,6 +20,7 @@ package v1
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
@@ -40,6 +41,7 @@ const (
|
||||
epLabelValues = apiPrefix + "/label/:name/values"
|
||||
epSeries = apiPrefix + "/series"
|
||||
epTargets = apiPrefix + "/targets"
|
||||
epRules = apiPrefix + "/rules"
|
||||
epSnapshot = apiPrefix + "/admin/tsdb/snapshot"
|
||||
epDeleteSeries = apiPrefix + "/admin/tsdb/delete_series"
|
||||
epCleanTombstones = apiPrefix + "/admin/tsdb/clean_tombstones"
|
||||
@@ -47,13 +49,27 @@ const (
|
||||
epFlags = apiPrefix + "/status/flags"
|
||||
)
|
||||
|
||||
// AlertState models the state of an alert.
|
||||
type AlertState string
|
||||
|
||||
// ErrorType models the different API error types.
|
||||
type ErrorType string
|
||||
|
||||
// HealthStatus models the health status of a scrape target.
|
||||
type HealthStatus string
|
||||
|
||||
// RuleType models the type of a rule.
|
||||
type RuleType string
|
||||
|
||||
// RuleHealth models the health status of a rule.
|
||||
type RuleHealth string
|
||||
|
||||
const (
|
||||
// Possible values for AlertState.
|
||||
AlertStateFiring AlertState = "firing"
|
||||
AlertStateInactive AlertState = "inactive"
|
||||
AlertStatePending AlertState = "pending"
|
||||
|
||||
// Possible values for ErrorType.
|
||||
ErrBadData ErrorType = "bad_data"
|
||||
ErrTimeout ErrorType = "timeout"
|
||||
@@ -67,6 +83,15 @@ const (
|
||||
HealthGood HealthStatus = "up"
|
||||
HealthUnknown HealthStatus = "unknown"
|
||||
HealthBad HealthStatus = "down"
|
||||
|
||||
// Possible values for RuleType.
|
||||
RuleTypeRecording RuleType = "recording"
|
||||
RuleTypeAlerting RuleType = "alerting"
|
||||
|
||||
// Possible values for RuleHealth.
|
||||
RuleHealthGood = "ok"
|
||||
RuleHealthUnknown = "unknown"
|
||||
RuleHealthBad = "err"
|
||||
)
|
||||
|
||||
// Error is an error returned by the API.
|
||||
@@ -111,6 +136,8 @@ type API interface {
|
||||
// Snapshot creates a snapshot of all current data into snapshots/<datetime>-<rand>
|
||||
// under the TSDB's data directory and returns the directory as response.
|
||||
Snapshot(ctx context.Context, skipHead bool) (SnapshotResult, error)
|
||||
// Rules returns a list of alerting and recording rules that are currently loaded.
|
||||
Rules(ctx context.Context) (RulesResult, error)
|
||||
// Targets returns an overview of the current state of the Prometheus target discovery.
|
||||
Targets(ctx context.Context) (TargetsResult, error)
|
||||
}
|
||||
@@ -139,6 +166,63 @@ type SnapshotResult struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
// RulesResult contains the result from querying the rules endpoint.
|
||||
type RulesResult struct {
|
||||
Groups []RuleGroup `json:"groups"`
|
||||
}
|
||||
|
||||
// RuleGroup models a rule group that contains a set of recording and alerting rules.
|
||||
type RuleGroup struct {
|
||||
Name string `json:"name"`
|
||||
File string `json:"file"`
|
||||
Interval float64 `json:"interval"`
|
||||
Rules Rules `json:"rules"`
|
||||
}
|
||||
|
||||
// Recording and alerting rules are stored in the same slice to preserve the order
|
||||
// that rules are returned in by the API.
|
||||
//
|
||||
// Rule types can be determined using a type switch:
|
||||
// switch v := rule.(type) {
|
||||
// case RecordingRule:
|
||||
// fmt.Print("got a recording rule")
|
||||
// case AlertingRule:
|
||||
// fmt.Print("got a alerting rule")
|
||||
// default:
|
||||
// fmt.Printf("unknown rule type %s", v)
|
||||
// }
|
||||
type Rules []interface{}
|
||||
|
||||
// AlertingRule models a alerting rule.
|
||||
type AlertingRule struct {
|
||||
Name string `json:"name"`
|
||||
Query string `json:"query"`
|
||||
Duration float64 `json:"duration"`
|
||||
Labels model.LabelSet `json:"labels"`
|
||||
Annotations model.LabelSet `json:"annotations"`
|
||||
Alerts []*Alert `json:"alerts"`
|
||||
Health RuleHealth `json:"health"`
|
||||
LastError string `json:"lastError,omitempty"`
|
||||
}
|
||||
|
||||
// RecordingRule models a recording rule.
|
||||
type RecordingRule struct {
|
||||
Name string `json:"name"`
|
||||
Query string `json:"query"`
|
||||
Labels model.LabelSet `json:"labels,omitempty"`
|
||||
Health RuleHealth `json:"health"`
|
||||
LastError string `json:"lastError,omitempty"`
|
||||
}
|
||||
|
||||
// Alert models an active alert.
|
||||
type Alert struct {
|
||||
ActiveAt time.Time `json:"activeAt"`
|
||||
Annotations model.LabelSet
|
||||
Labels model.LabelSet
|
||||
State AlertState
|
||||
Value float64
|
||||
}
|
||||
|
||||
// TargetsResult contains the result from querying the targets endpoint.
|
||||
type TargetsResult struct {
|
||||
Active []ActiveTarget `json:"activeTargets"`
|
||||
@@ -147,17 +231,17 @@ type TargetsResult struct {
|
||||
|
||||
// ActiveTarget models an active Prometheus scrape target.
|
||||
type ActiveTarget struct {
|
||||
DiscoveredLabels model.LabelSet `json:"discoveredLabels"`
|
||||
Labels model.LabelSet `json:"labels"`
|
||||
ScrapeURL string `json:"scrapeUrl"`
|
||||
LastError string `json:"lastError"`
|
||||
LastScrape time.Time `json:"lastScrape"`
|
||||
Health HealthStatus `json:"health"`
|
||||
DiscoveredLabels map[string]string `json:"discoveredLabels"`
|
||||
Labels model.LabelSet `json:"labels"`
|
||||
ScrapeURL string `json:"scrapeUrl"`
|
||||
LastError string `json:"lastError"`
|
||||
LastScrape time.Time `json:"lastScrape"`
|
||||
Health HealthStatus `json:"health"`
|
||||
}
|
||||
|
||||
// DroppedTarget models a dropped Prometheus scrape target.
|
||||
type DroppedTarget struct {
|
||||
DiscoveredLabels model.LabelSet `json:"discoveredLabels"`
|
||||
DiscoveredLabels map[string]string `json:"discoveredLabels"`
|
||||
}
|
||||
|
||||
// queryResult contains result data for a query.
|
||||
@@ -169,6 +253,111 @@ type queryResult struct {
|
||||
v model.Value
|
||||
}
|
||||
|
||||
func (rg *RuleGroup) UnmarshalJSON(b []byte) error {
|
||||
v := struct {
|
||||
Name string `json:"name"`
|
||||
File string `json:"file"`
|
||||
Interval float64 `json:"interval"`
|
||||
Rules []json.RawMessage `json:"rules"`
|
||||
}{}
|
||||
|
||||
if err := json.Unmarshal(b, &v); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rg.Name = v.Name
|
||||
rg.File = v.File
|
||||
rg.Interval = v.Interval
|
||||
|
||||
for _, rule := range v.Rules {
|
||||
alertingRule := AlertingRule{}
|
||||
if err := json.Unmarshal(rule, &alertingRule); err == nil {
|
||||
rg.Rules = append(rg.Rules, alertingRule)
|
||||
continue
|
||||
}
|
||||
recordingRule := RecordingRule{}
|
||||
if err := json.Unmarshal(rule, &recordingRule); err == nil {
|
||||
rg.Rules = append(rg.Rules, recordingRule)
|
||||
continue
|
||||
}
|
||||
return errors.New("failed to decode JSON into an alerting or recording rule")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *AlertingRule) UnmarshalJSON(b []byte) error {
|
||||
v := struct {
|
||||
Type string `json:"type"`
|
||||
}{}
|
||||
if err := json.Unmarshal(b, &v); err != nil {
|
||||
return err
|
||||
}
|
||||
if v.Type == "" {
|
||||
return errors.New("type field not present in rule")
|
||||
}
|
||||
if v.Type != string(RuleTypeAlerting) {
|
||||
return fmt.Errorf("expected rule of type %s but got %s", string(RuleTypeAlerting), v.Type)
|
||||
}
|
||||
|
||||
rule := struct {
|
||||
Name string `json:"name"`
|
||||
Query string `json:"query"`
|
||||
Duration float64 `json:"duration"`
|
||||
Labels model.LabelSet `json:"labels"`
|
||||
Annotations model.LabelSet `json:"annotations"`
|
||||
Alerts []*Alert `json:"alerts"`
|
||||
Health RuleHealth `json:"health"`
|
||||
LastError string `json:"lastError,omitempty"`
|
||||
}{}
|
||||
if err := json.Unmarshal(b, &rule); err != nil {
|
||||
return err
|
||||
}
|
||||
r.Health = rule.Health
|
||||
r.Annotations = rule.Annotations
|
||||
r.Name = rule.Name
|
||||
r.Query = rule.Query
|
||||
r.Alerts = rule.Alerts
|
||||
r.Duration = rule.Duration
|
||||
r.Labels = rule.Labels
|
||||
r.LastError = rule.LastError
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *RecordingRule) UnmarshalJSON(b []byte) error {
|
||||
v := struct {
|
||||
Type string `json:"type"`
|
||||
}{}
|
||||
if err := json.Unmarshal(b, &v); err != nil {
|
||||
return err
|
||||
}
|
||||
if v.Type == "" {
|
||||
return errors.New("type field not present in rule")
|
||||
}
|
||||
if v.Type != string(RuleTypeRecording) {
|
||||
return fmt.Errorf("expected rule of type %s but got %s", string(RuleTypeRecording), v.Type)
|
||||
}
|
||||
|
||||
rule := struct {
|
||||
Name string `json:"name"`
|
||||
Query string `json:"query"`
|
||||
Labels model.LabelSet `json:"labels,omitempty"`
|
||||
Health RuleHealth `json:"health"`
|
||||
LastError string `json:"lastError,omitempty"`
|
||||
}{}
|
||||
if err := json.Unmarshal(b, &rule); err != nil {
|
||||
return err
|
||||
}
|
||||
r.Health = rule.Health
|
||||
r.Labels = rule.Labels
|
||||
r.Name = rule.Name
|
||||
r.LastError = rule.LastError
|
||||
r.Query = rule.Query
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (qr *queryResult) UnmarshalJSON(b []byte) error {
|
||||
v := struct {
|
||||
Type model.ValueType `json:"resultType"`
|
||||
@@ -427,6 +616,24 @@ func (h *httpAPI) Snapshot(ctx context.Context, skipHead bool) (SnapshotResult,
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (h *httpAPI) Rules(ctx context.Context) (RulesResult, error) {
|
||||
u := h.client.URL(epRules, nil)
|
||||
|
||||
req, err := http.NewRequest(http.MethodGet, u.String(), nil)
|
||||
if err != nil {
|
||||
return RulesResult{}, err
|
||||
}
|
||||
|
||||
_, body, err := h.client.Do(ctx, req)
|
||||
if err != nil {
|
||||
return RulesResult{}, err
|
||||
}
|
||||
|
||||
var res RulesResult
|
||||
err = json.Unmarshal(body, &res)
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (h *httpAPI) Targets(ctx context.Context) (TargetsResult, error) {
|
||||
u := h.client.URL(epTargets, nil)
|
||||
|
||||
|
||||
2
vendor/github.com/prometheus/client_golang/prometheus/collector.go
generated
vendored
2
vendor/github.com/prometheus/client_golang/prometheus/collector.go
generated
vendored
@@ -79,7 +79,7 @@ type Collector interface {
|
||||
// of the Describe method. If a Collector sometimes collects no metrics at all
|
||||
// (for example vectors like CounterVec, GaugeVec, etc., which only collect
|
||||
// metrics after a metric with a fully specified label set has been accessed),
|
||||
// it might even get registered as an unchecked Collecter (cf. the Register
|
||||
// it might even get registered as an unchecked Collector (cf. the Register
|
||||
// method of the Registerer interface). Hence, only use this shortcut
|
||||
// implementation of Describe if you are certain to fulfill the contract.
|
||||
//
|
||||
|
||||
6
vendor/github.com/prometheus/client_golang/prometheus/doc.go
generated
vendored
6
vendor/github.com/prometheus/client_golang/prometheus/doc.go
generated
vendored
@@ -122,13 +122,13 @@
|
||||
// the Collect method. The Describe method has to return separate Desc
|
||||
// instances, representative of the “throw-away” metrics to be created later.
|
||||
// NewDesc comes in handy to create those Desc instances. Alternatively, you
|
||||
// could return no Desc at all, which will marke the Collector “unchecked”. No
|
||||
// checks are porformed at registration time, but metric consistency will still
|
||||
// could return no Desc at all, which will mark the Collector “unchecked”. No
|
||||
// checks are performed at registration time, but metric consistency will still
|
||||
// be ensured at scrape time, i.e. any inconsistencies will lead to scrape
|
||||
// errors. Thus, with unchecked Collectors, the responsibility to not collect
|
||||
// metrics that lead to inconsistencies in the total scrape result lies with the
|
||||
// implementer of the Collector. While this is not a desirable state, it is
|
||||
// sometimes necessary. The typical use case is a situatios where the exact
|
||||
// sometimes necessary. The typical use case is a situation where the exact
|
||||
// metrics to be returned by a Collector cannot be predicted at registration
|
||||
// time, but the implementer has sufficient knowledge of the whole system to
|
||||
// guarantee metric consistency.
|
||||
|
||||
4
vendor/github.com/prometheus/client_golang/prometheus/histogram.go
generated
vendored
4
vendor/github.com/prometheus/client_golang/prometheus/histogram.go
generated
vendored
@@ -204,8 +204,8 @@ func newHistogram(desc *Desc, opts HistogramOpts, labelValues ...string) Histogr
|
||||
}
|
||||
}
|
||||
}
|
||||
// Finally we know the final length of h.upperBounds and can make counts
|
||||
// for both states:
|
||||
// Finally we know the final length of h.upperBounds and can make buckets
|
||||
// for both counts:
|
||||
h.counts[0].buckets = make([]uint64, len(h.upperBounds))
|
||||
h.counts[1].buckets = make([]uint64, len(h.upperBounds))
|
||||
|
||||
|
||||
1
vendor/github.com/prometheus/client_golang/prometheus/http.go
generated
vendored
1
vendor/github.com/prometheus/client_golang/prometheus/http.go
generated
vendored
@@ -34,7 +34,6 @@ import (
|
||||
|
||||
const (
|
||||
contentTypeHeader = "Content-Type"
|
||||
contentLengthHeader = "Content-Length"
|
||||
contentEncodingHeader = "Content-Encoding"
|
||||
acceptEncodingHeader = "Accept-Encoding"
|
||||
)
|
||||
|
||||
1
vendor/github.com/prometheus/client_golang/prometheus/promhttp/delegator.go
generated
vendored
1
vendor/github.com/prometheus/client_golang/prometheus/promhttp/delegator.go
generated
vendored
@@ -38,7 +38,6 @@ type delegator interface {
|
||||
type responseWriterDelegator struct {
|
||||
http.ResponseWriter
|
||||
|
||||
handler, method string
|
||||
status int
|
||||
written int64
|
||||
wroteHeader bool
|
||||
|
||||
1
vendor/github.com/prometheus/client_golang/prometheus/promhttp/http.go
generated
vendored
1
vendor/github.com/prometheus/client_golang/prometheus/promhttp/http.go
generated
vendored
@@ -47,7 +47,6 @@ import (
|
||||
|
||||
const (
|
||||
contentTypeHeader = "Content-Type"
|
||||
contentLengthHeader = "Content-Length"
|
||||
contentEncodingHeader = "Content-Encoding"
|
||||
acceptEncodingHeader = "Accept-Encoding"
|
||||
)
|
||||
|
||||
2
vendor/github.com/prometheus/client_golang/prometheus/registry.go
generated
vendored
2
vendor/github.com/prometheus/client_golang/prometheus/registry.go
generated
vendored
@@ -680,7 +680,7 @@ func processMetric(
|
||||
// Gatherers is a slice of Gatherer instances that implements the Gatherer
|
||||
// interface itself. Its Gather method calls Gather on all Gatherers in the
|
||||
// slice in order and returns the merged results. Errors returned from the
|
||||
// Gather calles are all returned in a flattened MultiError. Duplicate and
|
||||
// Gather calls are all returned in a flattened MultiError. Duplicate and
|
||||
// inconsistent Metrics are skipped (first occurrence in slice order wins) and
|
||||
// reported in the returned error.
|
||||
//
|
||||
|
||||
151
vendor/github.com/prometheus/client_golang/prometheus/summary.go
generated
vendored
151
vendor/github.com/prometheus/client_golang/prometheus/summary.go
generated
vendored
@@ -16,8 +16,10 @@ package prometheus
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"runtime"
|
||||
"sort"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/beorn7/perks/quantile"
|
||||
@@ -151,7 +153,7 @@ type SummaryOpts struct {
|
||||
BufCap uint32
|
||||
}
|
||||
|
||||
// Great fuck-up with the sliding-window decay algorithm... The Merge method of
|
||||
// Problem with the sliding-window decay algorithm... The Merge method of
|
||||
// perk/quantile is actually not working as advertised - and it might be
|
||||
// unfixable, as the underlying algorithm is apparently not capable of merging
|
||||
// summaries in the first place. To avoid using Merge, we are currently adding
|
||||
@@ -214,6 +216,17 @@ func newSummary(desc *Desc, opts SummaryOpts, labelValues ...string) Summary {
|
||||
opts.BufCap = DefBufCap
|
||||
}
|
||||
|
||||
if len(opts.Objectives) == 0 {
|
||||
// Use the lock-free implementation of a Summary without objectives.
|
||||
s := &noObjectivesSummary{
|
||||
desc: desc,
|
||||
labelPairs: makeLabelPairs(desc, labelValues),
|
||||
counts: [2]*summaryCounts{&summaryCounts{}, &summaryCounts{}},
|
||||
}
|
||||
s.init(s) // Init self-collection.
|
||||
return s
|
||||
}
|
||||
|
||||
s := &summary{
|
||||
desc: desc,
|
||||
|
||||
@@ -382,6 +395,142 @@ func (s *summary) swapBufs(now time.Time) {
|
||||
}
|
||||
}
|
||||
|
||||
type summaryCounts struct {
|
||||
// sumBits contains the bits of the float64 representing the sum of all
|
||||
// observations. sumBits and count have to go first in the struct to
|
||||
// guarantee alignment for atomic operations.
|
||||
// http://golang.org/pkg/sync/atomic/#pkg-note-BUG
|
||||
sumBits uint64
|
||||
count uint64
|
||||
}
|
||||
|
||||
type noObjectivesSummary struct {
|
||||
// countAndHotIdx is a complicated one. For lock-free yet atomic
|
||||
// observations, we need to save the total count of observations again,
|
||||
// combined with the index of the currently-hot counts struct, so that
|
||||
// we can perform the operation on both values atomically. The least
|
||||
// significant bit defines the hot counts struct. The remaining 63 bits
|
||||
// represent the total count of observations. This happens under the
|
||||
// assumption that the 63bit count will never overflow. Rationale: An
|
||||
// observations takes about 30ns. Let's assume it could happen in
|
||||
// 10ns. Overflowing the counter will then take at least (2^63)*10ns,
|
||||
// which is about 3000 years.
|
||||
//
|
||||
// This has to be first in the struct for 64bit alignment. See
|
||||
// http://golang.org/pkg/sync/atomic/#pkg-note-BUG
|
||||
countAndHotIdx uint64
|
||||
|
||||
selfCollector
|
||||
desc *Desc
|
||||
writeMtx sync.Mutex // Only used in the Write method.
|
||||
|
||||
// Two counts, one is "hot" for lock-free observations, the other is
|
||||
// "cold" for writing out a dto.Metric. It has to be an array of
|
||||
// pointers to guarantee 64bit alignment of the histogramCounts, see
|
||||
// http://golang.org/pkg/sync/atomic/#pkg-note-BUG.
|
||||
counts [2]*summaryCounts
|
||||
hotIdx int // Index of currently-hot counts. Only used within Write.
|
||||
|
||||
labelPairs []*dto.LabelPair
|
||||
}
|
||||
|
||||
func (s *noObjectivesSummary) Desc() *Desc {
|
||||
return s.desc
|
||||
}
|
||||
|
||||
func (s *noObjectivesSummary) Observe(v float64) {
|
||||
// We increment s.countAndHotIdx by 2 so that the counter in the upper
|
||||
// 63 bits gets incremented by 1. At the same time, we get the new value
|
||||
// back, which we can use to find the currently-hot counts.
|
||||
n := atomic.AddUint64(&s.countAndHotIdx, 2)
|
||||
hotCounts := s.counts[n%2]
|
||||
|
||||
for {
|
||||
oldBits := atomic.LoadUint64(&hotCounts.sumBits)
|
||||
newBits := math.Float64bits(math.Float64frombits(oldBits) + v)
|
||||
if atomic.CompareAndSwapUint64(&hotCounts.sumBits, oldBits, newBits) {
|
||||
break
|
||||
}
|
||||
}
|
||||
// Increment count last as we take it as a signal that the observation
|
||||
// is complete.
|
||||
atomic.AddUint64(&hotCounts.count, 1)
|
||||
}
|
||||
|
||||
func (s *noObjectivesSummary) Write(out *dto.Metric) error {
|
||||
var (
|
||||
sum = &dto.Summary{}
|
||||
hotCounts, coldCounts *summaryCounts
|
||||
count uint64
|
||||
)
|
||||
|
||||
// For simplicity, we mutex the rest of this method. It is not in the
|
||||
// hot path, i.e. Observe is called much more often than Write. The
|
||||
// complication of making Write lock-free isn't worth it.
|
||||
s.writeMtx.Lock()
|
||||
defer s.writeMtx.Unlock()
|
||||
|
||||
// This is a bit arcane, which is why the following spells out this if
|
||||
// clause in English:
|
||||
//
|
||||
// If the currently-hot counts struct is #0, we atomically increment
|
||||
// s.countAndHotIdx by 1 so that from now on Observe will use the counts
|
||||
// struct #1. Furthermore, the atomic increment gives us the new value,
|
||||
// which, in its most significant 63 bits, tells us the count of
|
||||
// observations done so far up to and including currently ongoing
|
||||
// observations still using the counts struct just changed from hot to
|
||||
// cold. To have a normal uint64 for the count, we bitshift by 1 and
|
||||
// save the result in count. We also set s.hotIdx to 1 for the next
|
||||
// Write call, and we will refer to counts #1 as hotCounts and to counts
|
||||
// #0 as coldCounts.
|
||||
//
|
||||
// If the currently-hot counts struct is #1, we do the corresponding
|
||||
// things the other way round. We have to _decrement_ s.countAndHotIdx
|
||||
// (which is a bit arcane in itself, as we have to express -1 with an
|
||||
// unsigned int...).
|
||||
if s.hotIdx == 0 {
|
||||
count = atomic.AddUint64(&s.countAndHotIdx, 1) >> 1
|
||||
s.hotIdx = 1
|
||||
hotCounts = s.counts[1]
|
||||
coldCounts = s.counts[0]
|
||||
} else {
|
||||
count = atomic.AddUint64(&s.countAndHotIdx, ^uint64(0)) >> 1 // Decrement.
|
||||
s.hotIdx = 0
|
||||
hotCounts = s.counts[0]
|
||||
coldCounts = s.counts[1]
|
||||
}
|
||||
|
||||
// Now we have to wait for the now-declared-cold counts to actually cool
|
||||
// down, i.e. wait for all observations still using it to finish. That's
|
||||
// the case once the count in the cold counts struct is the same as the
|
||||
// one atomically retrieved from the upper 63bits of s.countAndHotIdx.
|
||||
for {
|
||||
if count == atomic.LoadUint64(&coldCounts.count) {
|
||||
break
|
||||
}
|
||||
runtime.Gosched() // Let observations get work done.
|
||||
}
|
||||
|
||||
sum.SampleCount = proto.Uint64(count)
|
||||
sum.SampleSum = proto.Float64(math.Float64frombits(atomic.LoadUint64(&coldCounts.sumBits)))
|
||||
|
||||
out.Summary = sum
|
||||
out.Label = s.labelPairs
|
||||
|
||||
// Finally add all the cold counts to the new hot counts and reset the cold counts.
|
||||
atomic.AddUint64(&hotCounts.count, count)
|
||||
atomic.StoreUint64(&coldCounts.count, 0)
|
||||
for {
|
||||
oldBits := atomic.LoadUint64(&hotCounts.sumBits)
|
||||
newBits := math.Float64bits(math.Float64frombits(oldBits) + sum.GetSampleSum())
|
||||
if atomic.CompareAndSwapUint64(&hotCounts.sumBits, oldBits, newBits) {
|
||||
atomic.StoreUint64(&coldCounts.sumBits, 0)
|
||||
break
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type quantSort []*dto.Quantile
|
||||
|
||||
func (s quantSort) Len() int {
|
||||
|
||||
Reference in New Issue
Block a user