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

     1  // Copyright 2016 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 hawkular
    16  
    17  import (
    18  	"net/url"
    19  	"sync"
    20  
    21  	"github.com/hawkular/hawkular-client-go/metrics"
    22  	"k8s.io/heapster/metrics/core"
    23  )
    24  
    25  type Filter func(ms *core.MetricSet, metricName string) bool
    26  type FilterType int
    27  
    28  const (
    29  	// Filter by label's value
    30  	Label FilterType = iota
    31  	// Filter by metric name
    32  	Name
    33  	// Unknown filter type
    34  	Unknown
    35  )
    36  
    37  func (f FilterType) From(s string) FilterType {
    38  	switch s {
    39  	case "label":
    40  		return Label
    41  	case "name":
    42  		return Name
    43  	default:
    44  		return Unknown
    45  	}
    46  }
    47  
    48  type expiringItem struct {
    49  	hash uint64
    50  	ttl  uint64
    51  }
    52  
    53  type hawkularSink struct {
    54  	client  *metrics.Client
    55  	models  map[string]*metrics.MetricDefinition // Model definitions
    56  	regLock sync.RWMutex
    57  	// reg      map[string]uint64 // Hash of real definition
    58  	expReg   map[string]*expiringItem
    59  	runId    uint64
    60  	cacheAge uint64
    61  
    62  	uri *url.URL
    63  
    64  	labelTenant    string
    65  	labelNodeId    string
    66  	labelTagPrefix string
    67  	modifiers      []metrics.Modifier
    68  	filters        []Filter
    69  
    70  	disablePreCaching bool
    71  	batchSize         int
    72  }
    73  
    74  func heapsterTypeToHawkularType(t core.MetricType) metrics.MetricType {
    75  	switch t {
    76  	case core.MetricCumulative:
    77  		return metrics.Counter
    78  	case core.MetricGauge:
    79  		return metrics.Gauge
    80  	default:
    81  		return metrics.Gauge
    82  	}
    83  }