Skip to content

Commit 671af5c

Browse files
committed
Remove unnecessary debuginfod client raw files cache & address several review comments
1 parent a413070 commit 671af5c

File tree

12 files changed

+436
-151
lines changed

12 files changed

+436
-151
lines changed

.mockery.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,4 @@ packages:
6363
github.com/grafana/pyroscope/pkg/experiment/symbolizer:
6464
interfaces:
6565
DebuginfodClient:
66+
DebugInfoStore:

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require (
1111
github.com/cespare/xxhash/v2 v2.3.0
1212
github.com/colega/zeropool v0.0.0-20230505084239-6fb4a4f75381
1313
github.com/dennwc/varint v1.0.0
14-
github.com/dgraph-io/ristretto v0.2.0
14+
github.com/dgraph-io/ristretto/v2 v2.2.0
1515
github.com/dgryski/go-groupvarint v0.0.0-20230630160417-2bfb7969fb3c
1616
github.com/dolthub/swiss v0.2.1
1717
github.com/drone/envsubst v1.0.3

go.sum

+4-4
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,10 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
197197
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
198198
github.com/dennwc/varint v1.0.0 h1:kGNFFSSw8ToIy3obO/kKr8U9GZYUAxQEVuix4zfDWzE=
199199
github.com/dennwc/varint v1.0.0/go.mod h1:hnItb35rvZvJrbTALZtY/iQfDs48JKRG1RPpgziApxA=
200-
github.com/dgraph-io/ristretto v0.2.0 h1:XAfl+7cmoUDWW/2Lx8TGZQjjxIQ2Ley9DSf52dru4WE=
201-
github.com/dgraph-io/ristretto v0.2.0/go.mod h1:8uBHCU/PBV4Ag0CJrP47b9Ofby5dqWNh4FicAdoqFNU=
202-
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 h1:fAjc9m62+UWV/WAFKLNi6ZS0675eEUC9y3AlwSbQu1Y=
203-
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
200+
github.com/dgraph-io/ristretto/v2 v2.2.0 h1:bkY3XzJcXoMuELV8F+vS8kzNgicwQFAaGINAEJdWGOM=
201+
github.com/dgraph-io/ristretto/v2 v2.2.0/go.mod h1:RZrm63UmcBAaYWC1DotLYBmTvgkrs0+XhBd7Npn7/zI=
202+
github.com/dgryski/go-farm v0.0.0-20240924180020-3414d57e47da h1:aIftn67I1fkbMa512G+w+Pxci9hJPB8oMnkcP3iZF38=
203+
github.com/dgryski/go-farm v0.0.0-20240924180020-3414d57e47da/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
204204
github.com/dgryski/go-groupvarint v0.0.0-20230630160417-2bfb7969fb3c h1:cHaw4wmusVzAZLEPWOCCGCfu6UvFXx9UboCHQCnjvxY=
205205
github.com/dgryski/go-groupvarint v0.0.0-20230630160417-2bfb7969fb3c/go.mod h1:MlkUQveSLEDbIgq2r1e++tSf0zfzU9mQpa9Qkczl+9Y=
206206
github.com/digitalocean/godo v1.109.0 h1:4W97RJLJSUQ3veRZDNbp1Ol3Rbn6Lmt9bKGvfqYI5SU=

pkg/experiment/symbolizer/debuginfo_store.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type DebugInfoStoreConfig struct {
1616
Storage objstoreclient.Config `yaml:"storage"`
1717
}
1818

19-
// DebugInfoCache handles caching of debug info files
19+
// DebugInfoStore handles caching of debug info files
2020
type DebugInfoStore interface {
2121
Get(ctx context.Context, buildID string) (io.ReadCloser, error)
2222
Put(ctx context.Context, buildID string, reader io.Reader) error

pkg/experiment/symbolizer/debuginfod_client.go

+19-54
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"regexp"
1414
"time"
1515

16-
"github.com/dgraph-io/ristretto"
1716
"github.com/go-kit/log"
1817
"github.com/go-kit/log/level"
1918
"github.com/grafana/dskit/backoff"
@@ -58,9 +57,6 @@ type DebuginfodHTTPClient struct {
5857
metrics *Metrics
5958
logger log.Logger
6059

61-
// In-memory cache of build IDs to debug info data
62-
cache *ristretto.Cache
63-
6460
// Used to deduplicate concurrent requests for the same build ID
6561
group singleflight.Group
6662
}
@@ -77,13 +73,6 @@ func NewDebuginfodClient(logger log.Logger, baseURL string, metrics *Metrics) (*
7773
MaxBackoff: 10 * time.Second,
7874
MaxRetries: 3,
7975
},
80-
CacheConfig: struct {
81-
MaxSizeBytes int64
82-
NumCounters int64
83-
}{
84-
MaxSizeBytes: 2 << 30, // 2GB default
85-
NumCounters: 1e7, // 10M default
86-
},
8776
}, metrics)
8877
}
8978

