MCPcopy
hub / github.com/prometheus/client_golang / Gather

Method Gather

prometheus/registry.go:1011–1034  ·  view source on GitHub ↗

Gather implements TransactionalGatherer interface.

()

Source from the content-addressed store, hash-verified

1009
1010// Gather implements TransactionalGatherer interface.
1011func (r *MultiTRegistry) Gather() (mfs []*dto.MetricFamily, done func(), err error) {
1012 errs := MultiError{}
1013
1014 dFns := make([]func(), 0, len(r.tGatherers))
1015 // TODO(bwplotka): Implement concurrency for those?
1016 for _, g := range r.tGatherers {
1017 // TODO(bwplotka): Check for duplicates?
1018 m, d, err := g.Gather()
1019 errs.Append(err)
1020
1021 mfs = append(mfs, m...)
1022 dFns = append(dFns, d)
1023 }
1024
1025 // TODO(bwplotka): Consider sort in place, given metric family in gather is sorted already.
1026 sort.Slice(mfs, func(i, j int) bool {
1027 return *mfs[i].Name < *mfs[j].Name
1028 })
1029 return mfs, func() {
1030 for _, d := range dFns {
1031 d()
1032 }
1033 }, errs.MaybeUnwrap()
1034}
1035
1036// TransactionalGatherer represents transactional gatherer that can be triggered to notify gatherer that memory
1037// used by metric family is no longer used by a caller. This allows implementations with cache.

Callers 1

TestNewMultiTRegistryFunction · 0.95

Calls 3

AppendMethod · 0.95
MaybeUnwrapMethod · 0.95
GatherMethod · 0.65

Tested by 1

TestNewMultiTRegistryFunction · 0.76