-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The upload completer scans for uploads that need to be completed, likely due to an error or process restart. Prior to this change, it only completed uploads that had 1 or more parts. Since completing an upload is what cleans up the directory on disk (or in the case of cloud storage, finishes the multipart upload), it was possible for us to leave behind empty directories (or multipart uploads) for uploads with no parts. This change makes it valid to complete uploads with no parts, which ensures that these directories get cleaned up. Also fix an issue with the GCS uploader, which failed to properly calculate the upload ID from the path. This is because strings.Split(s, "/") returns an empty string as the last element when s ends with a /. Updates #9646
- Loading branch information
Showing
8 changed files
with
158 additions
and
45 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
Copyright 2022 Gravitational, Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package events | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
apievents "github.com/gravitational/teleport/api/types/events" | ||
"github.com/gravitational/teleport/lib/session" | ||
"github.com/jonboulle/clockwork" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// TestUploadCompleterCompletesEmptyUploads verifies that the upload completer | ||
// completes uploads that have no parts. This ensures that we don't leave empty | ||
// directories behind. | ||
func TestUploadCompleterCompletesEmptyUploads(t *testing.T) { | ||
clock := clockwork.NewFakeClock() | ||
mu := NewMemoryUploader() | ||
mu.Clock = clock | ||
|
||
log := &MockAuditLog{} | ||
|
||
uc, err := NewUploadCompleter(UploadCompleterConfig{ | ||
Unstarted: true, | ||
Uploader: mu, | ||
AuditLog: log, | ||
GracePeriod: 2 * time.Hour, | ||
}) | ||
require.NoError(t, err) | ||
|
||
upload, err := mu.CreateUpload(context.Background(), session.NewID()) | ||
require.NoError(t, err) | ||
clock.Advance(3 * time.Hour) | ||
|
||
err = uc.CheckUploads(context.Background()) | ||
require.NoError(t, err) | ||
|
||
require.True(t, mu.uploads[upload.ID].completed) | ||
} | ||
|
||
type MockAuditLog struct { | ||
DiscardAuditLog | ||
|
||
emitter MockEmitter | ||
sessionEvents []EventFields | ||
} | ||
|
||
func (m *MockAuditLog) GetSessionEvents(namespace string, sid session.ID, after int, includePrintEvents bool) ([]EventFields, error) { | ||
return m.sessionEvents, nil | ||
} | ||
|
||
func (m *MockAuditLog) EmitAuditEvent(ctx context.Context, event apievents.AuditEvent) error { | ||
return m.emitter.EmitAuditEvent(ctx, event) | ||
} |
This file contains 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 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 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 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 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 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