Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more tags to the admissionControl span to increase visibility #3318

Open
wants to merge 2 commits into
base: refactorMockTracer
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions filters/shedder/admission.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,13 @@ func sum(a []int64) int64 {
return result
}

func (ac *admissionControl) setCommonTags(span opentracing.Span) {
span.SetTag("admissionControl.group", ac.metricSuffix)
span.SetTag("admissionControl.mode", ac.mode.String())
span.SetTag("admissionControl.d", ac.d.String())
span.SetTag("admissionControl.windowSize", ac.windowSize)
}

// calculates P_{reject} see https://opensource.zalando.com/skipper/reference/filters/#admissioncontrol
func (ac *admissionControl) pReject() float64 {
var rejectP float64
Expand Down Expand Up @@ -412,6 +419,8 @@ func (ac *admissionControl) shouldReject() bool {
func (ac *admissionControl) Request(ctx filters.FilterContext) {
span := ac.startSpan(ctx.Request().Context())
defer span.Finish()

ac.setCommonTags(span)
ac.metrics.IncCounter(counterPrefix + "total." + ac.metricSuffix)

if ac.shouldReject() {
Expand Down
90 changes: 90 additions & 0 deletions filters/shedder/admission_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/zalando/skipper/eskip"
"github.com/zalando/skipper/filters"
"github.com/zalando/skipper/filters/builtin"
"github.com/zalando/skipper/metrics"
"github.com/zalando/skipper/metrics/metricstest"
"github.com/zalando/skipper/net"
"github.com/zalando/skipper/proxy"
"github.com/zalando/skipper/proxy/proxytest"
"github.com/zalando/skipper/routing"
"github.com/zalando/skipper/routing/testdataclient"
"github.com/zalando/skipper/tracing/tracingtest"
"golang.org/x/time/rate"
)

Expand Down Expand Up @@ -594,6 +597,93 @@
}
}

func TestAdmissionControlSetsSpansTags(t *testing.T) {
tracer := tracingtest.NewMockTracer()

Check failure on line 601 in filters/shedder/admission_test.go

View workflow job for this annotation

GitHub Actions / check-race

undefined: tracingtest.NewMockTracer

backend := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
}))
defer backend.Close()

fspec := NewAdmissionControl(Options{Tracer: tracer})
spec, ok := fspec.(*AdmissionControlSpec)
if !ok {
t.Fatal("FilterSpec is not a AdmissionControlSpec")
}
preProcessor := spec.PreProcessor()
postProcessor := spec.PostProcessor()

args := make([]interface{}, 0, 6)
args = append(args, "testmetric", "active", "10ms", 5, 1, 0.1, 0.95, 0.5)
f, err := spec.CreateFilter(args)
if err != nil {
t.Fatalf("error creating filter: %v", err)
return
}
f.(*admissionControl).Close()

r := &eskip.Route{Filters: []*eskip.Filter{{Name: spec.Name(), Args: args}}, Backend: backend.URL}

fr := make(filters.Registry)
fr.Register(fspec)

dc := testdataclient.New([]*eskip.Route{r})
defer dc.Close()

proxy := proxytest.WithParamsAndRoutingOptions(fr,
proxy.Params{
OpenTracing: &proxy.OpenTracingParams{Tracer: tracer},
},
routing.Options{
DataClients: []routing.DataClient{dc},
PostProcessors: []routing.PostProcessor{postProcessor},
PreProcessors: []routing.PreProcessor{preProcessor},
})
defer proxy.Close()

client := proxy.Client()
req, err := http.NewRequest("GET", proxy.URL, nil)
if err != nil {
t.Error(err)
return
}

_, err = client.Do(req)
if err != nil {
t.Error(err)
}

acSpanFound := false
finishedSpans := tracer.FinishedSpans()
for _, span := range finishedSpans {
if span.OperationName == "admission_control" {
acSpanFound = true
tags := span.Tags()

d, found := tags["admissionControl.d"]
assert.True(t, found)
assert.Equal(t, "10ms", d)

windowSize, found := tags["admissionControl.windowSize"]
assert.True(t, found)
assert.Equal(t, 5, windowSize)

group, found := tags["admissionControl.group"]
assert.True(t, found)
assert.Equal(t, "testmetric", group)

mode, found := tags["admissionControl.mode"]
assert.True(t, found)
assert.Equal(t, "active", mode)

mode, found = tags["mode"]
assert.True(t, found)
assert.Equal(t, "active", mode)
}
}
assert.True(t, acSpanFound)
}

type validationPostProcessorNumberOfFilters struct {
ch chan []*routing.Route
}
Expand Down
Loading