-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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 unit test for OTLP receiver in jaeger-v1 #6541
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6541 +/- ##
==========================================
- Coverage 96.05% 96.01% -0.05%
==========================================
Files 364 364
Lines 20750 20752 +2
==========================================
- Hits 19932 19924 -8
- Misses 622 631 +9
- Partials 196 197 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
dependent PR was merged |
Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com>
Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com>
Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com>
Signed-off-by: Yuri Shkuro <yurishkuro@users.noreply.github.com>
Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com>
…into e2e-otlp Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com>
Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com>
Signed-off-by: Yuri Shkuro <yurishkuro@users.noreply.github.com>
…into e2e-otlp Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com>
Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com>
Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com>
ScopeSpans().At(0). | ||
Spans().At(0) | ||
receivedTenant := tenancy.GetTenant(*storedCtx) | ||
return receivedSpan.Name() == span.Name() && receivedTenant == "test-tenant" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so for HTTP we cannot validate the tenant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enabling tenancy starts to fail the test because the tenant information doesnt get passed to the context from http header , even for the default header it doesnt work .
Line 16 in b689a86
func ExtractTenantHTTPHandler(tc *Manager, h http.Handler) http.Handler { |
Should this be used as middleware somewhere to populate the context ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Take a look at OTEL's config/confighttp/clientinfohandler. It looks like it stores the headers in the context and you can retrieve it via
info := client.FromContext(ctx)
// info.Metadata['x-tenant'] should contain the tenant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, a couple of questions
…into e2e-otlp Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com>
Signed-off-by: chahat sagar <109112505+chahatsagarmain@users.noreply.github.com>
var receivedTraces atomic.Pointer[ptrace.Traces] | ||
var receivedCtx atomic.Pointer[context.Context] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you cannot share state between tests like this, it creates side effects. HTTP and gRPC should be tested in complete isolation.
Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com>
) | ||
require.NoError(t, err) | ||
ctx := context.Background() | ||
defer rec.Shutdown(ctx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from L852 you are repeating a lot of code for each test. You can create a helper function that will initialize the receiver (it can be a lambda function).
receivedTraces.Store(&storeTrace) | ||
receivedCtx.Store(&storeContext) | ||
}).Return(nil) | ||
// Can't send tenancy headers with http request to OTLP receiver |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
old comment
|
||
func TestOTLPReceiverWithV2Storage(t *testing.T) { | ||
// Send trace via HTTP | ||
t.Run("Send trace data using HTTP connection", func(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there are multiple ways to organize the tests, yours makes the least sense to me.
Option 1: two top-level functions, with shared helper functions
Option 2: a single test function with table-driven tests, no setup helpers needed but each test has a lambda function parameter executeRequest
implemented with two other functions, for http and grpc separately
Your test is only checking success path, does not check scenario when incoming tenant is invalid.
Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com>
tenants := httpMd.Metadata.Get(c.tenancyMgr.Header) | ||
|
||
if len(tenants) > 0 { | ||
if !c.tenancyMgr.Valid(tenants[0]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want to duplicate validation. You are missing other checks like the one that causes return "", status.Errorf(codes.PermissionDenied, "missing tenant header")
This function needs to be constructed of two parts, one is extracting the tenant info, another is validation.
And I would prefer to consolidate all this in pkg/tenancy/getValidTenant (which can be made public). It's a kind of a mess there too. We have four possible sources of tenant:
- it may already be in the Context
- it may be in the HTTP request headers
- it may be in gRPC request headers, which are accessible via Context via
metadata
- finally, it may be in the Context as OTEL's
client.Metadata
Which problem is this PR solving?
Description of the changes
How was this change tested?
Checklist
jaeger
:make lint test
jaeger-ui
:npm run lint
andnpm run test