Skip to content

Commit 13ea5ae

Browse files
authored
Merge pull request moby#3705 from coryb/bklog
use bklog.G(ctx) instead of logrus directly
2 parents 2816a83 + a8aa7b2 commit 13ea5ae

File tree

54 files changed

+180
-170
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+180
-170
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ linters-settings:
4444
forbidigo:
4545
forbid:
4646
- '^fmt\.Errorf(# use errors\.Errorf instead)?$'
47+
- 'logrus\.(Trace|Debug|Info|Warn|Warning|Error|Fatal)(f|ln)?\((# use bklog\.G\(ctx\) instead of logrus directly)?'
4748
importas:
4849
alias:
4950
- pkg: "github.com/opencontainers/image-spec/specs-go/v1"

cache/blobs.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ import (
1111
"github.com/containerd/containerd/leases"
1212
"github.com/containerd/containerd/mount"
1313
"github.com/moby/buildkit/session"
14+
"github.com/moby/buildkit/util/bklog"
1415
"github.com/moby/buildkit/util/compression"
1516
"github.com/moby/buildkit/util/flightcontrol"
1617
"github.com/moby/buildkit/util/winlayers"
1718
digest "github.com/opencontainers/go-digest"
1819
imagespecidentity "github.com/opencontainers/image-spec/identity"
1920
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
2021
"github.com/pkg/errors"
21-
"github.com/sirupsen/logrus"
2222
"golang.org/x/sync/errgroup"
2323
)
2424

@@ -180,7 +180,7 @@ func computeBlobChain(ctx context.Context, sr *immutableRef, createIfNeeded bool
180180
}
181181
}
182182
if logWarnOnErr {
183-
logrus.Warnf("failed to compute blob by overlay differ (ok=%v): %v", ok, err)
183+
bklog.G(ctx).Warnf("failed to compute blob by overlay differ (ok=%v): %v", ok, err)
184184
}
185185
}
186186
if ok {
@@ -198,7 +198,7 @@ func computeBlobChain(ctx context.Context, sr *immutableRef, createIfNeeded bool
198198
diff.WithCompressor(compressorFunc),
199199
)
200200
if err != nil {
201-
logrus.WithError(err).Warnf("failed to compute blob by buildkit differ")
201+
bklog.G(ctx).WithError(err).Warnf("failed to compute blob by buildkit differ")
202202
}
203203
}
204204

cache/manager.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
imagespecidentity "github.com/opencontainers/image-spec/identity"
2828
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
2929
"github.com/pkg/errors"
30-
"github.com/sirupsen/logrus"
3130
"golang.org/x/sync/errgroup"
3231
)
3332

