From cd9d4c40d6abb2b6569f4410dafc9792e0c9a0df Mon Sep 17 00:00:00 2001 From: Nikita Volodin Date: Wed, 6 Mar 2024 01:14:37 -0500 Subject: [PATCH] wip: log as trace tags instead of logs --- .../pkg/envoyfilter/config.go | 2 +- .../pkg/envoyfilter/filter.go | 34 +++++++++++++++++-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/privacy-profile-composer/pkg/envoyfilter/config.go b/privacy-profile-composer/pkg/envoyfilter/config.go index 80dea8fa..0b34430a 100644 --- a/privacy-profile-composer/pkg/envoyfilter/config.go +++ b/privacy-profile-composer/pkg/envoyfilter/config.go @@ -89,7 +89,7 @@ func (p *ConfigParser) Parse(any *anypb.Any, callbacks api.ConfigCallbackHandler if internalCidrsExist, ok := configStruct["internal_cidrs"]; !ok { return nil, fmt.Errorf("missing internal_cidrs") } else if internalCidrs, ok := internalCidrsExist.([]string); !ok { - return nil, fmt.Errorf("internal_cidrs: expect a list of strings while got %T", internalCidrs) + return nil, fmt.Errorf("internal_cidrs: expect a list of strings while got %T", internalCidrsExist) } else { parsedCidrs, err := parseCIDRs(internalCidrs) if err != nil { diff --git a/privacy-profile-composer/pkg/envoyfilter/filter.go b/privacy-profile-composer/pkg/envoyfilter/filter.go index 7eec84b8..668c15b8 100644 --- a/privacy-profile-composer/pkg/envoyfilter/filter.go +++ b/privacy-profile-composer/pkg/envoyfilter/filter.go @@ -3,6 +3,7 @@ package envoyfilter import ( "bytes" "context" + "encoding/json" "fmt" "log" "net" @@ -67,8 +68,29 @@ func (f *Filter) DecodeHeaders(header api.RequestHeaderMap, endStream bool) api. span := f.tracer.StartSpan("test span in decode headers", zipkin.Parent(f.parentSpanContext)) defer span.Finish() + span.Tag("opa-enforce", fmt.Sprint(f.config.opaEnforce)) + span.Tag("sidecar-direction", fmt.Sprint(f.config.direction)) + f.headerMetadata = common.ExtractHeaderData(header) + span.Tag("method", f.headerMetadata.Method) + span.Tag("host", f.headerMetadata.Host) + span.Tag("path", f.headerMetadata.Path) + span.Tag("svc-name", f.headerMetadata.SvcName) + span.Tag("purpose", f.headerMetadata.Purpose) + if f.headerMetadata.EnvoyPeerMetadata != nil { + encoded, err := json.Marshal(f.headerMetadata.EnvoyPeerMetadata) + if err != nil { + span.Tag("envoy-peer-metadata-error", fmt.Sprint(err)) + } else { + span.Tag("envoy-peer-metadata", string(encoded)) + } + } + + // TODO: should these two be added to `f.headerMetadata`? + span.Tag("protocol", header.Protocol()) + span.Tag("scheme", header.Scheme()) + // TODO: Insert it into OpenTelemetry baggage for tracing? header.Add("x-prose-purpose", f.headerMetadata.Purpose) // For OPA @@ -90,16 +112,22 @@ func (f *Filter) DecodeHeaders(header api.RequestHeaderMap, endStream bool) api. // and only process the body in this case destinationAddress, err := f.callbacks.GetProperty("destination.address") if err != nil { - log.Println(err) + span.Tag("error", "true") + span.Tag("error-msg", fmt.Sprint(err)) return api.Continue } + span.Tag("destination-address", destinationAddress) + isInternalDestination, err := f.checkInternalAddress(destinationAddress) if err != nil { - log.Println(err) + span.Tag("error", "true") + span.Tag("error-msg", fmt.Sprint(err)) return api.Continue } + span.Tag("is-internal-destination", fmt.Sprint(isInternalDestination)) + if isInternalDestination { log.Printf("outbound sidecar processed a request to another sidecar in the mesh" + "Prose will process it through the inbound decode function\n") @@ -114,6 +142,8 @@ func (f *Filter) DecodeHeaders(header api.RequestHeaderMap, endStream bool) api. return api.Continue } + span.Tag("process-decode-body", fmt.Sprint(f.processDecodeBody)) + return api.StopAndBuffer }