Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions assets/graphqls/trace/ColdTrace.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Licensed to Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright
# ownership. Apache Software Foundation (ASF) licenses this file to you under
# the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

query ($traceId: ID!, $duration: Duration!) {
result: queryTraceFromColdStage(traceId: $traceId, duration: $duration) {
spans {
traceId
segmentId
spanId
parentSpanId
refs {
traceId
parentSegmentId
parentSpanId
type
}
serviceCode
serviceInstanceName
startTime
endTime
endpointName
type
peer
component
isError
layer
tags {
key value
}
logs {
time data {
key value
}
}
attachedEvents {
startTime {
seconds nanos
}
event
endTime {
seconds nanos
}
tags {
key value
}
summary {
key value
}
}
}
}
}
22 changes: 22 additions & 0 deletions internal/commands/trace/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ $ swctl trace ls --service-name "business-zone::projectB" --endpoint-name "/proj

3. Query the monitored trace of id "321661b1-9a31-4e12-ad64-c8f6711f108d":
$ swctl trace ls --trace-id "321661b1-9a31-4e12-ad64-c8f6711f108d"

4. Query the monitored trace of id "321661b1-9a31-4e12-ad64-c8f6711f108d" from cold-stage storage:
$ swctl trace ls --trace-id "321661b1-9a31-4e12-ad64-c8f6711f108d" --cold
`,
Flags: flags.Flags(
flags.DurationFlags,
Expand All @@ -74,6 +77,11 @@ $ swctl trace ls --trace-id "321661b1-9a31-4e12-ad64-c8f6711f108d"
Usage: "`order` of the returned traces, can be `duration` or `startTime`",
Value: "duration",
},
&cli.BoolFlag{
Name: "cold",
Usage: "query trace from cold-stage storage, must be used with trace-id",
Value: false,
},
},
),
Before: interceptor.BeforeChain(
Expand All @@ -96,6 +104,20 @@ $ swctl trace ls --trace-id "321661b1-9a31-4e12-ad64-c8f6711f108d"
serviceInstanceID := ctx.String("instance-id")
traceID := ctx.String("trace-id")
tagStr := ctx.String("tags")
cold := ctx.Bool("cold")

if cold && traceID == "" {
return fmt.Errorf("cold storage must be queried with trace-id")
}

if cold {
trace, err := trace.ColdTrace(ctx.Context, duration, traceID)
if err != nil {
return err
}
return display.Display(ctx.Context, &displayable.Displayable{Data: trace})
}

var tags []*api.SpanTag = nil
if tagStr != "" {
tagArr := strings.SplitSeq(tagStr, ",")
Expand Down
11 changes: 11 additions & 0 deletions pkg/graphql/trace/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ func Trace(ctx context.Context, traceID string) (api.Trace, error) {
return response["result"], err
}

func ColdTrace(ctx context.Context, duration api.Duration, traceID string) (api.Trace, error) {
var response map[string]api.Trace

request := graphql.NewRequest(assets.Read("graphqls/trace/ColdTrace.graphql"))
request.Var("traceId", traceID)
request.Var("duration", duration)
err := client.ExecuteQuery(ctx, request, &response)

return response["result"], err
}

func Traces(ctx context.Context, condition *api.TraceQueryCondition) (api.TraceBrief, error) {
var response map[string]api.TraceBrief

Expand Down
Loading