github.com/galamsiva2020/kubernetes-heapster-monitoring@v0.0.0-20210823134957-3c1baa7c1e70/events/sinks/factory.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 sinks 16 17 import ( 18 "fmt" 19 20 "k8s.io/heapster/common/flags" 21 "k8s.io/heapster/events/core" 22 "k8s.io/heapster/events/sinks/elasticsearch" 23 "k8s.io/heapster/events/sinks/gcl" 24 "k8s.io/heapster/events/sinks/honeycomb" 25 "k8s.io/heapster/events/sinks/influxdb" 26 "k8s.io/heapster/events/sinks/kafka" 27 "k8s.io/heapster/events/sinks/log" 28 "k8s.io/heapster/events/sinks/riemann" 29 30 "github.com/golang/glog" 31 ) 32 33 type SinkFactory struct { 34 } 35 36 func (this *SinkFactory) Build(uri flags.Uri) (core.EventSink, error) { 37 switch uri.Key { 38 case "gcl": 39 return gcl.CreateGCLSink(&uri.Val) 40 case "log": 41 return logsink.CreateLogSink() 42 case "influxdb": 43 return influxdb.CreateInfluxdbSink(&uri.Val) 44 case "elasticsearch": 45 return elasticsearch.NewElasticSearchSink(&uri.Val) 46 case "kafka": 47 return kafka.NewKafkaSink(&uri.Val) 48 case "riemann": 49 return riemann.CreateRiemannSink(&uri.Val) 50 case "honeycomb": 51 return honeycomb.NewHoneycombSink(&uri.Val) 52 default: 53 return nil, fmt.Errorf("Sink not recognized: %s", uri.Key) 54 } 55 } 56 57 func (this *SinkFactory) BuildAll(uris flags.Uris) []core.EventSink { 58 result := make([]core.EventSink, 0, len(uris)) 59 for _, uri := range uris { 60 sink, err := this.Build(uri) 61 if err != nil { 62 glog.Errorf("Failed to create %v sink: %v", uri, err) 63 continue 64 } 65 result = append(result, sink) 66 } 67 return result 68 } 69 70 func NewSinkFactory() *SinkFactory { 71 return &SinkFactory{} 72 }