Skip to content

Commit

Permalink
added httpTrace logging for debugging network issues
Browse files Browse the repository at this point in the history
  • Loading branch information
yesoreyeram committed Dec 9, 2024
1 parent 4458dfa commit e8d8f88
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/sixty-lemons-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'grafana-infinity-datasource': minor
---

Added HTTPTrace logging for debugging connection issues
5 changes: 0 additions & 5 deletions docker/blocks/tempo/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ metrics_generator:
storage:
trace:
backend: local # backend configuration to use
block:
bloom_filter_false_positive: .05 # bloom filter false positive rate. lower values create larger filters but fewer false positives
v2_index_downsample_bytes: 1000 # number of bytes per index record
v2_encoding: zstd # block encoding/compression. options: none, gzip, lz4-64k, lz4-256k, lz4-1M, lz4, snappy, zstd, s2
version: vParquet
wal:
path: /tmp/tempo/wal # where to store the the wal locally
v2_encoding: snappy # wal encoding/compression. options: none, gzip, lz4-64k, lz4-256k, lz4-1M, lz4, snappy, zstd, s2
Expand Down
42 changes: 42 additions & 0 deletions pkg/infinity/httptrace.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package infinity

import (
"crypto/tls"
"net/http"
"net/http/httptrace"

"github.com/grafana/grafana-plugin-sdk-go/backend/log"
)

func reqWithHTTPTraceContext(req *http.Request, logger log.Logger) *http.Request {
trace := &httptrace.ClientTrace{
DNSStart: func(di httptrace.DNSStartInfo) {
logger.Debug("HTTPTrace event", "event_name", "DNSStart")
},
DNSDone: func(dnsInfo httptrace.DNSDoneInfo) {
logger.Debug("HTTPTrace event", "event_name", "DNSDone")
},
ConnectStart: func(network, addr string) {
logger.Debug("HTTPTrace event", "event_name", "ConnectStart")
},
ConnectDone: func(network, addr string, err error) {
logger.Debug("HTTPTrace event", "event_name", "ConnectDone")
},
GetConn: func(hostPort string) {
logger.Debug("HTTPTrace event", "event_name", "GetConn")
},
GotConn: func(connInfo httptrace.GotConnInfo) {
logger.Debug("HTTPTrace event", "event_name", "GotConn")
},
TLSHandshakeStart: func() {
logger.Debug("HTTPTrace event", "event_name", "TLSHandshakeStart")
},
TLSHandshakeDone: func(cs tls.ConnectionState, err error) {
logger.Debug("HTTPTrace event", "event_name", "TLSHandshakeDone")
},
GotFirstResponseByte: func() {
logger.Debug("HTTPTrace event", "event_name", "GotFirstResponseByte")
},
}
return req.WithContext(httptrace.WithClientTrace(req.Context(), trace))
}
3 changes: 3 additions & 0 deletions pkg/infinity/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import (
"strings"

"github.com/grafana/grafana-infinity-datasource/pkg/models"
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana-plugin-sdk-go/backend/tracing"
"moul.io/http2curl"
)

func GetRequest(ctx context.Context, settings models.InfinitySettings, body io.Reader, query models.Query, requestHeaders map[string]string, includeSect bool) (req *http.Request, err error) {
ctx, span := tracing.DefaultTracer().Start(ctx, "GetRequest")
logger := backend.Logger.FromContext(ctx)
defer span.End()
url, err := GetQueryURL(ctx, settings, query, includeSect)
if err != nil {
Expand All @@ -34,6 +36,7 @@ func GetRequest(ctx context.Context, settings models.InfinitySettings, body io.R
req = ApplyBearerToken(settings, req, includeSect)
req = ApplyApiKeyAuth(settings, req, includeSect)
req = ApplyForwardedOAuthIdentity(requestHeaders, settings, req, includeSect)
req = reqWithHTTPTraceContext(req, logger)
return req, err
}

Expand Down

0 comments on commit e8d8f88

Please sign in to comment.