-
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.
feat(agent): Adding graphql introspection to agent
- Loading branch information
Showing
12 changed files
with
1,499 additions
and
683 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
63 changes: 63 additions & 0 deletions
63
agent/client/workflow_listen_for_graphql_introspection_requests.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,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) startGraphqlIntrospectionListener(ctx context.Context) error { | ||
logger := c.logger.Named("graphqlIntrospectionListener") | ||
logger.Debug("Starting") | ||
|
||
client := proto.NewOrchestratorClient(c.conn) | ||
|
||
stream, err := client.RegisterGraphqlIntrospectListener(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.GraphqlIntrospectRequest{} | ||
err := stream.RecvMsg(&req) | ||
if err != nil { | ||
logger.Error("could not get message from graphql introspection stream", zap.Error(err)) | ||
} | ||
if isEndOfFileError(err) || isCancelledError(err) { | ||
logger.Debug("graphql introspection stream closed") | ||
return | ||
} | ||
|
||
reconnected, err := c.handleDisconnectionError(err, &req) | ||
if reconnected { | ||
logger.Warn("reconnected to graphql introspection stream") | ||
return | ||
} | ||
|
||
if err != nil { | ||
logger.Error("could not get message from graphql introspection stream", zap.Error(err)) | ||
log.Println("could not get message from graphql introspection 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.graphqlIntrospectionListener(ctx, &req) | ||
if err != nil { | ||
logger.Error("could not handle graphql introspection request", zap.Error(err)) | ||
fmt.Println(err.Error()) | ||
} | ||
}() | ||
} | ||
}() | ||
return nil | ||
} |
23 changes: 23 additions & 0 deletions
23
agent/client/workflow_send_graphql_introspection_result.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,23 @@ | ||
package client | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/kubeshop/tracetest/agent/proto" | ||
"github.com/kubeshop/tracetest/agent/telemetry" | ||
) | ||
|
||
func (c *Client) SendGraphqlIntrospectionResult(ctx context.Context, response *proto.GraphqlIntrospectResponse) error { | ||
client := proto.NewOrchestratorClient(c.conn) | ||
|
||
response.AgentIdentification = c.sessionConfig.AgentIdentification | ||
response.Metadata = telemetry.ExtractMetadataFromContext(ctx) | ||
|
||
_, err := client.SendGraphqlIntrospectResult(ctx, response) | ||
if err != nil { | ||
return fmt.Errorf("could not send graphql introspection result request: %w", err) | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.