github.com/jonaz/heapster@v1.3.0-beta.0.0.20170208112634-cd3c15ca3d29/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 hawkularSink struct { 49 client *metrics.Client 50 models map[string]*metrics.MetricDefinition // Model definitions 51 regLock sync.Mutex 52 reg map[string]*metrics.MetricDefinition // Real definitions 53 54 uri *url.URL 55 56 labelTenant string 57 labelNodeId string 58 modifiers []metrics.Modifier 59 filters []Filter 60 61 batchSize int 62 } 63 64 func heapsterTypeToHawkularType(t core.MetricType) metrics.MetricType { 65 switch t { 66 case core.MetricCumulative: 67 return metrics.Counter 68 case core.MetricGauge: 69 return metrics.Gauge 70 default: 71 return metrics.Gauge 72 } 73 }