github.com/galamsiva2020/kubernetes-heapster-monitoring@v0.0.0-20210823134957-3c1baa7c1e70/metrics/processors/cluster_aggregator.go (about)

     1  // Copyright 2015 Google Inc. All Rights Reserved.
     2  //
     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
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     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.
    14  
    15  package processors
    16  
    17  import "k8s.io/heapster/metrics/core"
    18  
    19  type ClusterAggregator struct {
    20  	MetricsToAggregate []string
    21  }
    22  
    23  func (this *ClusterAggregator) Name() string {
    24  	return "cluster_aggregator"
    25  }
    26  
    27  func (this *ClusterAggregator) Process(batch *core.DataBatch) (*core.DataBatch, error) {
    28  	clusterKey := core.ClusterKey()
    29  	cluster := clusterMetricSet()
    30  	for _, metricSet := range batch.MetricSets {
    31  		if metricSetType, found := metricSet.Labels[core.LabelMetricSetType.Key]; found &&
    32  			metricSetType == core.MetricSetTypeNamespace {
    33  			if err := aggregate(metricSet, cluster, this.MetricsToAggregate); err != nil {
    34  				return nil, err
    35  			}
    36  		}
    37  	}
    38  	batch.MetricSets[clusterKey] = cluster
    39  	return batch, nil
    40  }
    41  
    42  func clusterMetricSet() *core.MetricSet {
    43  	return &core.MetricSet{
    44  		MetricValues: make(map[string]core.MetricValue),
    45  		Labels: map[string]string{
    46  			core.LabelMetricSetType.Key: core.MetricSetTypeCluster,
    47  		},
    48  	}
    49  }