Skip to content

Commit

Permalink
Merge pull request #945 from filipenko-sennder/master
Browse files Browse the repository at this point in the history
feat(tracing): Add meter-insecure, meter-urlpath, tracer-url-path configuration option
  • Loading branch information
tolgaOzen committed Dec 19, 2023
2 parents f0888d3 + 6d0e01a commit ccd7e8d
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 10 deletions.
8 changes: 8 additions & 0 deletions docs/docs/reference/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ authorization when using Permify.
| ├── exporter
| ├── endpoint
| ├── enabled
| ├── insecure
| ├── urlpath
```

#### Glossary
Expand All @@ -304,6 +306,7 @@ authorization when using Permify.
| [x] | exporter | - | Tracer exporter, the options are `jaeger`, `otlp`, `signoz`, and `zipkin`. |
| [x] | endpoint | - | export uri for tracing data. |
| [ ] | enabled | false | switch option for tracing. |
| [ ] | urlpath | | allows one to override the default URL path for otlp, used for sending traces. If unset, default ("/v1/traces") will be used. |
| [ ] | insecure | false | Whether to use HTTP instead of HTTPs for exporting the traces. |

#### ENV
Expand All @@ -313,6 +316,7 @@ authorization when using Permify.
| tracer-enabled | PERMIFY_TRACER_ENABLED | boolean |
| tracer-exporter | PERMIFY_TRACER_EXPORTER | string |
| tracer-endpoint | PERMIFY_TRACER_ENDPOINT | string |
| tracer-urlpath | PERMIFY_TRACER_URL_PATH | string |
| tracer-insecure | PERMIFY_TRACER_INSECURE | boolean |

</p>
Expand All @@ -333,6 +337,8 @@ os, arch.
| ├── exporter
| ├── endpoint
| ├── enabled
| ├── insecure
| ├── urlpath
```

#### Glossary
Expand All @@ -350,6 +356,8 @@ os, arch.
| meter-enabled | PERMIFY_METER_ENABLED | boolean |
| meter-exporter | PERMIFY_METER_EXPORTER | string |
| meter-endpoint | PERMIFY_METER_ENDPOINT | string |
| meter-urlpath | PERMIFY_METER_URL_PATH | string |
| meter-insecure | PERMIFY_METER_INSECURE | boolean |

</p>
</details>
Expand Down
1 change: 1 addition & 0 deletions docs/docs/reference/tracing.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ tracer:
- ***endpoint***: export url for tracing data.
- ***disabled***: switch option for tracing.
- ***insecure***: configures the exporter to connect to the collcetor using HTTP instead of HTTPS. This configuration is relevant only for `signoz` and `otlp`.
- ***urlpath***: allows one to override the default URL path used for sending traces. If unset, default ("/v1/traces") will be used. This configuration is relevant only for `otlp`.

**Example YAML configuration file**

Expand Down
2 changes: 1 addition & 1 deletion example.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ service:
cache:
number_of_counters: 10_000
max_cost: 10MiB
relationship:
data:

# The database section specifies the database engine and connection settings,
# including the URI for the database, whether or not to auto-migrate the database,
Expand Down
3 changes: 3 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,16 @@ type (
Exporter string `mapstructure:"exporter"` // Exporter for tracing data
Endpoint string `mapstructure:"endpoint"` // Endpoint for the tracing exporter
Insecure bool `mapstructure:"insecure"` // Connect to the collector using the HTTP scheme, instead of HTTPS.
URLPath string `mapstructure:"path"` // Path for the tracing exporter, if not defined /v1/trace will be used
}

// Meter contains configuration for metrics collection and reporting.
Meter struct {
Enabled bool `mapstructure:"enabled"` // Whether metrics collection is enabled
Exporter string `mapstructure:"exporter"` // Exporter for metrics data
Endpoint string `mapstructure:"endpoint"` // Endpoint for the metrics exporter
Insecure bool `mapstructure:"insecure"` // Connect to the collector using the HTTP scheme, instead of HTTPS.
URLPath string `mapstructure:"path"` // Path for the metrics exporter, if not defined /v1/metrics will be used
}

// Service contains configuration for various service-level features.
Expand Down
31 changes: 31 additions & 0 deletions pkg/cmd/flags/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,21 @@ func RegisterServeFlags(cmd *cobra.Command) {
if err = viper.BindEnv("tracer.endpoint", "PERMIFY_TRACER_ENDPOINT"); err != nil {
panic(err)
}
flags.Bool("tracer-insecure", conf.Tracer.Insecure, "use https or http for tracer data, only used for otlp exporter or signoz")
if err = viper.BindPFlag("tracer.insecure", flags.Lookup("tracer-insecure")); err != nil {
panic(err)
}
if err = viper.BindEnv("tracer.insecure", "PERMIFY_TRACER_INSECURE"); err != nil {
panic(err)
}

flags.String("tracer-urlpath", conf.Tracer.URLPath, "allow to set url path for otlp exporter")
if err = viper.BindPFlag("tracer.urlpath", flags.Lookup("tracer-urlpath")); err != nil {
panic(err)
}
if err = viper.BindEnv("tracer.urlpath", "PERMIFY_TRACER_URL_PATH"); err != nil {
panic(err)
}

// METER
flags.Bool("meter-enabled", conf.Meter.Enabled, "switch option for metric")
Expand All @@ -237,6 +252,22 @@ func RegisterServeFlags(cmd *cobra.Command) {
panic(err)
}

flags.Bool("meter-insecure", conf.Meter.Insecure, "use https or http for metric data")
if err = viper.BindPFlag("meter.insecure", flags.Lookup("meter-insecure")); err != nil {
panic(err)
}
if err = viper.BindEnv("meter.insecure", "PERMIFY_METER_INSECURE"); err != nil {
panic(err)
}

flags.String("meter-urlpath", conf.Meter.URLPath, "allow to set url path for otlp exporter")
if err = viper.BindPFlag("meter.urlpath", flags.Lookup("meter-urlpath")); err != nil {
panic(err)
}
if err = viper.BindEnv("meter.urlpath", "PERMIFY_METER_URL_PATH"); err != nil {
panic(err)
}

// SERVICE
flags.Bool("service-circuit-breaker", conf.Service.CircuitBreaker, "switch option for service circuit breaker")
if err = viper.BindPFlag("service.circuit_breaker", flags.Lookup("service-circuit-breaker")); err != nil {
Expand Down
8 changes: 7 additions & 1 deletion pkg/cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ func serve() func(cmd *cobra.Command, args []string) error {
cfg.Tracer.Exporter,
cfg.Tracer.Endpoint,
cfg.Tracer.Insecure,
cfg.Tracer.URLPath,
)
if err != nil {
slog.Error(err.Error())
Expand Down Expand Up @@ -178,7 +179,12 @@ func serve() func(cmd *cobra.Command, args []string) error {
meter := telemetry.NewNoopMeter()
if cfg.Meter.Enabled {
var exporter metric.Exporter
exporter, err = meterexporters.ExporterFactory(cfg.Meter.Exporter, cfg.Meter.Endpoint)
exporter, err = meterexporters.ExporterFactory(
cfg.Meter.Exporter,
cfg.Meter.Endpoint,
cfg.Meter.Insecure,
cfg.Meter.URLPath,
)
if err != nil {
slog.Error(err.Error())
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/telemetry/meterexporters/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
)

// ExporterFactory - Create meter exporter according to given params
func ExporterFactory(name, endpoint string) (metric.Exporter, error) {
func ExporterFactory(name, endpoint string, insecure bool, urlpath string) (metric.Exporter, error) {
switch name {
case "otlp":
return NewOTLP(endpoint)
return NewOTLP(endpoint, insecure, urlpath)
default:
return nil, fmt.Errorf("%s meter exporter is unsupported", name)
}
Expand Down
17 changes: 14 additions & 3 deletions pkg/telemetry/meterexporters/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,24 @@ import (
)

// NewOTLP - Creates new OTLP exporter
func NewOTLP(endpoint string) (metric.Exporter, error) {
exporter, err := otlpmetrichttp.New(context.Background(),
func NewOTLP(endpoint string, insecure bool, urlpath string) (metric.Exporter, error) {
options := []otlpmetrichttp.Option{
otlpmetrichttp.WithCompression(otlpmetrichttp.GzipCompression),
otlpmetrichttp.WithEndpoint(endpoint),
)
}

if urlpath != "" {
options = append(options, otlpmetrichttp.WithURLPath(urlpath))
}

if insecure {
options = append(options, otlpmetrichttp.WithInsecure())
}

exporter, err := otlpmetrichttp.New(context.Background(), options...)
if err != nil {
return nil, err
}

return exporter, nil
}
4 changes: 2 additions & 2 deletions pkg/telemetry/tracerexporters/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import (
)

// ExporterFactory - Create tracer exporter according to given params
func ExporterFactory(name, url string, insecure bool) (trace.SpanExporter, error) {
func ExporterFactory(name, url string, insecure bool, urlpath string) (trace.SpanExporter, error) {
switch name {
case "zipkin":
return NewZipkin(url)
case "jaeger":
return NewJaegar(url)
case "otlp":
return NewOTLP(url, insecure)
return NewOTLP(url, insecure, urlpath)
case "signoz":
return NewSigNoz(url, insecure)
default:
Expand Down
6 changes: 5 additions & 1 deletion pkg/telemetry/tracerexporters/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ import (
)

// NewOTLP - Creates new OTLP exporter
func NewOTLP(endpoint string, insecure bool) (trace.SpanExporter, error) {
func NewOTLP(endpoint string, insecure bool, urlpath string) (trace.SpanExporter, error) {
var exporter trace.SpanExporter
var err error

opts := []otlptracehttp.Option{
otlptracehttp.WithEndpoint(endpoint),
}

if urlpath != "" {
opts = append(opts, otlptracehttp.WithURLPath(urlpath))
}

if insecure {
opts = append(opts, otlptracehttp.WithInsecure())
}
Expand Down

0 comments on commit ccd7e8d

Please sign in to comment.