Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3db3e6b

Browse files
committed
bring back logging
1 parentbc69d1e commit3db3e6b

File tree

3 files changed

+48
-14
lines changed

3 files changed

+48
-14
lines changed

‎provisioner/terraform/parse.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func (s *server) Parse(sess *provisionersdk.Session, _ *proto.ParseRequest, _ <-
2626
returnprovisionersdk.ParseErrorf("load module: %s",formatDiagnostics(sess.WorkDirectory,diags))
2727
}
2828

29-
workspaceTags,err:=tfparse.WorkspaceTags(nil,module)
29+
workspaceTags,err:=tfparse.WorkspaceTags(ctx,s.logger,nil,module)
3030
iferr!=nil {
3131
returnprovisionersdk.ParseErrorf("can't load workspace tags: %v",err)
3232
}

‎provisioner/terraform/tfparse/tfextract.go‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,15 @@ type Parser interface {
4343
// Note that this only returns the lexical values of the data source, and does not
4444
// evaluate variables and such. To do this, see evalProvisionerTags below.
4545
// If the provided Parser is nil, a new instance of hclparse.Parser will be used instead.
46-
funcWorkspaceTags(parserParser,module*tfconfig.Module) (map[string]string,error) {
46+
funcWorkspaceTags(ctx context.Context,logger slog.Logger,parserParser,module*tfconfig.Module) (map[string]string,error) {
4747
ifparser==nil {
4848
parser=hclparse.NewParser()
4949
}
5050
tags:=map[string]string{}
51-
51+
varskipped []string
5252
for_,dataResource:=rangemodule.DataResources {
5353
ifdataResource.Type!="coder_workspace_tags" {
54+
skipped=append(skipped,strings.Join([]string{"data",dataResource.Type,dataResource.Name},"."))
5455
continue
5556
}
5657

@@ -118,6 +119,7 @@ func WorkspaceTags(parser Parser, module *tfconfig.Module) (map[string]string, e
118119
}
119120
}
120121
}
122+
logger.Debug(ctx,"found workspace tags",slog.F("tags",maps.Keys(tags)),slog.F("skipped",skipped))
121123
returntags,nil
122124
}
123125

@@ -145,18 +147,18 @@ func WorkspaceTagDefaultsFromFile(ctx context.Context, logger slog.Logger, file
145147

146148
// This only gets us the expressions. We need to evaluate them.
147149
// Example: var.region -> "us"
148-
tags,err=WorkspaceTags(parser,module)
150+
tags,err=WorkspaceTags(ctx,logger,parser,module)
149151
iferr!=nil {
150152
returnnil,xerrors.Errorf("extract workspace tags: %w",err)
151153
}
152154

153155
// To evaluate the expressions, we need to load the default values for
154156
// variables and parameters.
155-
varsDefaults,err:=loadVarsDefaults(maps.Values(module.Variables))
157+
varsDefaults,err:=loadVarsDefaults(ctx,logger,maps.Values(module.Variables))
156158
iferr!=nil {
157159
returnnil,xerrors.Errorf("load variable defaults: %w",err)
158160
}
159-
paramsDefaults,err:=loadParamsDefaults(parser,maps.Values(module.DataResources))
161+
paramsDefaults,err:=loadParamsDefaults(ctx,logger,parser,maps.Values(module.DataResources))
160162
iferr!=nil {
161163
returnnil,xerrors.Errorf("load parameter defaults: %w",err)
162164
}
@@ -176,8 +178,6 @@ func WorkspaceTagDefaultsFromFile(ctx context.Context, logger slog.Logger, file
176178
}
177179
returnnil,xerrors.Errorf("provisioner tag %q evaluated to an empty value, please set a default value",k)
178180
}
179-
logger.Info(ctx,"found workspace tags",slog.F("tags",evalTags))
180-
181181
returnevalTags,nil
182182
}
183183

@@ -224,7 +224,7 @@ func loadModuleFromFile(file []byte, mimetype string) (module *tfconfig.Module,
224224
}
225225

226226
// loadVarsDefaults returns the default values for all variables passed to it.
227-
funcloadVarsDefaults(variables []*tfconfig.Variable) (map[string]string,error) {
227+
funcloadVarsDefaults(ctx context.Context,logger slog.Logger,variables []*tfconfig.Variable) (map[string]string,error) {
228228
// iterate through vars to get the default values for all
229229
// variables.
230230
m:=make(map[string]string)
@@ -238,18 +238,21 @@ func loadVarsDefaults(variables []*tfconfig.Variable) (map[string]string, error)
238238
}
239239
m[v.Name]=strings.Trim(sv,`"`)
240240
}
241+
logger.Debug(ctx,"found default values for variables",slog.F("defaults",m))
241242
returnm,nil
242243
}
243244

