Create init method on provider interface
This commit is contained in:
parent
b2a57ca1f3
commit
027093a5a5
52 changed files with 2760 additions and 131 deletions
45
vendor/github.com/containous/traefik-extra-service-fabric/servicefabric.go
generated
vendored
45
vendor/github.com/containous/traefik-extra-service-fabric/servicefabric.go
generated
vendored
|
@ -8,12 +8,14 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/cenk/backoff"
|
||||
"github.com/containous/flaeg"
|
||||
"github.com/containous/traefik/job"
|
||||
"github.com/containous/traefik/log"
|
||||
"github.com/containous/traefik/provider"
|
||||
"github.com/containous/traefik/provider/label"
|
||||
"github.com/containous/traefik/safe"
|
||||
"github.com/containous/traefik/types"
|
||||
"github.com/jjcollinge/logrus-appinsights"
|
||||
sf "github.com/jjcollinge/servicefabric"
|
||||
)
|
||||
|
||||
|
@ -31,13 +33,23 @@ type Provider struct {
|
|||
provider.BaseProvider `mapstructure:",squash"`
|
||||
ClusterManagementURL string `description:"Service Fabric API endpoint"`
|
||||
APIVersion string `description:"Service Fabric API version" export:"true"`
|
||||
RefreshSeconds int `description:"Polling interval (in seconds)" export:"true"`
|
||||
RefreshSeconds flaeg.Duration `description:"Polling interval (in seconds)" export:"true"`
|
||||
TLS *types.ClientTLS `description:"Enable TLS support" export:"true"`
|
||||
AppInsightsClientName string `description:"The client name, Identifies the cloud instance"`
|
||||
AppInsightsKey string `description:"Application Insights Instrumentation Key"`
|
||||
AppInsightsBatchSize int `description:"Number of trace lines per batch, optional"`
|
||||
AppInsightsInterval flaeg.Duration `description:"The interval for sending data to Application Insights, optional"`
|
||||
}
|
||||
|
||||
// Init the provider
|
||||
func (p *Provider) Init(constraints types.Constraints) error {
|
||||
p.BaseProvider.Init(constraints)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Provide allows the ServiceFabric provider to provide configurations to traefik
|
||||
// using the given configuration channel.
|
||||
func (p *Provider) Provide(configurationChan chan<- types.ConfigMessage, pool *safe.Pool, constraints types.Constraints) error {
|
||||
func (p *Provider) Provide(configurationChan chan<- types.ConfigMessage, pool *safe.Pool) error {
|
||||
if p.APIVersion == "" {
|
||||
p.APIVersion = sf.DefaultAPIVersion
|
||||
}
|
||||
|
@ -53,10 +65,20 @@ func (p *Provider) Provide(configurationChan chan<- types.ConfigMessage, pool *s
|
|||
}
|
||||
|
||||
if p.RefreshSeconds <= 0 {
|
||||
p.RefreshSeconds = 10
|
||||
p.RefreshSeconds = flaeg.Duration(10 * time.Second)
|
||||
}
|
||||
|
||||
return p.updateConfig(configurationChan, pool, sfClient, time.Duration(p.RefreshSeconds)*time.Second)
|
||||
if p.AppInsightsClientName != "" && p.AppInsightsKey != "" {
|
||||
if p.AppInsightsBatchSize == 0 {
|
||||
p.AppInsightsBatchSize = 10
|
||||
}
|
||||
if p.AppInsightsInterval == 0 {
|
||||
p.AppInsightsInterval = flaeg.Duration(5 * time.Second)
|
||||
}
|
||||
createAppInsightsHook(p.AppInsightsClientName, p.AppInsightsKey, p.AppInsightsBatchSize, p.AppInsightsInterval)
|
||||
}
|
||||
|
||||
return p.updateConfig(configurationChan, pool, sfClient, time.Duration(p.RefreshSeconds))
|
||||
}
|
||||
|
||||
func (p *Provider) updateConfig(configurationChan chan<- types.ConfigMessage, pool *safe.Pool, sfClient sfClient, pollInterval time.Duration) error {
|
||||
|
@ -263,3 +285,18 @@ func getLabels(sfClient sfClient, service *sf.ServiceItem, app *sf.ApplicationIt
|
|||
}
|
||||
return labels, nil
|
||||
}
|
||||
|
||||
func createAppInsightsHook(appInsightsClientName string, instrumentationKey string, maxBatchSize int, interval flaeg.Duration) {
|
||||
hook, err := logrus_appinsights.New(appInsightsClientName, logrus_appinsights.Config{
|
||||
InstrumentationKey: instrumentationKey,
|
||||
MaxBatchSize: maxBatchSize, // optional
|
||||
MaxBatchInterval: time.Duration(interval), // optional
|
||||
})
|
||||
if err != nil || hook == nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// ignore fields
|
||||
hook.AddIgnore("private")
|
||||
log.AddHook(hook)
|
||||
}
|
||||
|
|
2
vendor/github.com/containous/traefik-extra-service-fabric/servicefabric_config.go
generated
vendored
2
vendor/github.com/containous/traefik-extra-service-fabric/servicefabric_config.go
generated
vendored
|
@ -76,7 +76,7 @@ func getDefaultEndpoint(instance replicaInstance) string {
|
|||
id, data := instance.GetReplicaData()
|
||||
endpoint, err := getReplicaDefaultEndpoint(data)
|
||||
if err != nil {
|
||||
log.Warnf("No default endpoint for replica %s in service %s endpointData: %s", id, data.Address)
|
||||
log.Warnf("No default endpoint for replica %s in service %s endpointData: %s", id, data.Address, err)
|
||||
return ""
|
||||
}
|
||||
return endpoint
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue