Skip to content

Commit

Permalink
feat: protocol flags and env variables added
Browse files Browse the repository at this point in the history
  • Loading branch information
tolgaOzen committed Aug 24, 2024
1 parent 27755ff commit 5fe01aa
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 5 deletions.
7 changes: 5 additions & 2 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,17 +298,20 @@ func DefaultConfig() *Config {
Enabled: false,
Exporter: "otlp",
Headers: []string{},
Protocol: "http",
},
Tracer: Tracer{
Enabled: false,
Headers: []string{},
Enabled: false,
Headers: []string{},
Protocol: "http",
},
Meter: Meter{
Enabled: false,
Exporter: "otlp",
Endpoint: "telemetry.permify.co",
Headers: []string{},
Interval: 300,
Protocol: "http",
},
Service: Service{
CircuitBreaker: false,
Expand Down
7 changes: 7 additions & 0 deletions pkg/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func NewConfigCommand() *cobra.Command {
f.Bool("log-insecure", conf.Log.Insecure, "use https or http for logs")
f.String("log-urlpath", conf.Log.URLPath, "allow to set url path for otlp exporter")
f.StringSlice("log-headers", conf.Log.Headers, "allows setting custom headers for the log exporter in key-value pairs")
f.String("log-protocol", conf.Log.Protocol, "allows setting the communication protocol for the log exporter, with options http or grpc")
f.Bool("authn-enabled", conf.Authn.Enabled, "enable server authentication")
f.String("authn-method", conf.Authn.Method, "server authentication method")
f.StringSlice("authn-preshared-keys", conf.Authn.Preshared.Keys, "preshared key/keys for server authentication")
Expand All @@ -65,13 +66,15 @@ func NewConfigCommand() *cobra.Command {
f.Bool("tracer-insecure", conf.Tracer.Insecure, "use https or http for tracer data, only used for otlp exporter or signoz")
f.String("tracer-urlpath", conf.Tracer.URLPath, "allow to set url path for otlp exporter")
f.StringSlice("tracer-headers", conf.Tracer.Headers, "allows setting custom headers for the tracer exporter in key-value pairs")
f.String("tracer-protocol", conf.Tracer.Protocol, "allows setting the communication protocol for the tracer exporter, with options http or grpc")
f.Bool("meter-enabled", conf.Meter.Enabled, "switch option for metric")
f.String("meter-exporter", conf.Meter.Exporter, "can be; otlp. (integrated metric tools)")
f.String("meter-endpoint", conf.Meter.Endpoint, "export uri for metric data")
f.Bool("meter-insecure", conf.Meter.Insecure, "use https or http for metric data")
f.String("meter-urlpath", conf.Meter.URLPath, "allow to set url path for otlp exporter")
f.StringSlice("meter-headers", conf.Meter.Headers, "allows setting custom headers for the metric exporter in key-value pairs")
f.Int("meter-interval", conf.Meter.Interval, "allows to set metrics to be pushed in certain time interval")
f.String("meter-protocol", conf.Meter.Protocol, "allows setting the communication protocol for the meter exporter, with options http or grpc")
f.Bool("service-circuit-breaker", conf.Service.CircuitBreaker, "switch option for service circuit breaker")
f.Bool("service-watch-enabled", conf.Service.Watch.Enabled, "switch option for watch service")
f.Int64("service-schema-cache-number-of-counters", conf.Service.Schema.Cache.NumberOfCounters, "schema service cache number of counters")
Expand Down Expand Up @@ -161,6 +164,7 @@ func conf() func(cmd *cobra.Command, args []string) error {
[]string{"logger.insecure", fmt.Sprintf("%v", cfg.Log.Insecure), getKeyOrigin(cmd, "log-insecure", "PERMIFY_LOG_INSECURE")},
[]string{"logger.urlpath", cfg.Log.URLPath, getKeyOrigin(cmd, "log-urlpath", "PERMIFY_LOG_URL_PATH")},
[]string{"logger.headers", fmt.Sprintf("%v", cfg.Log.Headers), getKeyOrigin(cmd, "log-headers", "PERMIFY_LOG_HEADERS")},
[]string{"logger.protocol", cfg.Log.Protocol, getKeyOrigin(cmd, "log-protocol", "PERMIFY_LOG_PROTOCOL")},
// AUTHN
[]string{"authn.enabled", fmt.Sprintf("%v", cfg.Authn.Enabled), getKeyOrigin(cmd, "authn-enabled", "PERMIFY_AUTHN_ENABLED")},
[]string{"authn.method", cfg.Authn.Method, getKeyOrigin(cmd, "authn-method", "PERMIFY_AUTHN_METHOD")},
Expand All @@ -179,13 +183,16 @@ func conf() func(cmd *cobra.Command, args []string) error {
[]string{"tracer.insecure", fmt.Sprintf("%v", cfg.Tracer.Insecure), getKeyOrigin(cmd, "tracer-insecure", "PERMIFY_TRACER_INSECURE")},
[]string{"tracer.urlpath", cfg.Tracer.URLPath, getKeyOrigin(cmd, "tracer-urlpath", "PERMIFY_TRACER_URL_PATH")},
[]string{"tracer.headers", fmt.Sprintf("%v", cfg.Tracer.Headers), getKeyOrigin(cmd, "tracer-headers", "PERMIFY_TRACER_HEADERS")},
[]string{"tracer.protocol", cfg.Tracer.Protocol, getKeyOrigin(cmd, "tracer-protocol", "PERMIFY_TRACER_PROTOCOL")},
// METER
[]string{"meter.enabled", fmt.Sprintf("%v", cfg.Meter.Enabled), getKeyOrigin(cmd, "meter-enabled", "PERMIFY_METER_ENABLED")},
[]string{"meter.exporter", cfg.Meter.Exporter, getKeyOrigin(cmd, "meter-exporter", "PERMIFY_METER_EXPORTER")},
[]string{"meter.endpoint", HideSecret(cfg.Meter.Exporter), getKeyOrigin(cmd, "meter-endpoint", "PERMIFY_METER_ENDPOINT")},
[]string{"meter.insecure", fmt.Sprintf("%v", cfg.Meter.Insecure), getKeyOrigin(cmd, "meter-insecure", "PERMIFY_METER_INSECURE")},
[]string{"meter.urlpath", cfg.Meter.URLPath, getKeyOrigin(cmd, "meter-urlpath", "PERMIFY_METER_URL_PATH")},
[]string{"meter.headers", fmt.Sprintf("%v", cfg.Meter.Headers), getKeyOrigin(cmd, "meter-headers", "PERMIFY_METER_HEADERS")},
[]string{"meter.protocol", cfg.Meter.Protocol, getKeyOrigin(cmd, "meter-protocol", "PERMIFY_METER_PROTOCOL")},
[]string{"meter.interval", fmt.Sprintf("%v", cfg.Meter.Interval), getKeyOrigin(cmd, "meter-interval", "PERMIFY_METER_INTERVAL")},
// SERVICE
[]string{"service.circuit_breaker", fmt.Sprintf("%v", cfg.Service.CircuitBreaker), getKeyOrigin(cmd, "service-circuit-breaker", "PERMIFY_SERVICE_CIRCUIT_BREAKER")},
[]string{"service.schema.cache.number_of_counters", fmt.Sprintf("%v", cfg.Service.Schema.Cache.NumberOfCounters), getKeyOrigin(cmd, "service-schema-cache-number-of-counters", "PERMIFY_SERVICE_WATCH_ENABLED")},
Expand Down
28 changes: 28 additions & 0 deletions pkg/cmd/flags/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,13 @@ func RegisterServeFlags(flags *pflag.FlagSet) {
panic(err)
}

if err = viper.BindPFlag("logger.protocol", flags.Lookup("log-protocol")); err != nil {
panic(err)
}
if err = viper.BindEnv("logger.protocol", "PERMIFY_LOG_PROTOCOL"); err != nil {
panic(err)
}

// AUTHN
if err = viper.BindPFlag("authn.enabled", flags.Lookup("authn-enabled")); err != nil {
panic(err)
Expand Down Expand Up @@ -301,6 +308,13 @@ func RegisterServeFlags(flags *pflag.FlagSet) {
panic(err)
}

if err = viper.BindPFlag("tracer.protocol", flags.Lookup("tracer-protocol")); err != nil {
panic(err)
}
if err = viper.BindEnv("tracer.protocol", "PERMIFY_TRACER_PROTOCOL"); err != nil {
panic(err)
}

// METER
if err = viper.BindPFlag("meter.enabled", flags.Lookup("meter-enabled")); err != nil {
panic(err)
Expand Down Expand Up @@ -344,6 +358,20 @@ func RegisterServeFlags(flags *pflag.FlagSet) {
panic(err)
}

if err = viper.BindPFlag("meter.interval", flags.Lookup("meter-interval")); err != nil {
panic(err)
}
if err = viper.BindEnv("meter.interval", "PERMIFY_METER_INTERVAL"); err != nil {
panic(err)
}

if err = viper.BindPFlag("meter.protocol", flags.Lookup("meter-protocol")); err != nil {
panic(err)
}
if err = viper.BindEnv("meter.protocol", "PERMIFY_METER_PROTOCOL"); err != nil {
panic(err)
}

// SERVICE
if err = viper.BindPFlag("service.circuit_breaker", flags.Lookup("service-circuit-breaker")); err != nil {
panic(err)
Expand Down
4 changes: 4 additions & 0 deletions pkg/cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func NewServeCommand() *cobra.Command {
f.Bool("log-insecure", conf.Log.Insecure, "use https or http for logs")
f.String("log-urlpath", conf.Log.URLPath, "allow to set url path for otlp exporter")
f.StringSlice("log-headers", conf.Log.Headers, "allows setting custom headers for the log exporter in key-value pairs")
f.String("log-protocol", conf.Log.Protocol, "allows setting the communication protocol for the log exporter, with options http or grpc")
f.Bool("authn-enabled", conf.Authn.Enabled, "enable server authentication")
f.String("authn-method", conf.Authn.Method, "server authentication method")
f.StringSlice("authn-preshared-keys", conf.Authn.Preshared.Keys, "preshared key/keys for server authentication")
Expand All @@ -98,12 +99,15 @@ func NewServeCommand() *cobra.Command {
f.Bool("tracer-insecure", conf.Tracer.Insecure, "use https or http for tracer data, only used for otlp exporter or signoz")
f.String("tracer-urlpath", conf.Tracer.URLPath, "allow to set url path for otlp exporter")
f.StringSlice("tracer-headers", conf.Tracer.Headers, "allows setting custom headers for the tracer exporter in key-value pairs")
f.String("tracer-protocol", conf.Tracer.Protocol, "allows setting the communication protocol for the tracer exporter, with options http or grpc")
f.Bool("meter-enabled", conf.Meter.Enabled, "switch option for metric")
f.String("meter-exporter", conf.Meter.Exporter, "can be; otlp. (integrated metric tools)")
f.String("meter-endpoint", conf.Meter.Endpoint, "export uri for metric data")
f.Bool("meter-insecure", conf.Meter.Insecure, "use https or http for metric data")
f.String("meter-urlpath", conf.Meter.URLPath, "allow to set url path for otlp exporter")
f.StringSlice("meter-headers", conf.Meter.Headers, "allows setting custom headers for the metric exporter in key-value pairs")
f.Int("meter-interval", conf.Meter.Interval, "allows to set metrics to be pushed in certain time interval")
f.String("meter-protocol", conf.Meter.Protocol, "allows setting the communication protocol for the meter exporter, with options http or grpc")
f.Bool("service-circuit-breaker", conf.Service.CircuitBreaker, "switch option for service circuit breaker")
f.Bool("service-watch-enabled", conf.Service.Watch.Enabled, "switch option for watch service")
f.Int64("service-schema-cache-number-of-counters", conf.Service.Schema.Cache.NumberOfCounters, "schema service cache number of counters")
Expand Down
2 changes: 1 addition & 1 deletion pkg/telemetry/logexporters/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"fmt"

"github.com/agoda-com/opentelemetry-logs-go/exporters/otlp/otlplogs"
"github.com/agoda-com/opentelemetry-logs-go/exporters/otlp/otlplogs/otlplogshttp"
"github.com/agoda-com/opentelemetry-logs-go/exporters/otlp/otlplogs/otlplogsgrpc"
"github.com/agoda-com/opentelemetry-logs-go/exporters/otlp/otlplogs/otlplogshttp"
)

// NewOTLP - Creates new OTLP exporter based on protocol.
Expand Down
2 changes: 1 addition & 1 deletion pkg/telemetry/meterexporters/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"
"fmt"

"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp"
"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc"
"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp"
"go.opentelemetry.io/otel/sdk/metric"
"google.golang.org/grpc/credentials"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/telemetry/tracerexporters/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"
"fmt"

"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp"
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp"
"go.opentelemetry.io/otel/sdk/trace"
"google.golang.org/grpc/credentials"
)
Expand Down

0 comments on commit 5fe01aa

Please sign in to comment.