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

Httptrace #1087

Draft
wants to merge 2 commits into
base: dev-3.0.0
Choose a base branch
from
Draft
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
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
52 changes: 52 additions & 0 deletions pkg/infinity/httptrace.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package infinity

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

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

func reqWithHTTPTraceContext(req *http.Request) *http.Request {
ctx := req.Context()
logger := backend.Logger.FromContext(ctx)
trace := &httptrace.ClientTrace{
GetConn: func(hostPort string) {
logger.Debug("HTTPTrace event", "event_name", "GetConn")
},
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) {
if err != nil {
logger.Error("HTTPTrace event", "event_name", "ConnectDone", "error", err.Error())
return
}
logger.Debug("HTTPTrace event", "event_name", "ConnectDone", "address", addr)
},
TLSHandshakeStart: func() {
logger.Debug("HTTPTrace event", "event_name", "TLSHandshakeStart")
},
TLSHandshakeDone: func(cs tls.ConnectionState, err error) {
if err != nil {
logger.Error("HTTPTrace event", "event_name", "TLSHandshakeDone", "error", err.Error())
return
}
logger.Debug("HTTPTrace event", "event_name", "TLSHandshakeDone")
},
GotConn: func(connInfo httptrace.GotConnInfo) {
logger.Debug("HTTPTrace event", "event_name", "GotConn", "remote_address", connInfo.Conn.RemoteAddr().String())
},
GotFirstResponseByte: func() {
logger.Debug("HTTPTrace event", "event_name", "GotFirstResponseByte")
},
}
return req.WithContext(httptrace.WithClientTrace(ctx, trace))
}
1 change: 1 addition & 0 deletions pkg/infinity/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,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)
return req, err
}

Expand Down
Loading