-
Notifications
You must be signed in to change notification settings - Fork 50
Added Atlas counter titus.executor.S3Uploader.uploadMB to report log … #151
Conversation
Pull Request Test Coverage Report for Build 1605
💛 - Coveralls |
Codecov Report
@@ Coverage Diff @@
## master #151 +/- ##
===========================================
+ Coverage 20.69% 33.88% +13.19%
===========================================
Files 61 61
Lines 7414 7174 -240
===========================================
+ Hits 1534 2431 +897
+ Misses 5690 4445 -1245
- Partials 190 298 +108
|
uploader/s3.go
Outdated
@@ -87,6 +90,11 @@ func (u *S3Uploader) Upload(ctx context.Context, local string, remote string, ct | |||
} | |||
}() | |||
|
|||
// Record number of bytes being uploaded. At this point, file must exist. | |||
if stat, err := os.Stat(local); err == nil { | |||
u.metrics.Counter("titus.executor.S3Uploader.uploadMB", int(stat.Size()/1024/1024), nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this needs tags or the only information it will tell me is that an agent uploaded some megabytes to S3 during some time frame.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what tags can you think of? Filename may not be a good choice if it rotates and have a numerical or timestamp suffix. I assume the standard tags already includes container ID, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just thinking container ID. Does the u.metrics.Counter
method automatically add container information?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nf.node is usually set to the container's task ID from my understanding. I might suggest just asking the insights team all the the nf.* tags they associate with task metrics and use those.
uploader/s3.go
Outdated
@@ -87,6 +90,11 @@ func (u *S3Uploader) Upload(ctx context.Context, local string, remote string, ct | |||
} | |||
}() | |||
|
|||
// Record number of bytes being uploaded. At this point, file must exist. | |||
if stat, err := os.Stat(local); err == nil { | |||
u.metrics.Counter("titus.executor.S3Uploader.uploadMB", int(stat.Size()/1024/1024), nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nf.node is usually set to the container's task ID from my understanding. I might suggest just asking the insights team all the the nf.* tags they associate with task metrics and use those.
uploader/s3.go
Outdated
@@ -87,6 +90,11 @@ func (u *S3Uploader) Upload(ctx context.Context, local string, remote string, ct | |||
} | |||
}() | |||
|
|||
// Record number of bytes being uploaded. At this point, file must exist. | |||
if stat, err := os.Stat(local); err == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use os.Stat here because then you wont catch stuff being uploaded via UploadPartOfFile
.
You should move the code into uploadFile
. I might see if there's a simple io.Reader wrapper to get callbacks as data is read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
uploader/s3.go
Outdated
@@ -90,24 +93,43 @@ func (u *S3Uploader) Upload(ctx context.Context, local string, remote string, ct | |||
return u.uploadFile(ctx, f, remote, contentType) | |||
} | |||
|
|||
// CountingReader is a wrapper of io.Reader to count number of bytes read | |||
type CountingReader struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is CountingReader
exposed outside of the package? It should be countingReader
if it's not used outside of the package (equivalent to private in Java).
uploader/s3.go
Outdated
// CountingReader is a wrapper of io.Reader to count number of bytes read | ||
type CountingReader struct { | ||
reader io.Reader | ||
BytesRead int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might want to make this an int64?
uploader/s3.go
Outdated
// UploadFile writes a single file only to S3! | ||
func (u *S3Uploader) uploadFile(ctx context.Context, local io.Reader, remote string, contentType string) error { | ||
u.log.Printf("Attempting to upload file from: %s to: %s", local, path.Join(u.bucketName, remote)) | ||
if contentType == "" { | ||
contentType = defaultS3ContentType | ||
} | ||
|
||
// wrap input io.Reader with a counting reader | ||
reader := &CountingReader{local, 0} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, it's better to initialize with explicit field names. Also, by default in Go, uninitialized fields have default values. For ints, this is 0.
uploader/s3.go
Outdated
result, err := u.s3Uploader.UploadWithContext(ctx, &s3manager.UploadInput{ | ||
ACL: aws.String(defaultS3ACL), | ||
ContentType: aws.String(contentType), | ||
Bucket: aws.String(u.bucketName), | ||
Key: aws.String(remote), | ||
Body: local, | ||
Body: io.Reader(reader), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this cast neccessary here?
uploader/s3_test.go
Outdated
"testing" | ||
) | ||
|
||
func TestCountingReader_Read(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TestCountingReader_Read
-> TestCountingReaderRead
uploader/s3_test.go
Outdated
|
||
buffer := make([]byte, 10) | ||
for { | ||
_, err := countingReader.Read(buffer) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use:
- https://golang.org/pkg/io/ioutil/#ReadAll
- https://golang.org/pkg/io/#Copy with
ioutil.discard
There's also a library which makes asserting on these errors easier: https://github.com/stretchr/testify
You can do something like assert.Equal(t, len(data), n)
uploader/s3_test.go
Outdated
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCountingReader_Read(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, I thought there was a comment to remove this underscore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rewrite / squash your commits
aed7d28
to
e75b6b1
Compare
Report metrics on log file size uploaded in MB