Gather implements TransactionalGatherer interface.
()
| 1009 | |
| 1010 | // Gather implements TransactionalGatherer interface. |
| 1011 | func (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. |