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

Trace poller #3164

Merged
merged 15 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion agent/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Dependencies:
# https://grpc.io/docs/protoc-installation/
# go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.31
# go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.3

REQUIRED_BINS := protoc
REQUIRED_BINS := protoc protoc-gen-go protoc-gen-go-grpc

build-proto: ensure-dependencies clean-proto
@protoc \
Expand Down
12 changes: 3 additions & 9 deletions agent/client/workflow_send_trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,14 @@ import (
"github.com/kubeshop/tracetest/agent/proto"
)

func (c *Client) SendTrace(ctx context.Context, request *proto.PollingRequest, spans ...*proto.Span) error {
func (c *Client) SendTrace(ctx context.Context, pollingResponse *proto.PollingResponse) error {
client := proto.NewOrchestratorClient(c.conn)

pollingResponse := &proto.PollingResponse{
TestID: request.TestID,
RunID: request.RunID,
TraceID: request.TraceID,
Spans: spans,
AgentIdentification: c.sessionConfig.AgentIdentification,
}
pollingResponse.AgentIdentification = c.sessionConfig.AgentIdentification

_, err := client.SendPolledSpans(ctx, pollingResponse)
if err != nil {
return fmt.Errorf("could not send trigger result request: %w", err)
return fmt.Errorf("could not send polled spans result request: %w", err)
}

return nil
Expand Down
31 changes: 15 additions & 16 deletions agent/client/workflow_send_trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,26 @@ func TestSendTrace(t *testing.T) {
err = client.Start(context.Background())
require.NoError(t, err)

pollingRequest := &proto.PollingRequest{
pollingRequest := &proto.PollingResponse{
TestID: "test",
RunID: 1,
TraceID: "trace-id",
}

spans := []*proto.Span{
{
Name: "GET /",
Id: "id",
ParentId: "parent-id",
Kind: "internal",
StartTime: 0,
EndTime: 45,
Attributes: []*proto.KeyValuePair{
{Key: "http.status", Value: "200"},
Spans: []*proto.Span{
{
Name: "GET /",
Id: "id",
ParentId: "parent-id",
Kind: "internal",
StartTime: 0,
EndTime: 45,
Attributes: []*proto.KeyValuePair{
{Key: "http.status", Value: "200"},
},
},
},
}

err = client.SendTrace(context.Background(), pollingRequest, spans...)
err = client.SendTrace(context.Background(), pollingRequest)
require.NoError(t, err)

receivedPollingResponse := server.GetLastPollingResponse()
Expand All @@ -49,8 +48,8 @@ func TestSendTrace(t *testing.T) {
assert.Equal(t, pollingRequest.RunID, receivedPollingResponse.RunID)
assert.Equal(t, pollingRequest.TraceID, receivedPollingResponse.TraceID)

require.Len(t, receivedPollingResponse.Spans, len(spans))
for i, span := range spans {
require.Len(t, receivedPollingResponse.Spans, len(pollingRequest.Spans))
for i, span := range pollingRequest.Spans {
assert.Equal(t, span.Id, receivedPollingResponse.Spans[i].Id)
assert.Equal(t, span.Name, receivedPollingResponse.Spans[i].Name)
assert.Equal(t, span.Kind, receivedPollingResponse.Spans[i].Kind)
Expand Down
27 changes: 27 additions & 0 deletions agent/example/collector.config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
receivers:
otlp:
protocols:
grpc:
http:

processors:
batch:
timeout: 100ms

# Data sources: traces
probabilistic_sampler:
hash_seed: 22
sampling_percentage: 100

exporters:
otlp/jaeger:
endpoint: jaeger:4317
tls:
insecure: true

service:
pipelines:
traces:
receivers: [otlp]
processors: [probabilistic_sampler, batch]
exporters: [otlp/jaeger]
80 changes: 80 additions & 0 deletions agent/example/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
version: '3'
services:
demo-api:
image: kubeshop/demo-pokemon-api:latest
restart: unless-stopped
pull_policy: always
environment:
REDIS_URL: cache
DATABASE_URL: postgresql://postgres:postgres@postgres:5432/postgres?schema=public
RABBITMQ_HOST: queue
POKE_API_BASE_URL: https://pokeapi.co/api/v2
COLLECTOR_ENDPOINT: http://otel-collector:4317
NPM_RUN_COMMAND: api
ports:
- "8081:8081"
healthcheck:
test: ["CMD", "wget", "--spider", "localhost:8081"]
interval: 1s
timeout: 3s
retries: 60
depends_on:
postgres:
condition: service_healthy
cache:
condition: service_healthy
queue:
condition: service_healthy

postgres:
image: postgres:14
environment:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
healthcheck:
test: pg_isready -U "$$POSTGRES_USER" -d "$$POSTGRES_DB"
interval: 1s
timeout: 5s
retries: 60

cache:
image: redis:6
restart: unless-stopped
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 1s
timeout: 3s
retries: 60

queue:
image: rabbitmq:3.8-management
restart: unless-stopped
healthcheck:
test: rabbitmq-diagnostics -q check_running
interval: 1s
timeout: 5s
retries: 60

otel-collector:
image: otel/opentelemetry-collector:0.54.0
command:
- "--config"
- "/otel-local-config.yaml"
volumes:
- ./collector.config.yaml:/otel-local-config.yaml
depends_on:
- jaeger

jaeger:
image: jaegertracing/all-in-one:latest
restart: unless-stopped
healthcheck:
test: ["CMD", "wget", "--spider", "localhost:16686"]
interval: 1s
timeout: 3s
retries: 60
environment:
- COLLECTOR_OTLP_ENABLED=true
ports:
- 16686:16686
- 16685:16685
1 change: 1 addition & 0 deletions agent/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ require (
require (
github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 // indirect
github.com/AzureAD/microsoft-authentication-library-for-go v1.0.0 // indirect
github.com/Code-Hex/go-generics-cache v1.3.1 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/alecthomas/participle/v2 v2.0.0-alpha8 // indirect
Expand Down
2 changes: 2 additions & 0 deletions agent/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ github.com/AzureAD/microsoft-authentication-library-for-go v1.0.0 h1:OBhqkivkhkM
github.com/AzureAD/microsoft-authentication-library-for-go v1.0.0/go.mod h1:kgDmCTgBzIEPFElEF+FK0SdjAor06dRq2Go927dnQ6o=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/Code-Hex/go-generics-cache v1.3.1 h1:i8rLwyhoyhaerr7JpjtYjJZUcCbWOdiYO3fZXLiEC4g=
github.com/Code-Hex/go-generics-cache v1.3.1/go.mod h1:qxcC9kRVrct9rHeiYpFWSoW1vxyillCVzX13KZG8dl4=
github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
github.com/DATA-DOG/go-sqlmock v1.4.1/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
Expand Down