Skip to content

Commit

Permalink
wip: delay sidecar direction determination
Browse files Browse the repository at this point in the history
  • Loading branch information
qlonik committed Feb 29, 2024
1 parent b3ea61e commit e9c4f2f
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions privacy-profile-composer/pkg/envoyfilter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ import (
)

func NewFilter(callbacks api.FilterCallbackHandler, config *config) (api.StreamFilter, error) {
sidecarDirection, err := common.GetDirection(callbacks)
if err != nil {
return nil, err
}

tracer, err := common.NewZipkinTracer(config.zipkinUrl)
if err != nil {
return nil, fmt.Errorf("unable to create tracer: %+v\n", err)
Expand All @@ -38,24 +33,23 @@ func NewFilter(callbacks api.FilterCallbackHandler, config *config) (api.StreamF
}

return &Filter{
callbacks: callbacks,
config: config,
tracer: tracer,
sidecarDirection: sidecarDirection,
opa: opaObj,
callbacks: callbacks,
config: config,
tracer: tracer,
opa: opaObj,
}, nil
}

type Filter struct {
api.PassThroughStreamFilter

callbacks api.FilterCallbackHandler
config *config
tracer *common.ZipkinTracer
opa *sdk.OPA
sidecarDirection common.SidecarDirection
callbacks api.FilterCallbackHandler
config *config
tracer *common.ZipkinTracer
opa *sdk.OPA

// Runtime state of the filter
sidecarDirection common.SidecarDirection
parentSpanContext model.SpanContext
headerMetadata common.HeaderMetadata
}
Expand All @@ -64,6 +58,22 @@ type Filter struct {
func (f *Filter) DecodeHeaders(header api.RequestHeaderMap, endStream bool) api.StatusType {
log.Println(">>> DECODE HEADERS")

log.Println("get property xds.node")
v, err := f.callbacks.GetProperty("xds.node")
if err != nil {
log.Printf("error getting key: %v\n", err)
} else {
log.Printf("%+v\n", v)
}

sidecarDirection, err := common.GetDirection(f.callbacks)
if err != nil {
log.Println(err)
} else {
log.Printf("determined sidecar direction: \"%s\"\n", sidecarDirection)
}
f.sidecarDirection = sidecarDirection

f.parentSpanContext = f.tracer.Extract(header)

span := f.tracer.StartSpan("test span in decode headers", zipkin.Parent(f.parentSpanContext))
Expand Down

0 comments on commit e9c4f2f

Please sign in to comment.