Skip to content

Commit a5a621c

Browse files
committed
Use logrusctx on task
1 parent bd37b68 commit a5a621c

File tree

11 files changed

+90
-75
lines changed

11 files changed

+90
-75
lines changed

go.mod

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module terraform-provider-iterative
33
go 1.19
44

55
require (
6+
github.com/0x2b3bfa0/logrusctx v0.1.0
67
github.com/Azure/azure-sdk-for-go v58.1.0+incompatible
78
github.com/Azure/go-autorest/autorest v0.11.20
89
github.com/Azure/go-autorest/autorest/azure/auth v0.5.8
@@ -23,7 +24,6 @@ require (
2324
github.com/docker/go-units v0.4.0
2425
github.com/dustinkirkland/golang-petname v0.0.0-20191129215211-8e5a1ed0cff0
2526
github.com/gobwas/glob v0.2.3
26-
github.com/golang/mock v1.6.0 // indirect
2727
github.com/google/go-github/v42 v42.0.0
2828
github.com/google/go-github/v45 v45.2.0
2929
github.com/google/uuid v1.3.0
@@ -32,13 +32,13 @@ require (
3232
github.com/rclone/rclone v1.57.0
3333
github.com/sebdah/goldie/v2 v2.5.3
3434
github.com/shirou/gopsutil v3.21.11+incompatible
35-
github.com/sirupsen/logrus v1.8.1
35+
github.com/sirupsen/logrus v1.9.0
3636
github.com/spf13/cobra v1.5.0
3737
github.com/spf13/pflag v1.0.5
3838
github.com/spf13/viper v1.11.0
39-
github.com/stretchr/testify v1.7.1
39+
github.com/stretchr/testify v1.8.1
4040
github.com/wessie/appdirs v0.0.0-20141031215813-6573e894f8e2
41-
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4
41+
golang.org/x/crypto v0.1.0
4242
golang.org/x/oauth2 v0.0.0-20220909003341-f21342109be1
4343
google.golang.org/api v0.96.0
4444
gopkg.in/alessio/shellescape.v1 v1.0.0-20170105083845-52074bc9df61
@@ -103,7 +103,7 @@ require (
103103
github.com/go-ole/go-ole v1.2.6 // indirect
104104
github.com/go-openapi/jsonpointer v0.19.5 // indirect
105105
github.com/go-openapi/jsonreference v0.19.5 // indirect
106-
github.com/go-openapi/swag v0.19.14 // indirect
106+
github.com/go-openapi/swag v0.21.1 // indirect
107107
github.com/gogo/protobuf v1.3.2 // indirect
108108
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
109109
github.com/golang/protobuf v1.5.2 // indirect
@@ -144,10 +144,10 @@ require (
144144
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
145145
github.com/lithammer/dedent v1.1.0 // indirect
146146
github.com/magiconair/properties v1.8.6 // indirect
147-
github.com/mailru/easyjson v0.7.6 // indirect
148-
github.com/mattn/go-colorable v0.1.12 // indirect
147+
github.com/mailru/easyjson v0.7.7 // indirect
148+
github.com/mattn/go-colorable v0.1.13 // indirect
149149
github.com/mattn/go-ieproxy v0.0.1 // indirect
150-
github.com/mattn/go-isatty v0.0.14 // indirect
150+
github.com/mattn/go-isatty v0.0.16 // indirect
151151
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
152152
github.com/mitchellh/copystructure v1.2.0 // indirect
153153
github.com/mitchellh/go-homedir v1.1.0 // indirect
@@ -162,7 +162,7 @@ require (
162162
github.com/ncw/swift/v2 v2.0.1 // indirect
163163
github.com/oklog/run v1.0.0 // indirect
164164
github.com/pelletier/go-toml v1.9.4 // indirect
165-
github.com/pelletier/go-toml/v2 v2.0.0-beta.8 // indirect
165+
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
166166
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
167167
github.com/pkg/errors v0.9.1 // indirect
168168
github.com/pmezard/go-difflib v1.0.0 // indirect
@@ -188,12 +188,12 @@ require (
188188
github.com/zclconf/go-cty v1.9.1 // indirect
189189
go.opencensus.io v0.23.0 // indirect
190190
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
191-
golang.org/x/net v0.0.0-20220920203100-d0c6ba3f52d9 // indirect
191+
golang.org/x/net v0.1.0 // indirect
192192
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f // indirect
193-
golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8 // indirect
194-
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
195-
golang.org/x/text v0.3.7 // indirect
196-
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
193+
golang.org/x/sys v0.1.0 // indirect
194+
golang.org/x/term v0.1.0 // indirect
195+
golang.org/x/text v0.4.0 // indirect
196+
golang.org/x/time v0.0.0-20220411224347-583f2d630306 // indirect
197197
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
198198
google.golang.org/appengine v1.6.7 // indirect
199199
google.golang.org/genproto v0.0.0-20220920201722-2b89144ce006 // indirect
@@ -202,7 +202,7 @@ require (
202202
gopkg.in/inf.v0 v0.9.1 // indirect
203203
gopkg.in/ini.v1 v1.66.4 // indirect
204204
gopkg.in/yaml.v2 v2.4.0 // indirect
205-
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
205+
gopkg.in/yaml.v3 v3.0.1 // indirect
206206
k8s.io/component-base v0.22.3 // indirect
207207
k8s.io/klog/v2 v2.9.0 // indirect
208208
k8s.io/kube-openapi v0.0.0-20210421082810-95288971da7e // indirect

go.sum

Lines changed: 36 additions & 22 deletions
Large diffs are not rendered by default.

task/aws/resources/resource_auto_scaling_group.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/aws/aws-sdk-go-v2/service/autoscaling/types"
1414
"github.com/aws/aws-sdk-go-v2/service/ec2"
1515
"github.com/aws/smithy-go"
16-
"github.com/sirupsen/logrus"
16+
"github.com/0x2b3bfa0/logrusctx"
1717

1818
"terraform-provider-iterative/task/aws/client"
1919
"terraform-provider-iterative/task/common"
@@ -139,7 +139,7 @@ func (a *AutoScalingGroup) Read(ctx context.Context) error {
139139
if instance.StateReason != nil {
140140
status += " " + aws.ToString(instance.StateReason.Message)
141141
}
142-
logrus.Debug("AutoScaling Group State:", status)
142+
logrusctx.Debug(ctx, "AutoScaling Group State:", status)
143143
if status == "running" {
144144
a.Attributes.Status[common.StatusCodeActive]++
145145
}

task/aws/task.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"errors"
66
"net"
77

8-
"github.com/sirupsen/logrus"
8+
"github.com/0x2b3bfa0/logrusctx"
99

1010
"terraform-provider-iterative/task/aws/client"
1111
"terraform-provider-iterative/task/aws/resources"
@@ -133,7 +133,7 @@ type Task struct {
133133
}
134134

135135
func (t *Task) Create(ctx context.Context) error {
136-
logrus.Info("Creating resources...")
136+
logrusctx.Info(ctx, "Creating resources...")
137137
steps := []common.Step{{
138138
Description: "Parsing PermissionSet...",
139139
Action: t.DataSources.PermissionSet.Read,
@@ -188,15 +188,15 @@ func (t *Task) Create(ctx context.Context) error {
188188
if err := common.RunSteps(ctx, steps); err != nil {
189189
return err
190190
}
191-
logrus.Info("Creation completed")
191+
logrusctx.Info(ctx, "Creation completed")
192192
t.Attributes.Addresses = t.Resources.AutoScalingGroup.Attributes.Addresses
193193
t.Attributes.Status = t.Resources.AutoScalingGroup.Attributes.Status
194194
t.Attributes.Events = t.Resources.AutoScalingGroup.Attributes.Events
195195
return nil
196196
}
197197

198198
func (t *Task) Read(ctx context.Context) error {
199-
logrus.Info("Reading resources... (this may happen several times)")
199+
logrusctx.Info(ctx, "Reading resources... (this may happen several times)")
200200
steps := []common.Step{{
201201
Description: "Reading DefaultVPC...",
202202
Action: t.DataSources.DefaultVPC.Read,
@@ -235,15 +235,15 @@ func (t *Task) Read(ctx context.Context) error {
235235
if err := common.RunSteps(ctx, steps); err != nil {
236236
return err
237237
}
238-
logrus.Info("Read completed")
238+
logrusctx.Info(ctx, "Read completed")
239239
t.Attributes.Addresses = t.Resources.AutoScalingGroup.Attributes.Addresses
240240
t.Attributes.Status = t.Resources.AutoScalingGroup.Attributes.Status
241241
t.Attributes.Events = t.Resources.AutoScalingGroup.Attributes.Events
242242
return nil
243243
}
244244

245245
func (t *Task) Delete(ctx context.Context) error {
246-
logrus.Info("Deleting resources...")
246+
logrusctx.Info(ctx, "Deleting resources...")
247247
steps := []common.Step{}
248248
if t.Read(ctx) == nil {
249249
if t.Attributes.Environment.DirectoryOut != "" {
@@ -294,7 +294,7 @@ func (t *Task) Delete(ctx context.Context) error {
294294
if err := common.RunSteps(ctx, steps); err != nil {
295295
return err
296296
}
297-
logrus.Info("Deletion completed")
297+
logrusctx.Info(ctx, "Deletion completed")
298298
return nil
299299
}
300300

task/az/resources/resource_virtual_machine_scale_set.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/Azure/go-autorest/autorest"
1515
"github.com/Azure/go-autorest/autorest/to"
1616

17-
"github.com/sirupsen/logrus"
17+
"github.com/0x2b3bfa0/logrusctx"
1818

1919
"terraform-provider-iterative/task/az/client"
2020
"terraform-provider-iterative/task/common"
@@ -255,7 +255,7 @@ func (v *VirtualMachineScaleSet) Read(ctx context.Context) error {
255255
if scaleSetView.VirtualMachine.StatusesSummary != nil {
256256
for _, status := range *scaleSetView.VirtualMachine.StatusesSummary {
257257
code := to.String(status.Code)
258-
logrus.Debug("ScaleSet Status Summary:", code, int(to.Int32(status.Count)))
258+
logrusctx.Debug(ctx, "ScaleSet Status Summary:", code, int(to.Int32(status.Count)))
259259
if code == "ProvisioningState/succeeded" {
260260
v.Attributes.Status[common.StatusCodeActive] = int(to.Int32(status.Count))
261261
}

task/az/task.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"context"
55
"net"
66

7-
"github.com/sirupsen/logrus"
7+
"github.com/0x2b3bfa0/logrusctx"
88

99
"terraform-provider-iterative/task/az/client"
1010
"terraform-provider-iterative/task/az/resources"
@@ -123,7 +123,7 @@ type Task struct {
123123
}
124124

125125
func (t *Task) Create(ctx context.Context) error {
126-
logrus.Info("Creating resources...")
126+
logrusctx.Info(ctx, "Creating resources...")
127127
steps := []common.Step{{
128128
Description: "Creating ResourceGroup...",
129129
Action: t.Resources.ResourceGroup.Create,
@@ -172,15 +172,15 @@ func (t *Task) Create(ctx context.Context) error {
172172
if err := common.RunSteps(ctx, steps); err != nil {
173173
return err
174174
}
175-
logrus.Info("Creation completed")
175+
logrusctx.Info(ctx, "Creation completed")
176176
t.Attributes.Addresses = t.Resources.VirtualMachineScaleSet.Attributes.Addresses
177177
t.Attributes.Status = t.Resources.VirtualMachineScaleSet.Attributes.Status
178178
t.Attributes.Events = t.Resources.VirtualMachineScaleSet.Attributes.Events
179179
return nil
180180
}
181181

182182
func (t *Task) Read(ctx context.Context) error {
183-
logrus.Info("Reading resources... (this may happen several times)")
183+
logrusctx.Info(ctx, "Reading resources... (this may happen several times)")
184184
steps := []common.Step{{
185185
Description: "Reading ResourceGroup...",
186186
Action: t.Resources.ResourceGroup.Read,
@@ -219,15 +219,15 @@ func (t *Task) Read(ctx context.Context) error {
219219
if err := common.RunSteps(ctx, steps); err != nil {
220220
return err
221221
}
222-
logrus.Info("Read completed")
222+
logrusctx.Info(ctx, "Read completed")
223223
t.Attributes.Addresses = t.Resources.VirtualMachineScaleSet.Attributes.Addresses
224224
t.Attributes.Status = t.Resources.VirtualMachineScaleSet.Attributes.Status
225225
t.Attributes.Events = t.Resources.VirtualMachineScaleSet.Attributes.Events
226226
return nil
227227
}
228228

229229
func (t *Task) Delete(ctx context.Context) error {
230-
logrus.Info("Deleting resources...")
230+
logrusctx.Info(ctx, "Deleting resources...")
231231
steps := []common.Step{}
232232

233233
if t.Read(ctx) == nil {
@@ -286,7 +286,7 @@ func (t *Task) Delete(ctx context.Context) error {
286286
if err := common.RunSteps(ctx, steps); err != nil {
287287
return err
288288
}
289-
logrus.Info("Deletion completed")
289+
logrusctx.Info(ctx, "Deletion completed")
290290
return nil
291291
}
292292

task/common/machine/storage.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/rclone/rclone/fs/sync"
2828

2929
"github.com/sirupsen/logrus"
30+
"github.com/0x2b3bfa0/logrusctx"
3031

3132
"terraform-provider-iterative/task/common"
3233
)
@@ -147,7 +148,7 @@ func Transfer(ctx context.Context, source, destination string, exclude []string)
147148
}
148149

149150
if count, size, err := operations.Count(ctx, sourceFileSystem); err == nil {
150-
logrus.Infof("Transferring %s (%d files)...", units.HumanSize(float64(size)), count)
151+
logrusctx.Infof(ctx, "Transferring %s (%d files)...", units.HumanSize(float64(size)), count)
151152
} else {
152153
return err
153154
}

task/common/steps.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package common
33
import (
44
"context"
55

6-
"github.com/sirupsen/logrus"
6+
"github.com/0x2b3bfa0/logrusctx"
77
)
88

99
// Step defines a single resource creation step.
@@ -16,7 +16,7 @@ type Step struct {
1616
func RunSteps(ctx context.Context, steps []Step) error {
1717
total := len(steps)
1818
for i, step := range steps {
19-
logrus.Infof("[%d/%d] %s", i+1, total, step.Description)
19+
logrusctx.Infof(ctx, "[%d/%d] %s", i+1, total, step.Description)
2020
if err := step.Action(ctx); err != nil {
2121
logrus.Debug("step: ", step.Description, " error: ", err)
2222
return err

task/gcp/resources/resource_instance_group_manager.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"strings"
99
"time"
1010

11-
"github.com/sirupsen/logrus"
11+
"github.com/0x2b3bfa0/logrusctx"
1212

1313
"google.golang.org/api/compute/v1"
1414
"google.golang.org/api/googleapi"
@@ -80,7 +80,7 @@ func (i *InstanceGroupManager) Read(ctx context.Context) error {
8080
i.Attributes.Addresses = []net.IP{}
8181
i.Attributes.Status = common.Status{common.StatusCodeActive: 0}
8282
for _, groupInstance := range groupInstances.Items {
83-
logrus.Debug("Instance Group Manager Status:", groupInstance.Status)
83+
logrusctx.Debug(ctx, "Instance Group Manager Status:", groupInstance.Status)
8484
if groupInstance.Status == "RUNNING" {
8585
instance, err := i.client.Services.Compute.Instances.Get(i.client.Credentials.ProjectID, i.client.Region, filepath.Base(groupInstance.Instance)).Do()
8686
if err != nil {

task/gcp/task.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"errors"
66
"net"
77

8-
"github.com/sirupsen/logrus"
8+
"github.com/0x2b3bfa0/logrusctx"
99

1010
"terraform-provider-iterative/task/common"
1111
"terraform-provider-iterative/task/common/machine"
@@ -179,7 +179,7 @@ type Task struct {
179179
}
180180

181181
func (t *Task) Create(ctx context.Context) error {
182-
logrus.Info("Creating resources...")
182+
logrusctx.Info(ctx, "Creating resources...")
183183
steps := []common.Step{{
184184
Description: "Parsing PermissionSet...",
185185
Action: t.DataSources.PermissionSet.Read,
@@ -243,15 +243,15 @@ func (t *Task) Create(ctx context.Context) error {
243243
if err := common.RunSteps(ctx, steps); err != nil {
244244
return err
245245
}
246-
logrus.Info("Creation completed")
246+
logrusctx.Info(ctx, "Creation completed")
247247
t.Attributes.Addresses = t.Resources.InstanceGroupManager.Attributes.Addresses
248248
t.Attributes.Status = t.Resources.InstanceGroupManager.Attributes.Status
249249
t.Attributes.Events = t.Resources.InstanceGroupManager.Attributes.Events
250250
return nil
251251
}
252252

253253
func (t *Task) Read(ctx context.Context) error {
254-
logrus.Info("Reading resources... (this may happen several times)")
254+
logrusctx.Info(ctx, "Reading resources... (this may happen several times)")
255255
steps := []common.Step{{
256256
Description: "Reading DefaultNetwork...",
257257
Action: t.DataSources.DefaultNetwork.Read,
@@ -299,15 +299,15 @@ func (t *Task) Read(ctx context.Context) error {
299299
if err := common.RunSteps(ctx, steps); err != nil {
300300
return err
301301
}
302-
logrus.Info("Read completed")
302+
logrusctx.Info(ctx, "Read completed")
303303
t.Attributes.Addresses = t.Resources.InstanceGroupManager.Attributes.Addresses
304304
t.Attributes.Status = t.Resources.InstanceGroupManager.Attributes.Status
305305
t.Attributes.Events = t.Resources.InstanceGroupManager.Attributes.Events
306306
return nil
307307
}
308308

309309
func (t *Task) Delete(ctx context.Context) error {
310-
logrus.Info("Deleting resources...")
310+
logrusctx.Info(ctx, "Deleting resources...")
311311
steps := []common.Step{}
312312
if t.Read(ctx) == nil {
313313
if t.Attributes.Environment.DirectoryOut != "" {
@@ -366,7 +366,7 @@ func (t *Task) Delete(ctx context.Context) error {
366366
if err := common.RunSteps(ctx, steps); err != nil {
367367
return err
368368
}
369-
logrus.Info("Deletion completed")
369+
logrusctx.Info(ctx, "Deletion completed")
370370
return nil
371371
}
372372

0 commit comments

Comments
 (0)