Skip to content

Commit

Permalink
fix: possible panics in tracedb package
Browse files Browse the repository at this point in the history
  • Loading branch information
mathnogueira committed Nov 28, 2023
1 parent 65310e9 commit 924946d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
4 changes: 4 additions & 0 deletions server/tracedb/azureappinsights.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ func parseSpans(table *azquery.Table) ([]traces.Span, error) {

for _, eventRow := range eventRows {
parentSpan := spanMap[eventRow.ParentID()]
if parentSpan == nil {
continue

Check warning on line 218 in server/tracedb/azureappinsights.go

View check run for this annotation

Codecov / codecov/patch

server/tracedb/azureappinsights.go#L217-L218

Added lines #L217 - L218 were not covered by tests
}

event, err := parseEvent(eventRow)
if err != nil {
return []traces.Span{}, err
Expand Down
5 changes: 5 additions & 0 deletions server/tracedb/elasticsearchdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ func getClusterInfo(client *elasticsearch.Client) (string, error) {
if err != nil {
return "", fmt.Errorf("error getting cluster info response: %s", err)
}

if res == nil {
return "", fmt.Errorf("could not get response")
}

Check warning on line 143 in server/tracedb/elasticsearchdb.go

View check run for this annotation

Codecov / codecov/patch

server/tracedb/elasticsearchdb.go#L141-L143

Added lines #L141 - L143 were not covered by tests

defer res.Body.Close()

// Check response status
Expand Down
8 changes: 8 additions & 0 deletions server/tracedb/signalfxdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ func (db signalfxDB) getSegmentsTimestamps(ctx context.Context, traceID string)
return []int64{}, fmt.Errorf("could not execute request: %w", err)
}

if response == nil {
return []int64{}, fmt.Errorf("could not get response")
}

Check warning on line 119 in server/tracedb/signalfxdb.go

View check run for this annotation

Codecov / codecov/patch

server/tracedb/signalfxdb.go#L117-L119

Added lines #L117 - L119 were not covered by tests

if response.StatusCode != http.StatusOK {
return []int64{}, fmt.Errorf("service responded with a non ok status code: %s", strconv.Itoa(response.StatusCode))
}
Expand Down Expand Up @@ -148,6 +152,10 @@ func (db signalfxDB) getSegmentSpans(ctx context.Context, traceID string, timest
return []signalFXSpan{}, fmt.Errorf("could not execute request: %w", err)
}

if response == nil {
return []signalFXSpan{}, fmt.Errorf("could not get response")
}

Check warning on line 157 in server/tracedb/signalfxdb.go

View check run for this annotation

Codecov / codecov/patch

server/tracedb/signalfxdb.go#L155-L157

Added lines #L155 - L157 were not covered by tests

if response.StatusCode != 200 {
return []signalFXSpan{}, nil
}
Expand Down
5 changes: 4 additions & 1 deletion server/tracedb/tempodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,14 @@ func httpGetTraceByID(ctx context.Context, traceID string, client *datasource.Ht
return traces.Trace{}, err
}
resp, err := client.Request(ctx, fmt.Sprintf("/api/traces/%s", trID), http.MethodGet, "")

if err != nil {
return traces.Trace{}, handleError(err)
}

if resp == nil {
return traces.Trace{}, fmt.Errorf("could not get response")
}

Check warning on line 130 in server/tracedb/tempodb.go

View check run for this annotation

Codecov / codecov/patch

server/tracedb/tempodb.go#L128-L130

Added lines #L128 - L130 were not covered by tests

if resp.StatusCode == 404 {
return traces.Trace{}, connection.ErrTraceNotFound
}
Expand Down

0 comments on commit 924946d

Please sign in to comment.