Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Added Atlas counter titus.executor.S3Uploader.uploadMB to report log … #151

Merged
merged 1 commit into from
Jul 9, 2018

Conversation

rickkw
Copy link
Contributor

@rickkw rickkw commented Jun 29, 2018

Report metrics on log file size uploaded in MB

@coveralls
Copy link

coveralls commented Jun 29, 2018

Pull Request Test Coverage Report for Build 1605

  • 6 of 18 (33.33%) changed or added relevant lines in 5 files are covered.
  • 373 unchanged lines in 6 files lost coverage.
  • Overall coverage increased (+0.6%) to 23.042%

Changes Missing Coverage Covered Lines Changed/Added Lines %
cmd/titus-executor/main.go 0 1 0.0%
cmd/titus-standalone/main.go 0 1 0.0%
executor/mock/jobrunner.go 0 1 0.0%
uploader/uploader.go 0 4 0.0%
uploader/s3.go 6 11 54.55%
Files with Coverage Reduction New Missed Lines %
executor/runtime/docker/docker.go 7 2.21%
executor/runtime/types/types.go 15 30.68%
executor/mock/jobrunner.go 36 0.0%
api/netflix/titus/titus_agent_api.pb.go 79 4.69%
api/netflix/titus/agent.pb.go 114 17.76%
api/netflix/titus/titus_base.pb.go 122 4.56%
Totals Coverage Status
Change from base Build 1566: 0.6%
Covered Lines: 2095
Relevant Lines: 9092

💛 - Coveralls

@codecov
Copy link

codecov bot commented Jun 29, 2018

Codecov Report

Merging #151 into master will increase coverage by 13.19%.
The diff coverage is 56.25%.

Impacted file tree graph

@@             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
Impacted Files Coverage Δ
cmd/titus-standalone/main.go 0% <0%> (ø) ⬆️
cmd/titus-executor/main.go 4.83% <0%> (ø) ⬆️
executor/mock/jobrunner.go 77.23% <100%> (+77.23%) ⬆️
uploader/s3.go 7.35% <55.55%> (+7.35%) ⬆️
uploader/uploader.go 50% <75%> (+23.61%) ⬆️
api/netflix/titus/titus_agent_api.pb.go 5.34% <0%> (ø) ⬆️
api/netflix/titus/titus_base.pb.go 4.95% <0%> (+1.21%) ⬆️
filesystems/watcher.go 62% <0%> (+3.71%) ⬆️
config/config.go 97% <0%> (+4.5%) ⬆️
uploader/copy.go 50% <0%> (+5%) ⬆️
... and 13 more

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)
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor

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)
Copy link
Contributor

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 {
Copy link
Contributor

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.

Copy link
Contributor Author

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 {
Copy link
Contributor

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
Copy link
Contributor

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}
Copy link
Contributor

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),
Copy link
Contributor

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?

"testing"
)

func TestCountingReader_Read(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestCountingReader_Read -> TestCountingReaderRead


buffer := make([]byte, 10)
for {
_, err := countingReader.Read(buffer)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use:

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)

"github.com/stretchr/testify/assert"
)

func TestCountingReader_Read(t *testing.T) {
Copy link
Contributor

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?

Copy link
Contributor

@sargun sargun left a 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

@rickkw rickkw force-pushed the TITUS-895_publish_metrics_log_upload_in_MB branch from aed7d28 to e75b6b1 Compare July 9, 2018 19:57
@rickkw rickkw merged commit 3b03700 into master Jul 9, 2018
@rickkw rickkw deleted the TITUS-895_publish_metrics_log_upload_in_MB branch July 12, 2018 18:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants