8000 Add option to specify interval for transfer jobs by cristinaleonr · Pull Request #78 · m-lab/gcp-config · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add option to specify interval for transfer jobs #78

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 7 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM golang:1.20

ADD . /go/src/github.com/m-lab/gcp-config
WORKDIR /go/src/github.com/m-lab/gcp-config/
RUN go install -v github.com/m-lab/gcp-config/cmd/stctl@v1.3.12
RUN go install -v github.com/m-lab/gcp-config/cmd/cbif@v1.3.12
RUN go install -v ./cmd/stctl
RUN go install -v ./cmd/cbif
ENV SINGLE_COMMAND true
ENTRYPOINT ["/go/bin/cbif"]
5 changes: 4 additions & 1 deletion cmd/stctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// 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
// 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,
Expand Down Expand Up @@ -36,6 +36,7 @@ var (
destBucket string
prefixes flagx.StringArray
startTime flagx.Time
interval string
afterDate flagx.DateTime
minAge time.Duration
maxAge time.Duration
Expand All @@ -48,6 +49,7 @@ func init() {
flag.StringVar(&destBucket, "gcs.target", "", "Destination bucket.")
flag.Var(&prefixes, "include", "Only transfer files with given prefix. Default all prefixes. Can be specified multiple times.")
flag.Var(&startTime, "time", "Start daily transfer at this time (HH:MM:SS)")
flag.StringVar(&interval, "interval", "", "Interval between the start of each scheduled transfer operation.")
flag.Var(&afterDate, "after", "Only list operations that ran after the given date. Default is all dates.")
flag.DurationVar(&minAge, "minFileAge", 0, "Minimum time since file modification")
flag.DurationVar(&maxAge, "maxFileAge", 0, "Maximum time since file modification")
Expand Down Expand Up @@ -107,6 +109,7 @@ func main() {
TargetBucket: destBucket,
Prefixes: prefixes,
StartTime: startTime,
Interval: interval,
AfterDate: afterDate.Time,
MinFileAge: minAge.Truncate(time.Second),
MaxFileAge: maxAge.Truncate(time.Second),
Expand Down
13 changes: 3 additions & 10 deletions daily-archive-transfers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,14 @@ steps:

# Nodes upload to the pusher-* bucket every 2 hours.
# Configure hourly pusher to local archive transfer.
# NOTE: the hourly setting has been set by editing the job created
# in the web UI (because it is not supported by stctl), so this
# declaration is not identical to what is in the corresponding GCP
# config.
# TODO(cristinaleon): Add hourly schedule functionality to stctl.
- name: gcp-config-cbif
env:
- PROJECT_IN=mlab-sandbox,mlab-staging,mlab-oti
args: [
'stctl', '-gcs.source=pusher-$PROJECT_ID',
'-gcs.target=archive-$PROJECT_ID',
'-time=00:00:00',
'-interval=3600s',
'-include=autoload',
'-deleteAfterTransfer=true',
'sync'
Expand All @@ -70,6 +66,7 @@ steps:
'-gcs.target=archive-measurement-lab',
'-include=revtr',
'-time=02:30:00',
'-interval=3600s',
'-maxFileAge=27h',
'sync'
]
Expand Down Expand Up @@ -132,18 +129,14 @@ steps:
]

# Hourly local archive to public archive transfer for autoloaded data.
# NOTE: the hourly setting has been set by editing the job created
# in the web UI (because it is not supported by stctl), so this
# declaration is not identical to what is in the corresponding GCP
# config.
# TODO(cristinaleon): Add hourly schedule functionality to stctl.
- name: gcp-config-cbif
env:
- PROJECT_IN=measurement-lab
args: [
'stctl', '-gcs.source=archive-mlab-oti',
'-gcs.target=archive-measurement-lab',
'-time=00:00:00',
'-interval=3600s',
'-include=autoload',
'-deleteAfterTransfer=true',
'sync'
Expand Down
1 change: 1 addition & 0 deletions internal/stctl/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type Command struct {
TargetBucket string
Prefixes []string
StartTime flagx.Time
Interval string
AfterDate time.Time
MinFileAge time.Duration
MaxFileAge time.Duration
Expand Down
1 change: 1 addition & 0 deletions internal/stctl/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func (c *Command) Create(ctx context.Context) (*storagetransfer.TransferJob, err
Minutes: int64(c.StartTime.Minute),
Seconds: int64(c.StartTime.Second),
},
RepeatInterval: c.Interval,
},
Status: "ENABLED",
TransferSpec: &spec,
Expand Down
6 changes: 6 additions & 0 deletions internal/stctl/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ func (c *Command) specMatches(job *storagetransfer.TransferJob) bool {
logx.Debug.Println("spec: times not equal", job.Schedule, c.StartTime)
return false
}

if c.Interval != "" && job.Schedule.RepeatInterval != c.Interval {
logx.Debug.Println("spec: interval not equal", job.Schedule.RepeatInterval, c.Interval)
return false
}

cond := job.TransferSpec.ObjectConditions
if cond == nil {
if len(c.Prefixes) > 0 || c.MaxFileAge > 0 || c.MinFil 6D40 eAge > 0 {
Expand Down
48 changes: 48 additions & 0 deletions internal/stctl/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,54 @@ func TestCommand_Sync(t *testing.T) {
Status: "ENABLED",
},
},
{
name: "success-update-interval",
c: &Command{
SourceBucket: "fake-source",
TargetBucket: "fake-target",
StartTime: flagx.Time{Hour: 1, Minute: 2, Second: 3},
Interval: "3600s",
Client: &fakeTJ{
// fake job listed to search for one that matches the current Command spec.
listJobResp: &storagetransfer.ListTransferJobsResponse{
TransferJobs: []*storagetransfer.TransferJob{
{
Name: "transferOperations/update-interval",
Description: getDesc("fake-source", "fake-target", flagx.Time{Hour: 1, Minute: 2, Second: 3}),
Schedule: &storagetransfer.Schedule{
StartTimeOfDay: &storagetransfer.TimeOfDay{Hours: 1, Minutes: 2, Seconds: 3},
},
TransferSpec: &storagetransfer.TransferSpec{
GcsDataSource: &storagetransfer.GcsData{BucketName: "fake-source"},
GcsDataSink: &storagetransfer.GcsData{BucketName: "fake-target"},
},
},
},
},
// a fake job that is disabled.
job: &storagetransfer.TransferJob{},
},
},
shouldFind: true,
expected: &storagetransfer.TransferJob{
Description: "STCTL: transfer fake-source -> fake-target at 01:02:03",
Name: "THIS-IS-A-FAKE-ASSIGNED-JOB-NAME",
Schedule: &storagetransfer.Schedule{
StartTimeOfDay: &storagetransfer.TimeOfDay{Hours: 1, Minutes: 2, Seconds: 3},
ScheduleStartDate: &storagetransfer.Date{
Day: int64(ts.Day()),
Month: int64(ts.Month()),
Year: int64(ts.Year()),
},
RepeatInterval: "3600s",
},
TransferSpec: &storagetransfer.TransferSpec{
GcsDataSource: &storagetransfer.GcsData{BucketName: "fake-source"},
GcsDataSink: &storagetransfer.GcsData{BucketName: "fake-target"},
},
Status: "ENABLED",
},
},
{
name: "success-job-not-found-then-created",
c: &Command{
Expand Down
0