Skip to content

Commit c0c0d7e

Browse files
aledbfroboquat
authored andcommitted
[registry-facade] Improve IPFS logging
1 parent 1fe7486 commit c0c0d7e

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

components/registry-facade/pkg/registry/blob.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,9 @@ func (bh *blobHandler) getBlob(w http.ResponseWriter, r *http.Request) {
123123

124124
var srcs []BlobSource
125125

126+
ipfsSrc := ipfsBlobSource{source: bh.IPFS}
126127
if bh.IPFS != nil {
127-
srcs = append(srcs, ipfsBlobSource{source: bh.IPFS})
128+
srcs = append(srcs, ipfsSrc)
128129
}
129130

130131
srcs = append(srcs, storeBlobSource{Store: bh.Store})
@@ -176,6 +177,11 @@ func (bh *blobHandler) getBlob(w http.ResponseWriter, r *http.Request) {
176177
return nil
177178
}
178179

180+
// do not duplicate content in IPFS
181+
if src == ipfsSrc {
182+
return nil
183+
}
184+
179185
go func() {
180186
// we can do this only after the io.Copy above. Otherwise we might expect the blob
181187
// to be in the blobstore when in reality it isn't.

components/registry-facade/pkg/registry/http_client.go

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/gitpod-io/gitpod/common-go/log"
1111
"github.com/hashicorp/go-retryablehttp"
12+
"github.com/sirupsen/logrus"
1213
)
1314

1415
type Option func(opts *httpOpts)
@@ -35,7 +36,7 @@ func NewRetryableHTTPClient(options ...Option) *http.Client {
3536
func defaultOptions() httpOpts {
3637
return httpOpts{
3738
RetryMax: 5,
38-
Logger: log.Log,
39+
Logger: retryablehttp.LeveledLogger(&leveledLogrus{log.Log}),
3940

4041
RequestLogHook: func(logger retryablehttp.Logger, req *http.Request, attempt int) {
4142
if attempt > 0 {
@@ -47,7 +48,7 @@ func defaultOptions() httpOpts {
4748

4849
type httpOpts struct {
4950
HTTPClient *http.Client
50-
Logger interface{}
51+
Logger retryablehttp.LeveledLogger
5152

5253
RetryMax int
5354

@@ -82,3 +83,33 @@ func WithHTTPClient(client *http.Client) Option {
8283
opts.HTTPClient = client
8384
}
8485
}
86+
87+
type leveledLogrus struct {
88+
*logrus.Entry
89+
}
90+
91+
func (l *leveledLogrus) fields(keysAndValues ...interface{}) map[string]interface{} {
92+
fields := make(map[string]interface{})
93+
94+
for i := 0; i < len(keysAndValues)-1; i += 2 {
95+
fields[keysAndValues[i].(string)] = keysAndValues[i+1]
96+
}
97+
98+
return fields
99+
}
100+
101+
func (l *leveledLogrus) Error(msg string, keysAndValues ...interface{}) {
102+
l.WithFields(l.fields(keysAndValues...)).Error(msg)
103+
}
104+
105+
func (l *leveledLogrus) Info(msg string, keysAndValues ...interface{}) {
106+
l.WithFields(l.fields(keysAndValues...)).Info(msg)
107+
}
108+
109+
func (l *leveledLogrus) Debug(msg string, keysAndValues ...interface{}) {
110+
l.WithFields(l.fields(keysAndValues...)).Debug(msg)
111+
}
112+
113+
func (l *leveledLogrus) Warn(msg string, keysAndValues ...interface{}) {
114+
l.WithFields(l.fields(keysAndValues...)).Warn(msg)
115+
}

0 commit comments

Comments
 (0)