Skip to content

Commit c22d364

Browse files
hweawerCopilot
andauthored
Remove unused verification metrics (#457)
* Remove unused verification metrics * Fix formatting * Remove unused field * Fix test * Update lib/dockerregistry/manifests.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent f2150de commit c22d364

File tree

4 files changed

+16
-86
lines changed

4 files changed

+16
-86
lines changed

lib/dockerregistry/manifests.go

Lines changed: 7 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,14 @@ import (
2020

2121
"github.com/uber/kraken/utils/closers"
2222

23-
"github.com/uber-go/tally"
24-
"github.com/uber/kraken/lib/store"
25-
2623
storagedriver "github.com/docker/distribution/registry/storage/driver"
24+
2725
"github.com/uber/kraken/core"
2826
"github.com/uber/kraken/lib/dockerregistry/transfer"
29-
"github.com/uber/kraken/utils/cache"
27+
"github.com/uber/kraken/lib/store"
3028
"github.com/uber/kraken/utils/log"
3129
)
3230

33-
const (
34-
signatureVerificationSuccessCounter = "signature_verification_success"
35-
signatureVerificationFailureCounter = "signature_verification_failure"
36-
signatureVerificationErrorCounter = "signature_verification_error"
37-
signatureVerificationDuration = "signature_verification_duration"
38-
39-
// Verification cache configuration
40-
defaultVerificationCacheSize = 300 // Maximum number of entries
41-
defaultVerificationCacheTTL = 5 * time.Minute // TTL for verification cache entries
42-
)
43-
4431
type SignatureVerificationDecision int
4532

4633
const (
@@ -52,22 +39,15 @@ const (
5239
type manifests struct {
5340
transferer transfer.ImageTransferer
5441
verification func(repo string, digest core.Digest, blob store.FileReader) (SignatureVerificationDecision, error)
55-
metrics tally.Scope
56-
57-
// Cache to track verified (repo, digest) combinations to avoid duplicate metric emission.
58-
verifiedCache *cache.LRUCache
5942
}
6043

6144
func newManifests(
6245
transferer transfer.ImageTransferer,
6346
verification func(repo string, digest core.Digest, blob store.FileReader) (SignatureVerificationDecision, error),
64-
metrics tally.Scope,
6547
) *manifests {
6648
return &manifests{
67-
transferer: transferer,
68-
verification: verification,
69-
metrics: metrics,
70-
verifiedCache: cache.NewLRUCache(defaultVerificationCacheSize, defaultVerificationCacheTTL),
49+
transferer: transferer,
50+
verification: verification,
7151
}
7252
}
7353

@@ -80,7 +60,7 @@ func newManifests(
8060
// if subtype is revisions, parses the digest directly from the path.
8161
// 3. Downloads the manifest blob via the transferer using (repo, digest).
8262
// 4. Opportunistically invokes verify to run signature/image checks and
83-
// record metrics/logs. Verification result is not enforced here.
63+
// record logs. Verification result is not enforced here.
8464
// 5. Returns the digest in ASCII string form as a byte slice.
8565
//
8666
// Notes
@@ -121,36 +101,22 @@ func (t *manifests) getDigest(path string, subtype PathSubType) ([]byte, error)
121101
}
122102
defer closers.Close(blob)
123103

124-
// Only verify if we haven't already verified this (repo, digest) combination
125-
cacheKey := fmt.Sprintf("%s:%s", repo, digest.String())
126-
shouldEmitMetrics := !t.verifiedCache.Has(cacheKey)
127-
128104
// Signature verification is currently not enforced: errors from t.verify are ignored.
129105
// This is intentional because verification enforcement is planned for a future release.
130106
// Risks: manifests may be accepted without verification, which could allow untrusted content.
131107
// TODO: Remove error ignoring and enforce verification once the feature is activated.
132-
_, _ = t.verify(path, repo, digest, blob, shouldEmitMetrics) //nolint:errcheck
133-
134-
if shouldEmitMetrics {
135-
t.verifiedCache.Add(cacheKey)
136-
}
108+
_, _ = t.verify(path, repo, digest, blob) //nolint:errcheck
137109
return []byte(digest.String()), nil
138110
}
139111

140112
// verify runs signature/image verification for a downloaded manifest blob and
141-
// records metrics/logs around the decision and duration.
113+
// logs around the decision.
142114
//
143115
// Returns
144116
// - (true, nil) when verification is allowed or intentionally skipped.
145117
// - (false, nil) when verification explicitly denies.
146118
// - (false, err) on verification errors or unknown decisions.
147119
//
148-
// Metrics
149-
// - signature_verification_duration (timer): end-to-end verification latency.
150-
// - signature_verification_success (counter): allow decisions.
151-
// - signature_verification_failure (counter): deny decisions.
152-
// - signature_verification_error (counter): errors/unknown decisions.
153-
//
154120
// Logging
155121
// - Error on verification error (includes repo/digest).
156122
// - Warn on deny (includes original path).
@@ -160,43 +126,23 @@ func (t *manifests) verify(
160126
repo string,
161127
digest core.Digest,
162128
blob store.FileReader,
163-
emitMetrics bool,
164129
) (bool, error) {
165-
// Always measure duration, but only emit if not cached
166-
var stopwatch tally.Stopwatch
167-
if emitMetrics {
168-
stopwatch = t.metrics.Timer(signatureVerificationDuration).Start()
169-
defer stopwatch.Stop()
170-
}
171-
172130
decision, err := t.verification(repo, digest, blob)
173131
if err != nil {
174-
if emitMetrics {
175-
t.metrics.Counter(signatureVerificationErrorCounter).Inc(1)
176-
}
177132
log.With("repo", repo, "digest", digest).Errorf("Error while performing image validation %s", err)
178133
return false, err
179134
}
180135

181136
switch decision {
182137
case DecisionAllow:
183-
if emitMetrics {
184-
t.metrics.Counter(signatureVerificationSuccessCounter).Inc(1)
185-
}
186138
return true, nil
187139
case DecisionDeny:
188-
if emitMetrics {
189-
t.metrics.Counter(signatureVerificationFailureCounter).Inc(1)
190-
}
191140
log.With("repo", repo, "digest", digest).Warnf("Verification failed %s", path)
192141
return false, nil
193142
case DecisionSkip:
194143
log.With("repo", repo, "digest", digest).Debugf("Verification skipped for %s", path)
195144
return true, nil
196145
default:
197-
if emitMetrics {
198-
t.metrics.Counter(signatureVerificationErrorCounter).Inc(1)
199-
}
200146
return false, fmt.Errorf("unknown verification decision: %d", decision)
201147
}
202148
}

lib/dockerregistry/manifests_verification_test.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"testing"
1919

2020
"github.com/stretchr/testify/require"
21-
"github.com/uber-go/tally"
2221
"github.com/uber/kraken/core"
2322
"github.com/uber/kraken/lib/store"
2423
"github.com/uber/kraken/utils/dockerutil"
@@ -59,10 +58,7 @@ func buildDriverWithVerification(t *testing.T, decision SignatureVerificationDec
5958
require.Equal(t, manifestDigest, vDigest)
6059
return decision, retErr
6160
}
62-
63-
// Use a test scope so we can assert metrics
64-
stats := tally.NewTestScope("", nil)
65-
sd := NewReadWriteStorageDriver(Config{}, td.cas, td.transferer, verif, stats)
61+
sd := NewReadWriteStorageDriver(Config{}, td.cas, td.transferer, verif)
6662

6763
// Path that triggers manifests.getDigest → verify
6864
path := genManifestTagCurrentLinkPath(repo, tag, manifestDigest.Hex())

lib/dockerregistry/storage_driver.go

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828

2929
"github.com/docker/distribution/registry/storage/driver"
3030
"github.com/docker/distribution/registry/storage/driver/factory"
31-
"github.com/uber-go/tally"
3231
)
3332

3433
// The path layout in the storage backend is roughly as follows:
@@ -101,22 +100,19 @@ func getParam(params map[string]interface{}, name string) interface{} {
101100
return p
102101
}
103102

104-
func (factory *krakenStorageDriverFactory) Create(
105-
params map[string]interface{}) (driver.StorageDriver, error) {
106-
103+
func (factory *krakenStorageDriverFactory) Create(params map[string]interface{}) (driver.StorageDriver, error) {
107104
// Common parameters.
108105
constructor := getParam(params, "constructor").(string)
109106
config := getParam(params, "config").(Config)
110107
transferer := getParam(params, "transferer").(transfer.ImageTransferer)
111-
metrics := getParam(params, "metrics").(tally.Scope)
112108

113109
switch constructor {
114110
case _rw:
115111
castore := getParam(params, "castore").(*store.CAStore)
116-
return NewReadWriteStorageDriver(config, castore, transferer, factory.verification, metrics), nil
112+
return NewReadWriteStorageDriver(config, castore, transferer, factory.verification), nil
117113
case _ro:
118114
blobstore := getParam(params, "blobstore").(BlobStore)
119-
return NewReadOnlyStorageDriver(config, blobstore, transferer, factory.verification, metrics), nil
115+
return NewReadOnlyStorageDriver(config, blobstore, transferer, factory.verification), nil
120116
default:
121117
return nil, fmt.Errorf("unknown constructor %s", constructor)
122118
}
@@ -129,24 +125,20 @@ type KrakenStorageDriver struct {
129125
blobs *blobs
130126
uploads uploads
131127
manifests *manifests
132-
metrics tally.Scope
133128
}
134129

135130
// NewReadWriteStorageDriver creates a KrakenStorageDriver which can push / pull blobs.
136131
func NewReadWriteStorageDriver(
137132
config Config,
138133
cas *store.CAStore,
139134
transferer transfer.ImageTransferer,
140-
verification func(repo string, digest core.Digest, blob store.FileReader) (SignatureVerificationDecision, error),
141-
metrics tally.Scope) *KrakenStorageDriver {
142-
135+
verification func(repo string, digest core.Digest, blob store.FileReader) (SignatureVerificationDecision, error)) *KrakenStorageDriver {
143136
return &KrakenStorageDriver{
144137
config: config,
145138
transferer: transferer,
146139
blobs: newBlobs(cas, transferer),
147140
uploads: newCASUploads(cas, transferer),
148-
manifests: newManifests(transferer, verification, metrics),
149-
metrics: metrics,
141+
manifests: newManifests(transferer, verification),
150142
}
151143
}
152144

@@ -155,16 +147,13 @@ func NewReadOnlyStorageDriver(
155147
config Config,
156148
bs BlobStore,
157149
transferer transfer.ImageTransferer,
158-
verification func(repo string, digest core.Digest, blob store.FileReader) (SignatureVerificationDecision, error),
159-
metrics tally.Scope) *KrakenStorageDriver {
160-
150+
verification func(repo string, digest core.Digest, blob store.FileReader) (SignatureVerificationDecision, error)) *KrakenStorageDriver {
161151
return &KrakenStorageDriver{
162152
config: config,
163153
transferer: transferer,
164154
blobs: newBlobs(bs, transferer),
165155
uploads: disabledUploads{},
166-
manifests: newManifests(transferer, verification, metrics),
167-
metrics: metrics,
156+
manifests: newManifests(transferer, verification),
168157
}
169158
}
170159

lib/dockerregistry/testutils_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"github.com/uber/kraken/utils/dockerutil"
2525

2626
"github.com/docker/distribution/uuid"
27-
"github.com/uber-go/tally"
2827
)
2928

3029
const (
@@ -56,7 +55,7 @@ func newTestDriver() (*testDriver, func()) {
5655
}
5756

5857
func (d *testDriver) setup() (*KrakenStorageDriver, testImageUploadBundle) {
59-
sd := NewReadWriteStorageDriver(Config{}, d.cas, d.transferer, DefaultVerificationFunc, tally.NoopScope)
58+
sd := NewReadWriteStorageDriver(Config{}, d.cas, d.transferer, DefaultVerificationFunc)
6059

6160
// Create upload
6261
uploadUUID := uuid.Generate().String()

0 commit comments

Comments
 (0)