@@ -111,25 +100,6 @@ func NewDebuginfodClientWithConfig(logger log.Logger, cfg DebuginfodClientConfig
111100
}
112101
}
113102

114-
// Use default cache config if not specified
115-
if cfg.CacheConfig.MaxSizeBytes == 0 {
116-
cfg.CacheConfig.MaxSizeBytes = 2 << 30 // 2GB default
117-
}
118-
if cfg.CacheConfig.NumCounters == 0 {
119-
cfg.CacheConfig.NumCounters = 1e7 // 10M default
120-
}
121-
122-
// Create cache
123-
cache, err := ristretto.NewCache(&ristretto.Config{
124-
NumCounters: cfg.CacheConfig.NumCounters,
125-
MaxCost: cfg.CacheConfig.MaxSizeBytes,
126-
BufferItems: 64, // number of keys per Get buffer
127-
})
128-
129-
if err != nil {
130-
return nil, fmt.Errorf("failed to create debuginfod cache: %w", err)
131-
}
132-
133103
return &DebuginfodHTTPClient{
134104
cfg: DebuginfodClientConfig{
135105
BaseURL: cfg.BaseURL,
@@ -140,7 +110,6 @@ func NewDebuginfodClientWithConfig(logger log.Logger, cfg DebuginfodClientConfig
140110
CacheConfig: cfg.CacheConfig,
141111
},
142112
metrics: metrics,
143-
cache: cache,
144113
logger: logger,
145114
}, nil
146115
}
@@ -155,22 +124,22 @@ func (c *DebuginfodHTTPClient) FetchDebuginfo(ctx context.Context, buildID strin
155124
c.metrics.debuginfodRequestDuration.WithLabelValues(status).Observe(time.Since(start).Seconds())
156125
}()
157126

127+
level.Debug(c.logger).Log(
128+
"msg", "symbolizer: starting debuginfod fetch",
129+
"build_id", buildID,
130+
)
131+
158132
sanitizedBuildID, err := sanitizeBuildID(buildID)
159133
if err != nil {
160134
status = StatusErrorInvalidID
161135
return nil, err
162136
}
163137

164-
// Check in-memory cache first
165-
if c.cache != nil {
166-
if data, found := c.cache.Get(sanitizedBuildID); found {
167-
status = StatusCacheHit
168-
return io.NopCloser(bytes.NewReader(data.([]byte))), nil
169-
}
170-
}
171-
172138
// Check if there's already a request in flight for this build ID
173-
// This prevents duplicate requests for the same build ID
139+
level.Debug(c.logger).Log(
140+
"msg", "symbolizer: making debuginfod request",
141+
"build_id", sanitizedBuildID,
142+
)
174143
v, err, _ := c.group.Do(sanitizedBuildID, func() (interface{}, error) {
175144
return c.fetchDebugInfoWithRetries(ctx, sanitizedBuildID)
176145
})
@@ -193,6 +162,11 @@ func (c *DebuginfodHTTPClient) FetchDebuginfo(ctx context.Context, buildID strin
193162

194163
data := v.([]byte)
195164
c.metrics.debuginfodFileSize.Observe(float64(len(data)))
165+
level.Debug(c.logger).Log(
166+
"msg", "symbolizer: debuginfod fetch successful",
167+
"build_id", sanitizedBuildID,
168+
"size", len(data),
169+
)
196170
return io.NopCloser(bytes.NewReader(data)), nil
197171
}
198172

