-
Notifications
You must be signed in to change notification settings - Fork 46
Route harvester timeout #621
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
Merged
grcevski
merged 7 commits into
open-telemetry:main
from
grcevski:route_harvester_timeout
Sep 16, 2025
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
76032aa
add timeout for route harvester to avoid blocking the pipeline comple…
grcevski 045f2dc
add unit test
grcevski 16b045b
unit tests
grcevski 8773d1c
Merge branch 'main' into route_harvester_timeout
grcevski cecce9c
fix merge and test
grcevski b125d3a
Merge branch 'main' into route_harvester_timeout
grcevski 6117236
apply review feedback
grcevski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
200 changes: 200 additions & 0 deletions
200
pkg/components/transform/route/harvest/harvester_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,200 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package harvest | ||
|
|
||
| import ( | ||
| "errors" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "go.opentelemetry.io/obi/pkg/components/exec" | ||
| "go.opentelemetry.io/obi/pkg/components/svc" | ||
| ) | ||
|
|
||
| // successfulExtractRoutes simulates a successful route extraction | ||
| func successfulExtractRoutes(_ int32) (*RouteHarvesterResult, error) { | ||
grcevski marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return &RouteHarvesterResult{ | ||
| Routes: []string{"/api/users", "/api/orders"}, | ||
| Kind: CompleteRoutes, | ||
| }, nil | ||
| } | ||
|
|
||
| // errorExtractRoutes simulates an error during route extraction | ||
| func errorExtractRoutes(_ int32) (*RouteHarvesterResult, error) { | ||
| return nil, errors.New("failed to connect to Java process") | ||
| } | ||
|
|
||
| // timeoutExtractRoutes simulates a slow operation that will timeout | ||
| func timeoutExtractRoutes(_ int32) (*RouteHarvesterResult, error) { | ||
| // Sleep longer than any reasonable timeout | ||
| time.Sleep(5 * time.Second) | ||
| return &RouteHarvesterResult{ | ||
| Routes: []string{"/api/delayed"}, | ||
| Kind: CompleteRoutes, | ||
| }, nil | ||
| } | ||
|
|
||
| // panicExtractRoutes simulates a panic during route extraction | ||
| func panicExtractRoutes(_ int32) (*RouteHarvesterResult, error) { | ||
| panic("unexpected error in java route extraction") | ||
| } | ||
|
|
||
| // slowButSuccessfulExtractRoutes simulates a slow but successful operation | ||
| func slowButSuccessfulExtractRoutes(_ int32) (*RouteHarvesterResult, error) { | ||
| time.Sleep(50 * time.Millisecond) // Slow but within timeout | ||
| return &RouteHarvesterResult{ | ||
| Routes: []string{"/api/slow"}, | ||
| Kind: PartialRoutes, | ||
| }, nil | ||
| } | ||
|
|
||
| // emptyResultExtractRoutes simulates successful extraction with no routes | ||
| func emptyResultExtractRoutes(_ int32) (*RouteHarvesterResult, error) { | ||
| return &RouteHarvesterResult{ | ||
| Routes: []string{}, | ||
| Kind: CompleteRoutes, | ||
| }, nil | ||
| } | ||
|
|
||
| func createTestFileInfo(language svc.InstrumentableType) *exec.FileInfo { | ||
| return &exec.FileInfo{ | ||
| Pid: 12345, | ||
| Service: svc.Attrs{ | ||
| SDKLanguage: language, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func TestHarvestRoutes_Successful(t *testing.T) { | ||
| harvester := NewRouteHarvester([]string{}, 1*time.Second) | ||
| harvester.javaExtractRoutes = successfulExtractRoutes | ||
|
|
||
| fileInfo := createTestFileInfo(svc.InstrumentableJava) | ||
|
|
||
| result, err := harvester.HarvestRoutes(fileInfo) | ||
|
|
||
| require.NoError(t, err) | ||
| require.NotNil(t, result) | ||
| assert.Equal(t, []string{"/api/users", "/api/orders"}, result.Routes) | ||
| assert.Equal(t, CompleteRoutes, result.Kind) | ||
| } | ||
|
|
||
| func TestHarvestRoutes_Error(t *testing.T) { | ||
| harvester := NewRouteHarvester([]string{}, 1*time.Second) | ||
| harvester.javaExtractRoutes = errorExtractRoutes | ||
|
|
||
| fileInfo := createTestFileInfo(svc.InstrumentableJava) | ||
|
|
||
| result, err := harvester.HarvestRoutes(fileInfo) | ||
|
|
||
| require.Error(t, err) | ||
| assert.Nil(t, result) | ||
| assert.Contains(t, err.Error(), "failed to connect to Java process") | ||
| } | ||
|
|
||
| func TestHarvestRoutes_Timeout(t *testing.T) { | ||
| harvester := NewRouteHarvester([]string{}, 100*time.Millisecond) // Short timeout | ||
| harvester.javaExtractRoutes = timeoutExtractRoutes | ||
|
|
||
| fileInfo := createTestFileInfo(svc.InstrumentableJava) | ||
|
|
||
| start := time.Now() | ||
| result, err := harvester.HarvestRoutes(fileInfo) | ||
| elapsed := time.Since(start) | ||
|
|
||
| require.Error(t, err) | ||
| assert.Nil(t, result) | ||
|
|
||
| // Check that it's a HarvestError with timeout message | ||
| var harvestErr *HarvestError | ||
| require.ErrorAs(t, err, &harvestErr) | ||
| assert.Equal(t, "route harvesting timed out", harvestErr.Message) | ||
|
|
||
| // Ensure it actually timed out quickly (within reasonable bounds) | ||
| assert.Less(t, elapsed, 200*time.Millisecond) | ||
| assert.Greater(t, elapsed, 90*time.Millisecond) | ||
| } | ||
|
|
||
| func TestHarvestRoutes_Panic(t *testing.T) { | ||
| harvester := NewRouteHarvester([]string{}, 1*time.Second) | ||
| harvester.javaExtractRoutes = panicExtractRoutes | ||
|
|
||
| fileInfo := createTestFileInfo(svc.InstrumentableJava) | ||
|
|
||
| result, err := harvester.HarvestRoutes(fileInfo) | ||
|
|
||
| require.Error(t, err) | ||
| assert.Nil(t, result) | ||
|
|
||
| // Check that panic was caught and converted to HarvestError | ||
| var harvestErr *HarvestError | ||
| require.ErrorAs(t, err, &harvestErr) | ||
| assert.Equal(t, "harvesting failed", harvestErr.Message) | ||
| } | ||
|
|
||
| func TestHarvestRoutes_SlowButSuccessful(t *testing.T) { | ||
| harvester := NewRouteHarvester([]string{}, 200*time.Millisecond) // Enough time for slow operation | ||
| harvester.javaExtractRoutes = slowButSuccessfulExtractRoutes | ||
|
|
||
| fileInfo := createTestFileInfo(svc.InstrumentableJava) | ||
|
|
||
| result, err := harvester.HarvestRoutes(fileInfo) | ||
|
|
||
| require.NoError(t, err) | ||
| require.NotNil(t, result) | ||
| assert.Equal(t, []string{"/api/slow"}, result.Routes) | ||
| assert.Equal(t, PartialRoutes, result.Kind) | ||
| } | ||
|
|
||
| func TestHarvestRoutes_EmptyResult(t *testing.T) { | ||
| harvester := NewRouteHarvester([]string{}, 1*time.Second) | ||
| harvester.javaExtractRoutes = emptyResultExtractRoutes | ||
|
|
||
| fileInfo := createTestFileInfo(svc.InstrumentableJava) | ||
|
|
||
| result, err := harvester.HarvestRoutes(fileInfo) | ||
|
|
||
| require.NoError(t, err) | ||
| require.NotNil(t, result) | ||
| assert.Empty(t, result.Routes) | ||
| assert.Equal(t, CompleteRoutes, result.Kind) | ||
| } | ||
|
|
||
| func TestHarvestRoutes_NonJavaLanguage(t *testing.T) { | ||
| harvester := NewRouteHarvester([]string{}, 1*time.Second) | ||
| // javaExtractRoutes should not be called for non-Java languages | ||
| harvester.javaExtractRoutes = func(_ int32) (*RouteHarvesterResult, error) { | ||
| t.Fatal("javaExtractRoutes should not be called for non-Java languages") | ||
| return nil, nil | ||
| } | ||
|
|
||
| fileInfo := createTestFileInfo(svc.InstrumentableGolang) | ||
|
|
||
| result, err := harvester.HarvestRoutes(fileInfo) | ||
|
|
||
| require.NoError(t, err) | ||
| assert.Nil(t, result) // Should return nil for non-Java languages | ||
| } | ||
|
|
||
| func TestHarvestRoutes_MultipleTimeouts(t *testing.T) { | ||
| harvester := NewRouteHarvester([]string{}, 50*time.Millisecond) | ||
| harvester.javaExtractRoutes = timeoutExtractRoutes | ||
|
|
||
| fileInfo := createTestFileInfo(svc.InstrumentableJava) | ||
|
|
||
| // Test multiple calls to ensure timeout behavior is consistent | ||
| for i := 0; i < 3; i++ { | ||
| result, err := harvester.HarvestRoutes(fileInfo) | ||
|
|
||
| require.Error(t, err, "iteration %d should timeout", i) | ||
| assert.Nil(t, result, "iteration %d should return nil result", i) | ||
|
|
||
| var harvestErr *HarvestError | ||
| require.ErrorAs(t, err, &harvestErr, "iteration %d should return HarvestError", i) | ||
| assert.Equal(t, "route harvesting timed out", harvestErr.Message, "iteration %d should have timeout message", i) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.