1 // Copyright 2019, OpenCensus Authors
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 package metricproducer
21 // Manager maintains a list of active producers. Producers can register
22 // with the manager to allow readers to read all metrics provided by them.
23 // Readers can retrieve all producers registered with the manager,
24 // read metrics from the producers and export them.
27 producers map[Producer]struct{}
33 // GlobalManager is a single instance of producer manager
34 // that is used by all producers and all readers.
35 func GlobalManager() *Manager {
38 prodMgr.producers = make(map[Producer]struct{})
43 // AddProducer adds the producer to the Manager if it is not already present.
44 func (pm *Manager) AddProducer(producer Producer) {
50 pm.producers[producer] = struct{}{}
53 // DeleteProducer deletes the producer from the Manager if it is present.
54 func (pm *Manager) DeleteProducer(producer Producer) {
60 delete(pm.producers, producer)
63 // GetAll returns a slice of all producer currently registered with
64 // the Manager. For each call it generates a new slice. The slice
65 // should not be cached as registration may change at any time. It is
66 // typically called periodically by exporter to read metrics from
68 func (pm *Manager) GetAll() []Producer {
71 producers := make([]Producer, len(pm.producers))
73 for producer := range pm.producers {
74 producers[i] = producer