244245
// loadParamsDefaults returns the default values of all coder_parameter data sources data sources provided.
245-
funcloadParamsDefaults(parserParser,dataSources []*tfconfig.Resource) (map[string]string,error) {
246+
funcloadParamsDefaults(ctx context.Context,logger slog.Logger,parserParser,dataSources []*tfconfig.Resource) (map[string]string,error) {
246247
defaultsM:=make(map[string]string)
248+
varskipped []string
247249
for_,dataResource:=rangedataSources {
248250
ifdataResource==nil {
249251
continue
250252
}
251253

252254
ifdataResource.Type!="coder_parameter" {
255+
skipped=append(skipped,strings.Join([]string{"data",dataResource.Type,dataResource.Name},"."))
253256
continue
254257
}
255258

@@ -296,6 +299,7 @@ func loadParamsDefaults(parser Parser, dataSources []*tfconfig.Resource) (map[st
296299
}
297300
}
298301
}
302+
logger.Debug(ctx,"found default values for parameters",slog.F("defaults",defaultsM),slog.F("skipped",skipped))
299303
returndefaultsM,nil
300304
}
301305

‎provisioner/terraform/tfparse/tfparse_test.go‎

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ func Test_WorkspaceTagDefaultsFromFile(t *testing.T) {
5252
type = string
5353
default = "us"
5454
}
55+
data "base" "ours" {
56+
all = true
57+
}
5558
data "coder_parameter" "az" {
5659
name = "az"
5760
type = "string"
@@ -71,6 +74,9 @@ func Test_WorkspaceTagDefaultsFromFile(t *testing.T) {
7174
type = string
7275
default = "us"
7376
}
77+
data "base" "ours" {
78+
all = true
79+
}
7480
data "coder_parameter" "az" {
7581
name = "az"
7682
type = "string"
@@ -91,6 +97,9 @@ func Test_WorkspaceTagDefaultsFromFile(t *testing.T) {
9197
type = string
9298
default = "us"
9399
}
100+
data "base" "ours" {
101+
all = true
102+
}
94103
data "coder_parameter" "az" {
95104
name = "az"
96105
type = "string"
@@ -122,6 +131,9 @@ func Test_WorkspaceTagDefaultsFromFile(t *testing.T) {
122131
type = string
123132
default = "eu"
124133
}
134+
data "base" "ours" {
135+
all = true
136+
}
125137
data "coder_parameter" "az" {
126138
name = "az"
127139
type = "string"
@@ -159,6 +171,9 @@ func Test_WorkspaceTagDefaultsFromFile(t *testing.T) {
159171
type = string
160172
default = "us"
161173
}
174+
data "base" "ours" {
175+
all = true
176+
}
162177
data "coder_parameter" "az" {
163178
name = "az"
164179
type = "string"
@@ -184,6 +199,9 @@ func Test_WorkspaceTagDefaultsFromFile(t *testing.T) {
184199
type = string
185200
default = "us"
186201
}
202+
data "base" "ours" {
203+
all = true
204+
}
187205
data "coder_parameter" "az" {
188206
name = "az"
189207
type = "string"
@@ -218,6 +236,9 @@ func Test_WorkspaceTagDefaultsFromFile(t *testing.T) {
218236
variable "notregion" {
219237
type = string
220238
}
239+
data "base" "ours" {
240+
all = true
241+
}
221242
data "coder_parameter" "az" {
222243
name = "az"
223244
type = "string"
@@ -247,6 +268,9 @@ func Test_WorkspaceTagDefaultsFromFile(t *testing.T) {
247268
type = string
248269
default = "us"
249270
}
271+
data "base" "ours" {
272+
all = true
273+
}
250274
data "coder_parameter" "az" {
251275
name = "az"
252276
type = "string"
@@ -280,6 +304,9 @@ func Test_WorkspaceTagDefaultsFromFile(t *testing.T) {
280304
type = string
281305
default = "us"
282306
}
307+
data "base" "ours" {
308+
all = true
309+
}
283310
data "coder_parameter" "az" {
284311
name = "az"
285312
type = "string"
@@ -311,6 +338,9 @@ func Test_WorkspaceTagDefaultsFromFile(t *testing.T) {
311338
type = string
312339
default = "region.us"
313340
}
341+
data "base" "ours" {
342+
all = true
343+
}
314344
data "coder_parameter" "az" {
315345
name = "az"
316346
type = "string"
@@ -334,7 +364,7 @@ func Test_WorkspaceTagDefaultsFromFile(t *testing.T) {
334364
t.Parallel()
335365
ctx:=testutil.Context(t,testutil.WaitShort)
336366
tar:=createTar(t,tc.files)
337-
logger:=slogtest.Make(t,nil)
367+
logger:=slogtest.Make(t,nil).Leveled(slog.LevelDebug)
338368
tags,err:=tfparse.WorkspaceTagDefaultsFromFile(ctx,logger,tar,"application/x-tar")
339369
iftc.expectError!="" {
340370
require.NotNil(t,err)
@@ -348,7 +378,7 @@ func Test_WorkspaceTagDefaultsFromFile(t *testing.T) {
348378
t.Parallel()
349379
ctx:=testutil.Context(t,testutil.WaitShort)
350380
zip:=createZip(t,tc.files)
351-
logger:=slogtest.Make(t,nil)
381+
logger:=slogtest.Make(t,nil).Leveled(slog.LevelDebug)
352382
tags,err:=tfparse.WorkspaceTagDefaultsFromFile(ctx,logger,zip,"application/zip")
353383
iftc.expectError!="" {
354384
require.Contains(t,err.Error(),tc.expectError)
@@ -395,8 +425,8 @@ func createZip(t testing.TB, files map[string]string) []byte {
395425
// goarch: amd64
396426
// pkg: github.com/coder/coder/v2/provisioner/terraform/tfparse
397427
// cpu: AMD EPYC 7502P 32-Core Processor
398-
// BenchmarkWorkspaceTagDefaultsFromFile/Tar-1610771081951 ns/op200754 B/op 1312 allocs/op
399-
// BenchmarkWorkspaceTagDefaultsFromFile/Zip-169841187299 ns/op249574 B/op 1369 allocs/op
428+
// BenchmarkWorkspaceTagDefaultsFromFile/Tar-1617701064920 ns/op197638 B/op 1312 allocs/op
429+
// BenchmarkWorkspaceTagDefaultsFromFile/Zip-169541197070 ns/op246819 B/op 1369 allocs/op
400430
// PASS
401431
funcBenchmarkWorkspaceTagDefaultsFromFile(b*testing.B) {
402432
files:=map[string]string{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp