Skip to content

Commit

Permalink
feat: adding odigossamplingprocessor
Browse files Browse the repository at this point in the history
  • Loading branch information
Tamir David authored and Tamir David committed Jun 26, 2024
1 parent dff6b76 commit 9101a84
Show file tree
Hide file tree
Showing 11 changed files with 926 additions and 0 deletions.
1 change: 1 addition & 0 deletions collector/processors/odigossamplingprocessor/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../Makefile.Common
36 changes: 36 additions & 0 deletions collector/processors/odigossamplingprocessor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Odigos Sampling processor

This processor samples traces based on the following supported rules:

1. HTTP Latency Rule: This rule allows you to configure service, endpoint, and threshold. Traces with a duration less than the specified threshold will be deleted.


``` yaml
groupbytrace:
wait_duration: 10s
odigossampling:
rules:
- name: "http-latency-test"
type: "http_latency"
rule_details:
"threshold": 1050
"endpoint": "/buy"
"service": "frontend"
```
- threshold: The maximum allowable trace duration in milliseconds. Traces with a duration less than this value will be deleted.
- endpoint: The specific HTTP route to match for sampling. Only traces with this route will be considered.
- service: The name of the service for which the rule applies. Only traces from this service will be considered.


**Notes:**
- When using the `odigossampling` processor, it is mandatory to use the `groupbytrace` processor beforehand.
```
service:
pipelines:
traces:
receivers:
processors:
- groupbytrace
- odigossampling
exporters:
```
59 changes: 59 additions & 0 deletions collector/processors/odigossamplingprocessor/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package odigossamplingprocessor

import (
"errors"
"fmt"

"github.com/mitchellh/mapstructure"
"github.com/open-telemetry/opentelemetry-collector-contrib/odigos/processor/odigossamplingprocessor/internal/sampling"
"go.opentelemetry.io/collector/component"
)

type Config struct {
Rules []Rule `mapstructure:"rules"`
}

var _ component.Config = (*Config)(nil)

func (cfg *Config) Validate() error {
for _, rule := range cfg.Rules {
if err := rule.Validate(); err != nil {
return err
}
}
return nil
}

type Rule struct {
Name string `mapstructure:"name"`
Type string `mapstructure:"type"`
RuleDetails interface{} `mapstructure:"rule_details"`
}

func (r *Rule) Validate() error {
if r.Name == "" {
return errors.New("rule name cannot be empty")
}
if r.Type == "" {
return errors.New("rule type cannot be empty")
}
if r.RuleDetails == nil {
return errors.New("rule details cannot be nil")
}

switch r.Type {
case "http_latency":
var details sampling.TraceLatencyRule
if err := mapstructure.Decode(r.RuleDetails, &details); err != nil {
return err
}
if err := details.Validate(); err != nil {
return err
}
r.RuleDetails = &details
default:
return fmt.Errorf("unknown rule type: %s", r.Type)
}

return nil
}
43 changes: 43 additions & 0 deletions collector/processors/odigossamplingprocessor/factory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package odigossamplingprocessor

import (
"context"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/processor"
"go.opentelemetry.io/collector/processor/processorhelper"
)

// NewFactory returns a new factory for the Resource processor.
func NewFactory() processor.Factory {
return processor.NewFactory(
component.MustNewType("odigossampling"),
createDefaultConfig,
processor.WithTraces(createTracesProcessor, component.StabilityLevelBeta),
)
}

func createDefaultConfig() component.Config {
return &Config{
Rules: []Rule{},
}
}

func createTracesProcessor(
ctx context.Context,
set processor.CreateSettings,
cfg component.Config,
nextConsumer consumer.Traces) (processor.Traces, error) {

proc := &samplingProcessor{logger: set.Logger, config: cfg.(*Config)}

return processorhelper.NewTracesProcessor(
ctx,
set,
cfg,
nextConsumer,
proc.processTraces,
processorhelper.WithCapabilities(consumer.Capabilities{MutatesData: true}),
)
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions collector/processors/odigossamplingprocessor/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
module github.com/open-telemetry/opentelemetry-collector-contrib/odigos/processor/odigossamplingprocessor

go 1.20

require (
github.com/mitchellh/mapstructure v1.5.1-0.20231216201459-8508981c8b6c
github.com/stretchr/testify v1.8.4
go.opentelemetry.io/collector/component v0.94.0
go.opentelemetry.io/collector/confmap v0.94.0
go.opentelemetry.io/collector/consumer v0.94.0
go.opentelemetry.io/collector/pdata v1.1.0
go.opentelemetry.io/collector/processor v0.94.0
go.opentelemetry.io/otel/metric v1.23.0
go.opentelemetry.io/otel/trace v1.23.0
go.uber.org/zap v1.26.0
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/knadh/koanf v1.5.0 // indirect
github.com/knadh/koanf/v2 v2.0.2 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.18.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.46.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
go.opentelemetry.io/collector v0.94.0 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.94.0 // indirect
go.opentelemetry.io/otel v1.23.0 // indirect
go.opentelemetry.io/otel/exporters/prometheus v0.45.1 // indirect
go.opentelemetry.io/otel/sdk v1.23.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.23.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240102182953-50ed04b92917 // indirect
google.golang.org/grpc v1.61.0 // indirect
google.golang.org/protobuf v1.32.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 9101a84

Please sign in to comment.