-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
36 changed files
with
2,780 additions
and
218 deletions.
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
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,63 @@ | ||
package client | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"time" | ||
|
||
"github.com/kubeshop/tracetest/agent/proto" | ||
"github.com/kubeshop/tracetest/agent/telemetry" | ||
"go.uber.org/zap" | ||
) | ||
|
||
func (c *Client) startTraceModeListener(ctx context.Context) error { | ||
logger := c.logger.Named("trace_mode_listener") | ||
logger.Debug("Starting") | ||
|
||
client := proto.NewOrchestratorClient(c.conn) | ||
|
||
stream, err := client.RegisterTraceModeAgent(ctx, c.sessionConfig.AgentIdentification) | ||
if err != nil { | ||
logger.Error("could not open agent stream", zap.Error(err)) | ||
return fmt.Errorf("could not open agent stream: %w", err) | ||
} | ||
|
||
go func() { | ||
for { | ||
req := proto.TraceModeRequest{} | ||
err := stream.RecvMsg(&req) | ||
if err != nil { | ||
logger.Error("could not get message from stop stream", zap.Error(err)) | ||
} | ||
if isEndOfFileError(err) || isCancelledError(err) { | ||
logger.Debug("stop stream closed") | ||
return | ||
} | ||
|
||
reconnected, err := c.handleDisconnectionError(err, &req) | ||
if reconnected { | ||
logger.Warn("reconnected to stop stream") | ||
return | ||
} | ||
|
||
if err != nil { | ||
logger.Error("could not get message from stop stream", zap.Error(err)) | ||
log.Println("could not get message from trace mode stream: %w", err) | ||
time.Sleep(1 * time.Second) | ||
continue | ||
} | ||
|
||
// we want a new context per request, not to reuse the one from the stream | ||
ctx := telemetry.InjectMetadataIntoContext(context.Background(), req.Metadata) | ||
go func() { | ||
err = c.traceModeListener(ctx, &req) | ||
if err != nil { | ||
logger.Error("could not handle trace mode request", zap.Error(err)) | ||
fmt.Println(err.Error()) | ||
} | ||
}() | ||
} | ||
}() | ||
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,23 @@ | ||
package client | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/kubeshop/tracetest/agent/proto" | ||
"github.com/kubeshop/tracetest/agent/telemetry" | ||
) | ||
|
||
func (c *Client) SendTraceModeResponse(ctx context.Context, response *proto.TraceModeResponse) error { | ||
client := proto.NewOrchestratorClient(c.conn) | ||
|
||
response.AgentIdentification = c.sessionConfig.AgentIdentification | ||
response.Metadata = telemetry.ExtractMetadataFromContext(ctx) | ||
|
||
_, err := client.SendTraceModeResponse(ctx, response) | ||
if err != nil { | ||
return fmt.Errorf("could not send list traces 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
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
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
Oops, something went wrong.