mirror of
https://github.com/hanzoai/gateway.git
synced 2026-10-30 15:04:44 +00:00
Modules declare go 1.27.1 and the build images follow. go fix applied the modernizers; omitzero is not applied, since it changes what the JSON says. Co-authored-by: Hanzo Dev <[email protected]>
38 lines
1.0 KiB
Go
38 lines
1.0 KiB
Go
package influxdb
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"time"
|
|
|
|
opencensus "github.com/hanzoai/gateway/v2/internal/plugin/opencensus"
|
|
"github.com/kpacha/opencensus-influxdb"
|
|
)
|
|
|
|
func init() {
|
|
opencensus.RegisterExporterFactories(func(ctx context.Context, cfg opencensus.Config) (any, error) {
|
|
return Exporter(ctx, cfg)
|
|
})
|
|
}
|
|
|
|
func Exporter(ctx context.Context, cfg opencensus.Config) (*influxdb.Exporter, error) {
|
|
if cfg.Exporters.InfluxDB == nil {
|
|
return nil, errDisabled
|
|
}
|
|
timeout, err := time.ParseDuration(cfg.Exporters.InfluxDB.Timeout)
|
|
if err != nil {
|
|
timeout = 0
|
|
}
|
|
return influxdb.NewExporter(ctx, influxdb.Options{
|
|
Address: cfg.Exporters.InfluxDB.Address,
|
|
Username: cfg.Exporters.InfluxDB.Username,
|
|
Password: cfg.Exporters.InfluxDB.Password,
|
|
Database: cfg.Exporters.InfluxDB.Database,
|
|
Timeout: timeout,
|
|
InstanceName: cfg.Exporters.InfluxDB.InstanceName,
|
|
ReportingPeriod: time.Duration(cfg.ReportingPeriod) * time.Second,
|
|
})
|
|
}
|
|
|
|
var errDisabled = errors.New("opencensus influxdb exporter disabled")
|