@@ -255,7 +229,7 @@ func (c *DebuginfodHTTPClient) fetchDebugInfoWithRetries(ctx context.Context, sa
255229
statusCode, isHTTPErr := isHTTPStatusError(err)
256230
if isHTTPErr && statusCode == http.StatusNotFound {
257231
lastErr = buildIDNotFoundError{buildID: sanitizedBuildID}
258-
return true // Stop retrying on 404
232+
return true
259233
}
260234

261235
// Store the error for later reporting
@@ -287,19 +261,6 @@ func (c *DebuginfodHTTPClient) fetchDebugInfoWithRetries(ctx context.Context, sa
287261
return nil, fmt.Errorf("failed to fetch debuginfo after %d attempts: %w", backOff.NumRetries(), lastErr)
288262
}
289263

290-
// Store successful result in cache
291-
if c.cache != nil {
292-
// The cost is the size of the data in bytes
293-
success := c.cache.Set(sanitizedBuildID, data, int64(len(data)))
294-
if !success && c.logger != nil {
295-
level.Warn(c.logger).Log(
296-
"msg", "Failed to store debuginfo in cache",
297-
"sanitizedBuildID", sanitizedBuildID,
298-
"size", len(data),
299-
)
300-
}
301-
}
302-
303264
return data, nil
304265
}
305266

@@ -376,6 +337,10 @@ func isRetryableError(err error) bool {
376337
// It validates that the build ID contains only alphanumeric characters, underscores, and hyphens.
377338
// This prevents potential security issues like path traversal attacks.
378339
func sanitizeBuildID(buildID string) (string, error) {
340+
if buildID == "" {
341+
return "", invalidBuildIDError{buildID: buildID}
342+
}
343+
379344
// Only allow alphanumeric characters, underscores, and hyphens
380345
validBuildID := regexp.MustCompile(`^[a-zA-Z0-9_-]+$`)
381346
if !validBuildID.MatchString(buildID) {

pkg/experiment/symbolizer/debuginfod_client_test.go

-41
Original file line numberDiff line numberDiff line change
@@ -123,47 +123,6 @@ func TestDebuginfodClient(t *testing.T) {
123123
}
124124
}
125125

126-
func TestDebuginfodClientCache(t *testing.T) {
127-
// Create a test server that counts requests
128-
requestCount := 0
129-
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
130-
requestCount++
131-
w.WriteHeader(http.StatusOK)
132-
w.Write([]byte("mock debug info"))
133-
}))
134-
defer server.Close()
135-
136-
// Create a client with the test server URL
137-
metrics := NewMetrics(prometheus.NewRegistry())
138-
client, err := NewDebuginfodClient(log.NewNopLogger(), server.URL, metrics)
139-
require.NoError(t, err)
140-
141-
// Make multiple requests with the same build ID
142-
buildID := "cache-test-id"
143-
ctx := context.Background()
144-
145-
// First request should hit the server
146-
reader1, err := client.FetchDebuginfo(ctx, buildID)
147-
require.NoError(t, err)
148-
data1, err := io.ReadAll(reader1)
149-
require.NoError(t, err)
150-
reader1.Close()
151-
assert.Equal(t, "mock debug info", string(data1))
152-
assert.Equal(t, 1, requestCount)
153-
154-
// Wait for cache operations to complete
155-
client.cache.Wait()
156-
157-
// Second request should use the cache
158-
reader2, err := client.FetchDebuginfo(ctx, buildID)
159-
require.NoError(t, err)
160-
data2, err := io.ReadAll(reader2)
161-
require.NoError(t, err)
162-
reader2.Close()
163-
assert.Equal(t, "mock debug info", string(data2))
164-
assert.Equal(t, 1, requestCount, "Expected no additional HTTP requests")
165-
}
166-
167126
func TestDebuginfodClientSingleflight(t *testing.T) {
168127
// Create a test server that sleeps to simulate a slow response
169128
requestCount := 0

0 commit comments

Comments
 (0)