-
Notifications
You must be signed in to change notification settings - Fork 6.2k
dxf: separate metered traffic into object storage and cluster and fix missing cluster traffic for import-into #64523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
7847991
change
D3Hunter 7b6aeef
change
D3Hunter daeb4ca
change
D3Hunter 58f4c4a
change
D3Hunter 7f567e9
Merge remote-tracking branch 'upstream/master' into record-dxf-traffic
D3Hunter 2113cd3
change
D3Hunter 4df63f8
change
D3Hunter 641e66b
change
D3Hunter c183cc1
test
D3Hunter 776c822
log
D3Hunter 32c0b29
fix comment
D3Hunter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -117,6 +117,7 @@ type GCSStorage struct { | |
| handles []*storage.BucketHandle | ||
| clients []*storage.Client | ||
| clientCancel context.CancelFunc | ||
| accessRec *recording.AccessStats | ||
| } | ||
|
|
||
| // CopyFrom implements Copier. | ||
|
|
@@ -205,6 +206,7 @@ func (s *GCSStorage) WriteFile(ctx context.Context, name string, data []byte) er | |
| if err != nil { | ||
| return errors.Trace(err) | ||
| } | ||
| s.accessRec.RecWrite(len(data)) | ||
| return wc.Close() | ||
| } | ||
|
|
||
|
|
@@ -228,6 +230,7 @@ func (s *GCSStorage) ReadFile(ctx context.Context, name string) ([]byte, error) | |
| b = make([]byte, size) | ||
| _, err = io.ReadFull(rc, b) | ||
| } | ||
| s.accessRec.RecRead(len(b)) | ||
| return b, errors.Trace(err) | ||
| } | ||
|
|
||
|
|
@@ -345,7 +348,7 @@ func (s *GCSStorage) Create(ctx context.Context, name string, wo *WriterOption) | |
| wc := s.GetBucketHandle().Object(object).NewWriter(ctx) | ||
| wc.StorageClass = s.gcs.StorageClass | ||
| wc.PredefinedACL = s.gcs.PredefinedAcl | ||
| return newFlushStorageWriter(wc, &emptyFlusher{}, wc), nil | ||
| return newFlushStorageWriter(wc, &emptyFlusher{}, wc, s.accessRec), nil | ||
|
joechenrh marked this conversation as resolved.
|
||
| } | ||
| uri := s.objectName(name) | ||
| // 5MB is the minimum part size for GCS. | ||
|
|
@@ -354,8 +357,9 @@ func (s *GCSStorage) Create(ctx context.Context, name string, wo *WriterOption) | |
| if err != nil { | ||
| return nil, errors.Trace(err) | ||
| } | ||
| fw := newFlushStorageWriter(w, &emptyFlusher{}, w) | ||
| bw := newBufferedWriter(fw, int(partSize), NoCompression) | ||
| fw := newFlushStorageWriter(w, &emptyFlusher{}, w, s.accessRec) | ||
| // we already pass the accessRec to flushStorageWriter. | ||
| bw := newBufferedWriter(fw, int(partSize), NoCompression, nil) | ||
| return bw, nil | ||
| } | ||
|
|
||
|
|
@@ -423,14 +427,14 @@ skipHandleCred: | |
| } | ||
|
|
||
| httpClient := opts.HTTPClient | ||
| if reqRec := recording.GetRequests(ctx); reqRec != nil { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to meter traffic, we need to have it inside object reader/writer, the old context var not fit in this scenario, so it's better pass it as a option |
||
| if opts.AccessRecording != nil { | ||
| if httpClient == nil { | ||
| transport, _ := http.DefaultTransport.(*http.Transport) | ||
| httpClient = &http.Client{Transport: transport.Clone()} | ||
| } | ||
| httpClient.Transport = &roundTripperWrapper{ | ||
| RoundTripper: httpClient.Transport, | ||
| requestsRec: reqRec, | ||
| accessRec: opts.AccessRecording, | ||
| } | ||
| } | ||
| if httpClient != nil { | ||
|
|
@@ -460,6 +464,7 @@ skipHandleCred: | |
| idx: atomic.NewInt64(0), | ||
| clientCnt: gcsClientCnt, | ||
| clientOps: clientOps, | ||
| accessRec: opts.AccessRecording, | ||
| } | ||
| if err := ret.Reset(ctx); err != nil { | ||
| return nil, errors.Trace(err) | ||
|
|
@@ -632,6 +637,7 @@ func (r *gcsObjectReader) Read(p []byte) (n int, err error) { | |
| } | ||
| } | ||
| n, err = r.reader.Read(p) | ||
| r.storage.accessRec.RecRead(n) | ||
| r.pos += int64(n) | ||
| return n, err | ||
| } | ||
|
|
@@ -700,10 +706,10 @@ func (r *gcsObjectReader) GetFileSize() (int64, error) { | |
|
|
||
| type roundTripperWrapper struct { | ||
| http.RoundTripper | ||
| requestsRec *recording.Requests | ||
| accessRec *recording.AccessStats | ||
| } | ||
|
|
||
| func (rt *roundTripperWrapper) RoundTrip(req *http.Request) (*http.Response, error) { | ||
| rt.requestsRec.Rec(req) | ||
| rt.accessRec.RecRequest(req) | ||
| return rt.RoundTripper.RoundTrip(req) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Will we lose the records of bytes/requests for compression options?
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 add a comment, this
withCompressionis a wrapper aroundExternalStoragewhich will do the recording