go.ligato.io/vpp-agent/v3@v3.5.0/plugins/orchestrator/options.go (about) 1 // Copyright (c) 2019 Cisco and/or its affiliates. 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 orchestrator 16 17 import ( 18 grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus" 19 "go.ligato.io/cn-infra/v2/datasync/kvdbsync/local" 20 "go.ligato.io/cn-infra/v2/rpc/grpc" 21 22 "go.ligato.io/vpp-agent/v3/plugins/kvscheduler" 23 ) 24 25 // DefaultPlugin is default instance of Plugin 26 var DefaultPlugin = *NewPlugin() 27 28 // NewPlugin creates a new Plugin with the provides Options 29 func NewPlugin(opts ...Option) *Plugin { 30 p := &Plugin{} 31 32 p.PluginName = "orchestrator" 33 p.GRPC = &grpc.DefaultPlugin 34 p.KVScheduler = &kvscheduler.DefaultPlugin 35 p.Watcher = local.DefaultRegistry 36 p.reflection = true 37 38 for _, o := range opts { 39 o(p) 40 } 41 p.PluginDeps.Setup() 42 43 return p 44 } 45 46 // Option is a function that acts on a Plugin to inject Dependencies or configuration 47 type Option func(*Plugin) 48 49 func UseReflection(enabled bool) Option { 50 return func(p *Plugin) { 51 p.reflection = enabled 52 } 53 } 54 55 func EnabledGrpcMetrics() { 56 grpc_prometheus.EnableHandlingTimeHistogram() 57 grpc.UsePromMetrics(grpc_prometheus.DefaultServerMetrics)(&grpc.DefaultPlugin) 58 }