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 unit test for OTLP receiver in jaeger-v1 #6541

Open
wants to merge 26 commits into
base: main
Choose a base branch
from

Conversation

chahatsagarmain
Copy link
Contributor

Which problem is this PR solving?

Description of the changes

  • Added unit test

How was this change tested?

Checklist

Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com>
@chahatsagarmain chahatsagarmain requested a review from a team as a code owner January 13, 2025 19:51
@chahatsagarmain chahatsagarmain marked this pull request as draft January 13, 2025 19:51
Copy link

codecov bot commented Jan 13, 2025

Codecov Report

Attention: Patch coverage is 72.22222% with 10 lines in your changes missing coverage. Please review.

Project coverage is 96.01%. Comparing base (7168853) to head (1d7f157).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
pkg/tenancy/grpc.go 71.42% 9 Missing and 1 partial ⚠️
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     
Flag Coverage Δ
badger_v1 9.86% <0.00%> (-0.02%) ⬇️
badger_v2 1.83% <0.00%> (-0.01%) ⬇️
cassandra-4.x-v1-manual 15.00% <0.00%> (-0.03%) ⬇️
cassandra-4.x-v2-auto 1.82% <0.00%> (-0.01%) ⬇️
cassandra-4.x-v2-manual 1.82% <0.00%> (-0.01%) ⬇️
cassandra-5.x-v1-manual 15.00% <0.00%> (-0.03%) ⬇️
cassandra-5.x-v2-auto 1.82% <0.00%> (-0.01%) ⬇️
cassandra-5.x-v2-manual 1.82% <0.00%> (-0.01%) ⬇️
elasticsearch-6.x-v1 19.20% <0.00%> (-0.03%) ⬇️
elasticsearch-7.x-v1 19.28% <0.00%> (-0.03%) ⬇️
elasticsearch-8.x-v1 19.45% <0.00%> (-0.03%) ⬇️
elasticsearch-8.x-v2 1.83% <0.00%> (-0.01%) ⬇️
grpc_v1 11.16% <0.00%> (-0.02%) ⬇️
grpc_v2 8.03% <0.00%> (-0.02%) ⬇️
kafka-3.x-v1 10.16% <0.00%> (-0.02%) ⬇️
kafka-3.x-v2 1.83% <0.00%> (-0.01%) ⬇️
memory_v2 1.83% <0.00%> (-0.01%) ⬇️
opensearch-1.x-v1 19.33% <0.00%> (-0.03%) ⬇️
opensearch-2.x-v1 19.33% <0.00%> (-0.03%) ⬇️
opensearch-2.x-v2 1.83% <0.00%> (-0.01%) ⬇️
tailsampling-processor 0.48% <0.00%> (-0.01%) ⬇️
unittests 94.80% <72.22%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com>
@yurishkuro
Copy link
Member

dependent PR was merged

chahatsagarmain and others added 3 commits January 15, 2025 22:29
Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com>
Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com>
cmd/collector/app/span_processor_test.go Outdated Show resolved Hide resolved
cmd/collector/app/span_processor_test.go Outdated Show resolved Hide resolved
cmd/collector/app/span_processor_test.go Outdated Show resolved Hide resolved
Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com>
@yurishkuro yurishkuro added the changelog:test Change that's adding missing tests or correcting existing tests label Jan 18, 2025
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>
@chahatsagarmain chahatsagarmain marked this pull request as ready for review January 18, 2025 21:44
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"
Copy link
Member

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?

Copy link
Contributor Author

@chahatsagarmain chahatsagarmain Jan 22, 2025

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 .

func ExtractTenantHTTPHandler(tc *Manager, h http.Handler) http.Handler {

Should this be used as middleware somewhere to populate the context ?

Copy link
Member

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

Copy link
Member

@yurishkuro yurishkuro left a 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

@yurishkuro yurishkuro changed the title [test][WIP] Unit test for OTLP receiver in jaeger-v1 Add unit test for OTLP receiver in jaeger-v1 Jan 21, 2025
@yurishkuro yurishkuro added changelog:test Change that's adding missing tests or correcting existing tests and removed changelog:test Change that's adding missing tests or correcting existing tests labels Jan 21, 2025
Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com>
chahatsagarmain and others added 6 commits January 24, 2025 03:24
Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com>
Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com>
…into e2e-otlp

Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com>
Signed-off-by: chahat sagar <109112505+chahatsagarmain@users.noreply.github.com>
Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com>
Comment on lines 853 to 854
var receivedTraces atomic.Pointer[ptrace.Traces]
var receivedCtx atomic.Pointer[context.Context]
Copy link
Member

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)
Copy link
Member

@yurishkuro yurishkuro Jan 26, 2025

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

old comment

cmd/collector/app/handler/grpc_handler.go Outdated Show resolved Hide resolved

func TestOTLPReceiverWithV2Storage(t *testing.T) {
// Send trace via HTTP
t.Run("Send trace data using HTTP connection", func(t *testing.T) {
Copy link
Member

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]) {
Copy link
Member

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

Signed-off-by: chahatsagarmain <chahatsagar2003@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:test Change that's adding missing tests or correcting existing tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add e2e unit test for OTLP receiver in jaeger-v1
2 participants