-
Notifications
You must be signed in to change notification settings - Fork 77
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
feat: agent collector statistics report #3544
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e206a55
feat: count spans
mathnogueira 3940178
agent: implement grpc stream client
mathnogueira 1f820e8
agent: implement send otlp connection result
mathnogueira ddeaec3
feat: send collector statistics to server when requested
mathnogueira 1464a8d
test: check if collector statistics are precise
mathnogueira a799569
feat: reset statistics if flag is present
mathnogueira a82bda1
fix issue with datastore connection test and add tests
mathnogueira 470b58e
Merge branch 'main' of github.com:kubeshop/tracetest into feat/agent-…
mathnogueira 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 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 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
42 changes: 42 additions & 0 deletions
42
agent/client/workflow_listen_for_ds_connection_tests_test.go
This file contains 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,42 @@ | ||
package client_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/kubeshop/tracetest/agent/client" | ||
"github.com/kubeshop/tracetest/agent/client/mocks" | ||
"github.com/kubeshop/tracetest/agent/proto" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestDataStoreConnectionTestWorkflow(t *testing.T) { | ||
server := mocks.NewGrpcServer() | ||
defer server.Stop() | ||
|
||
client, err := client.Connect(context.Background(), server.Addr()) | ||
require.NoError(t, err) | ||
|
||
var receivedConnectionTestRequest *proto.DataStoreConnectionTestRequest | ||
client.OnDataStoreTestConnectionRequest(func(ctx context.Context, otr *proto.DataStoreConnectionTestRequest) error { | ||
receivedConnectionTestRequest = otr | ||
return nil | ||
}) | ||
|
||
err = client.Start(context.Background()) | ||
require.NoError(t, err) | ||
|
||
connectionTestRequest := &proto.DataStoreConnectionTestRequest{ | ||
RequestID: "request-id", | ||
} | ||
|
||
server.SendDataStoreConnectionTestRequest(connectionTestRequest) | ||
|
||
// ensures there's enough time for networking between server and client | ||
time.Sleep(1 * time.Second) | ||
|
||
assert.NotNil(t, receivedConnectionTestRequest) | ||
assert.Equal(t, connectionTestRequest.RequestID, "request-id") | ||
} |
This file contains 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,47 @@ | ||
package client | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"time" | ||
|
||
"github.com/kubeshop/tracetest/agent/proto" | ||
) | ||
|
||
func (c *Client) startOTLPConnectionTestListener(ctx context.Context) error { | ||
client := proto.NewOrchestratorClient(c.conn) | ||
|
||
stream, err := client.RegisterOTLPConnectionTestListener(ctx, c.sessionConfig.AgentIdentification) | ||
if err != nil { | ||
return fmt.Errorf("could not open agent stream: %w", err) | ||
} | ||
|
||
go func() { | ||
for { | ||
req := proto.OTLPConnectionTestRequest{} | ||
err := stream.RecvMsg(&req) | ||
if isEndOfFileError(err) || isCancelledError(err) { | ||
return | ||
} | ||
|
||
reconnected, err := c.handleDisconnectionError(err) | ||
if reconnected { | ||
return | ||
} | ||
|
||
if err != nil { | ||
log.Println("could not get message from otlp connection stream: %w", err) | ||
time.Sleep(1 * time.Second) | ||
continue | ||
} | ||
|
||
// TODO: Get ctx from request | ||
err = c.otlpConnectionTestListener(context.Background(), &req) | ||
if err != nil { | ||
fmt.Println(err.Error()) | ||
} | ||
} | ||
}() | ||
return nil | ||
} |
42 changes: 42 additions & 0 deletions
42
agent/client/workflow_listen_for_otlp_connection_tests_test.go
This file contains 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,42 @@ | ||
package client_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/kubeshop/tracetest/agent/client" | ||
"github.com/kubeshop/tracetest/agent/client/mocks" | ||
"github.com/kubeshop/tracetest/agent/proto" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestOtlpConnectionTestWorkflow(t *testing.T) { | ||
server := mocks.NewGrpcServer() | ||
defer server.Stop() | ||
|
||
client, err := client.Connect(context.Background(), server.Addr()) | ||
require.NoError(t, err) | ||
|
||
var receivedConnectionTestRequest *proto.OTLPConnectionTestRequest | ||
client.OnOTLPConnectionTest(func(ctx context.Context, otr *proto.OTLPConnectionTestRequest) error { | ||
receivedConnectionTestRequest = otr | ||
return nil | ||
}) | ||
|
||
err = client.Start(context.Background()) | ||
require.NoError(t, err) | ||
|
||
connectionTestRequest := &proto.OTLPConnectionTestRequest{ | ||
RequestID: "request-id", | ||
} | ||
|
||
server.SendOTLPConnectionTestRequest(connectionTestRequest) | ||
|
||
// ensures there's enough time for networking between server and client | ||
time.Sleep(1 * time.Second) | ||
|
||
assert.NotNil(t, receivedConnectionTestRequest) | ||
assert.Equal(t, connectionTestRequest.RequestID, "request-id") | ||
} |
This file contains 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 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,43 @@ | ||
package client_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/kubeshop/tracetest/agent/client" | ||
"github.com/kubeshop/tracetest/agent/client/mocks" | ||
"github.com/kubeshop/tracetest/agent/proto" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestDataStoreConnectionResult(t *testing.T) { | ||
server := mocks.NewGrpcServer() | ||
defer server.Stop() | ||
|
||
client, err := client.Connect(context.Background(), server.Addr()) | ||
require.NoError(t, err) | ||
|
||
err = client.Start(context.Background()) | ||
require.NoError(t, err) | ||
|
||
result := &proto.DataStoreConnectionTestResponse{ | ||
RequestID: "request-id", | ||
AgentIdentification: &proto.AgentIdentification{}, | ||
Successful: true, | ||
Steps: &proto.DataStoreConnectionTestSteps{ | ||
PortCheck: &proto.DataStoreConnectionTestStep{ | ||
Passed: true, | ||
}, | ||
}, | ||
} | ||
|
||
err = client.SendDataStoreConnectionResult(context.Background(), result) | ||
require.NoError(t, err) | ||
|
||
receivedResponse := server.GetLastDataStoreConnectionResponse() | ||
|
||
assert.Equal(t, result.RequestID, receivedResponse.RequestID) | ||
assert.True(t, result.Successful) | ||
assert.True(t, result.Steps.PortCheck.Passed) | ||
} |
This file contains 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,21 @@ | ||
package client | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/kubeshop/tracetest/agent/proto" | ||
) | ||
|
||
func (c *Client) SendOTLPConnectionResult(ctx context.Context, response *proto.OTLPConnectionTestResponse) error { | ||
client := proto.NewOrchestratorClient(c.conn) | ||
|
||
response.AgentIdentification = c.sessionConfig.AgentIdentification | ||
|
||
_, err := client.SendOTLPConnectionTestResult(ctx, response) | ||
if err != nil { | ||
return fmt.Errorf("could not send otlp connection result request: %w", err) | ||
} | ||
|
||
return nil | ||
} |
This file contains 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,41 @@ | ||
package client_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/kubeshop/tracetest/agent/client" | ||
"github.com/kubeshop/tracetest/agent/client/mocks" | ||
"github.com/kubeshop/tracetest/agent/proto" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestOTLPConnectionResultTrace(t *testing.T) { | ||
server := mocks.NewGrpcServer() | ||
defer server.Stop() | ||
|
||
client, err := client.Connect(context.Background(), server.Addr()) | ||
require.NoError(t, err) | ||
|
||
err = client.Start(context.Background()) | ||
require.NoError(t, err) | ||
|
||
now := time.Now() | ||
result := &proto.OTLPConnectionTestResponse{ | ||
RequestID: "request-id", | ||
AgentIdentification: &proto.AgentIdentification{}, | ||
SpanCount: 10, | ||
LastSpanTimestamp: now.UnixMilli(), | ||
} | ||
|
||
err = client.SendOTLPConnectionResult(context.Background(), result) | ||
require.NoError(t, err) | ||
|
||
receivedResponse := server.GetLastOTLPConnectionResponse() | ||
|
||
assert.Equal(t, result.RequestID, receivedResponse.RequestID) | ||
assert.Equal(t, result.SpanCount, receivedResponse.SpanCount) | ||
assert.Equal(t, result.LastSpanTimestamp, receivedResponse.LastSpanTimestamp) | ||
} |
Oops, something went wrong.
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.
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.
Philosophical question: is there a way to get the context from the request?
My impression is that there is no way to get these contexts due to the passive nature of getting the messages.
Could we create a context in the future and change it by monitoring the stream connection?
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 would need to propagate headers through the messages to be able to create a context from the request (propagate the otel headers)