@@ -243,7 +242,7 @@ func (cm *cacheManager) GetByBlob(ctx context.Context, desc ocispecs.Descriptor,
243242
if err := cm.LeaseManager.Delete(context.TODO(), leases.Lease{
244243
ID: l.ID,
245244
}); err != nil {
246-
logrus.Errorf("failed to remove lease: %+v", err)
245+
bklog.G(ctx).Errorf("failed to remove lease: %+v", err)
247246
}
248247
}
249248
}()
@@ -319,7 +318,7 @@ func (cm *cacheManager) init(ctx context.Context) error {
319318

320319
for _, si := range items {
321320
if _, err := cm.getRecord(ctx, si.ID()); err != nil {
322-
logrus.Debugf("could not load snapshot %s: %+v", si.ID(), err)
321+
bklog.G(ctx).Debugf("could not load snapshot %s: %+v", si.ID(), err)
323322
cm.MetadataStore.Clear(si.ID())
324323
cm.LeaseManager.Delete(ctx, leases.Lease{ID: si.ID()})
325324
}
@@ -597,7 +596,7 @@ func (cm *cacheManager) New(ctx context.Context, s ImmutableRef, sess session.Gr
597596
if err := cm.LeaseManager.Delete(context.TODO(), leases.Lease{
598597
ID: l.ID,
599598
}); err != nil {
600-
logrus.Errorf("failed to remove lease: %+v", err)
599+
bklog.G(ctx).Errorf("failed to remove lease: %+v", err)
601600
}
602601
}
603602
}()

cache/metadata.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func (cm *cacheManager) Search(ctx context.Context, idx string) ([]RefMetadata,
8787

8888
// callers must hold cm.mu lock
8989
func (cm *cacheManager) search(ctx context.Context, idx string) ([]RefMetadata, error) {
90-
sis, err := cm.MetadataStore.Search(idx)
90+
sis, err := cm.MetadataStore.Search(ctx, idx)
9191
if err != nil {
9292
return nil, err
9393
}

cache/metadata/metadata.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ package metadata
22

33
import (
44
"bytes"
5+
"context"
56
"encoding/json"
67
"strings"
78
"sync"
89

10+
"github.com/moby/buildkit/util/bklog"
911
"github.com/pkg/errors"
10-
"github.com/sirupsen/logrus"
1112
bolt "go.etcd.io/bbolt"
1213
)
1314

@@ -80,7 +81,7 @@ func (s *Store) Probe(index string) (bool, error) {
8081
return exists, errors.WithStack(err)
8182
}
8283

83-
func (s *Store) Search(index string) ([]*StorageItem, error) {
84+
func (s *Store) Search(ctx context.Context, index string) ([]*StorageItem, error) {
8485
var out []*StorageItem
8586
err := s.db.View(func(tx *bolt.Tx) error {
8687
b := tx.Bucket([]byte(indexBucket))
@@ -100,7 +101,7 @@ func (s *Store) Search(index string) ([]*StorageItem, error) {
100101
k, _ = c.Next()
101102
b := main.Bucket([]byte(itemID))
102103
if b == nil {
103-
logrus.Errorf("index pointing to missing record %s", itemID)
104+
bklog.G(ctx).Errorf("index pointing to missing record %s", itemID)
104105
continue
105106
}
106107
si, err := newStorageItem(itemID, b, s)

cache/metadata/metadata_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package metadata
22

33
import (
4+
"context"
45
"path/filepath"
56
"testing"
67

@@ -140,14 +141,15 @@ func TestIndexes(t *testing.T) {
140141
require.NoError(t, err)
141142
}
142143

143-
sis, err := s.Search("tag:baz")
144+
ctx := context.Background()
145+
sis, err := s.Search(ctx, "tag:baz")
144146
require.NoError(t, err)
145147
require.Equal(t, 2, len(sis))
146148

147149
require.Equal(t, sis[0].ID(), "foo1")
148150
require.Equal(t, sis[1].ID(), "foo3")
149151

150-
sis, err = s.Search("tag:bax")
152+
sis, err = s.Search(ctx, "tag:bax")
151153
require.NoError(t, err)
152154
require.Equal(t, 1, len(sis))
153155

@@ -156,7 +158,7 @@ func TestIndexes(t *testing.T) {
156158
err = s.Clear("foo1")
157159
require.NoError(t, err)
158160

159-
sis, err = s.Search("tag:baz")
161+
sis, err = s.Search(ctx, "tag:baz")
160162
require.NoError(t, err)
161163
require.Equal(t, 1, len(sis))
162164

cache/refs.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import (
3434
digest "github.com/opencontainers/go-digest"
3535
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
3636
"github.com/pkg/errors"
37-
"github.com/sirupsen/logrus"
3837
"golang.org/x/sync/errgroup"
3938
)
4039

@@ -993,7 +992,7 @@ func (sr *immutableRef) withRemoteSnapshotLabelsStargzMode(ctx context.Context,
993992
info.Labels[k] = "" // Remove labels appended in this call
994993
}
995994
if _, err := r.cm.Snapshotter.Update(ctx, info, flds...); err != nil {
996-
logrus.Warn(errors.Wrapf(err, "failed to remove tmp remote labels"))
995+
bklog.G(ctx).Warn(errors.Wrapf(err, "failed to remove tmp remote labels"))
997996
}
998997
}()
999998

@@ -1055,7 +1054,7 @@ func (sr *immutableRef) prepareRemoteSnapshotsStargzMode(ctx context.Context, s
10551054
info.Labels[k] = ""
10561055
}
10571056
if _, err := r.cm.Snapshotter.Update(ctx, info, tmpFields...); err != nil {
1058-
logrus.Warn(errors.Wrapf(err,
1057+
bklog.G(ctx).Warn(errors.Wrapf(err,
10591058
"failed to remove tmp remote labels after prepare"))
10601059
}
10611060
}()
@@ -1363,7 +1362,7 @@ func (cr *cacheRecord) finalize(ctx context.Context) error {
13631362
cr.cm.mu.Lock()
13641363
defer cr.cm.mu.Unlock()
13651364
if err := mutable.remove(context.TODO(), true); err != nil {
1366-
logrus.Error(err)
1365+
bklog.G(ctx).Error(err)
13671366
}
13681367
}()
13691368

cache/remotecache/azblob/exporter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ import (
1414
v1 "github.com/moby/buildkit/cache/remotecache/v1"
1515
"github.com/moby/buildkit/session"
1616
"github.com/moby/buildkit/solver"
17+
"github.com/moby/buildkit/util/bklog"
1718
"github.com/moby/buildkit/util/compression"
1819
"github.com/moby/buildkit/util/progress"
1920
digest "github.com/opencontainers/go-digest"
2021
"github.com/pkg/errors"
21-
"github.com/sirupsen/logrus"
2222
)
2323

2424
// ResolveCacheExporterFunc for "azblob" cache exporter.
@@ -89,7 +89,7 @@ func (ce *exporter) Finalize(ctx context.Context) (map[string]string, error) {
8989
return nil, err
9090
}
9191

92-
logrus.Debugf("layers %s exists = %t", key, exists)
92+
bklog.G(ctx).Debugf("layers %s exists = %t", key, exists)
9393

9494
if !exists {
9595
layerDone := progress.OneOff(ctx, fmt.Sprintf("writing layer %s", l.Blob))

cache/remotecache/azblob/importer.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ import (
1313
v1 "github.com/moby/buildkit/cache/remotecache/v1"
1414
"github.com/moby/buildkit/session"
1515
"github.com/moby/buildkit/solver"
16+
"github.com/moby/buildkit/util/bklog"
1617
"github.com/moby/buildkit/util/contentutil"
1718
"github.com/moby/buildkit/util/progress"
1819
"github.com/moby/buildkit/worker"
1920
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
2021
"github.com/pkg/errors"
21-
"github.com/sirupsen/logrus"
2222
"golang.org/x/sync/errgroup"
2323
)
2424

@@ -92,7 +92,7 @@ func (ci *importer) loadManifest(ctx context.Context, name string) (*v1.CacheCha
9292
return nil, err
9393
}
9494

95-
logrus.Debugf("name %s cache with key %s exists = %v", name, key, exists)
95+
bklog.G(ctx).Debugf("name %s cache with key %s exists = %v", name, key, exists)
9696

9797
if !exists {
9898
return v1.NewCacheChains(), nil
@@ -113,7 +113,7 @@ func (ci *importer) loadManifest(ctx context.Context, name string) (*v1.CacheCha
113113
return nil, errors.WithStack(err)
114114
}
115115

116-
logrus.Debugf("imported config: %s", string(bytes))
116+
bklog.G(ctx).Debugf("imported config: %s", string(bytes))
117117

118118
var config v1.CacheConfig
119119
if err := json.Unmarshal(bytes, &config); err != nil {
@@ -188,7 +188,7 @@ func (f *fetcher) Fetch(ctx context.Context, desc ocispecs.Descriptor) (io.ReadC
188188
return nil, errors.Errorf("blob %s not found", desc.Digest)
189189
}
190190

191-
logrus.Debugf("reading layer from cache: %s", key)
191+
bklog.G(ctx).Debugf("reading layer from cache: %s", key)
192192

193193
blobClient, err := f.containerClient.NewBlockBlobClient(key)
194194
if err != nil {

cache/remotecache/export.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func (ce *contentCacheExporter) Finalize(ctx context.Context) (map[string]string
104104
mfst.Manifests = append(mfst.Manifests, dgstPair.Descriptor)
105105
}
106106

107-
mfst.Manifests = compression.ConvertAllLayerMediaTypes(ce.oci, mfst.Manifests...)
107+
mfst.Manifests = compression.ConvertAllLayerMediaTypes(ctx, ce.oci, mfst.Manifests...)
108108

109109
dt, err := json.Marshal(config)
110110
if err != nil {

0 commit comments

Comments
 (0)