Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
3ea2f3e9
Commit
3ea2f3e9
authored
Jan 19, 2018
by
Bowei Du
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add logging in all generated GCE calls
parent
3b391c87
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
88 additions
and
8 deletions
+88
-8
main.go
pkg/cloudprovider/providers/gce/cloud/gen/main.go
+88
-8
No files found.
pkg/cloudprovider/providers/gce/cloud/gen/main.go
View file @
3ea2f3e9
...
@@ -657,8 +657,11 @@ type {{.GCEWrapType}} struct {
...
@@ -657,8 +657,11 @@ type {{.GCEWrapType}} struct {
{{- if .GenerateGet}}
{{- if .GenerateGet}}
// Get the {{.Object}} named by key.
// Get the {{.Object}} named by key.
func (g *{{.GCEWrapType}}) Get(ctx context.Context, key *meta.Key) (*{{.FQObjectType}}, error) {
func (g *{{.GCEWrapType}}) Get(ctx context.Context, key *meta.Key) (*{{.FQObjectType}}, error) {
glog.V(5).Infof("{{.GCEWrapType}}.Get(%v, %v): called", ctx, key)
if ! key.Valid() {
if ! key.Valid() {
return nil, fmt.Errorf("invalid GCE key (%+v)", key)
glog.V(2).Infof("{{.GCEWrapType}}.Get(%v, %v): key is invalid (%#v)", ctx, key, key)
return nil, fmt.Errorf("invalid GCE key (%#v)", key)
}
}
projectID := g.s.ProjectRouter.ProjectID(ctx, "{{.Version}}", "{{.Service}}")
projectID := g.s.ProjectRouter.ProjectID(ctx, "{{.Version}}", "{{.Service}}")
rk := &RateLimitKey{
rk := &RateLimitKey{
...
@@ -667,7 +670,9 @@ func (g *{{.GCEWrapType}}) Get(ctx context.Context, key *meta.Key) (*{{.FQObject
...
@@ -667,7 +670,9 @@ func (g *{{.GCEWrapType}}) Get(ctx context.Context, key *meta.Key) (*{{.FQObject
Version: meta.Version("{{.Version}}"),
Version: meta.Version("{{.Version}}"),
Service: "{{.Service}}",
Service: "{{.Service}}",
}
}
glog.V(5).Infof("{{.GCEWrapType}}.Get(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
glog.V(4).Infof("{{.GCEWrapType}}.Get(%v, %v): RateLimiter error: %v", ctx, key, err)
return nil, err
return nil, err
}
}
{{- if .KeyIsGlobal}}
{{- if .KeyIsGlobal}}
...
@@ -680,7 +685,9 @@ func (g *{{.GCEWrapType}}) Get(ctx context.Context, key *meta.Key) (*{{.FQObject
...
@@ -680,7 +685,9 @@ func (g *{{.GCEWrapType}}) Get(ctx context.Context, key *meta.Key) (*{{.FQObject
call := g.s.{{.VersionTitle}}.{{.Service}}.Get(projectID, key.Zone, key.Name)
call := g.s.{{.VersionTitle}}.{{.Service}}.Get(projectID, key.Zone, key.Name)
{{- end}}
{{- end}}
call.Context(ctx)
call.Context(ctx)
return call.Do()
v, err := call.Do()
glog.V(4).Infof("{{.GCEWrapType}}.Get(%v, %v) = %+v, %v", ctx, key, v, err)
return v, err
}
}
{{- end}}
{{- end}}
...
@@ -688,15 +695,18 @@ func (g *{{.GCEWrapType}}) Get(ctx context.Context, key *meta.Key) (*{{.FQObject
...
@@ -688,15 +695,18 @@ func (g *{{.GCEWrapType}}) Get(ctx context.Context, key *meta.Key) (*{{.FQObject
// List all {{.Object}} objects.
// List all {{.Object}} objects.
{{- if .KeyIsGlobal}}
{{- if .KeyIsGlobal}}
func (g *{{.GCEWrapType}}) List(ctx context.Context, fl *filter.F) ([]*{{.FQObjectType}}, error) {
func (g *{{.GCEWrapType}}) List(ctx context.Context, fl *filter.F) ([]*{{.FQObjectType}}, error) {
glog.V(5).Infof("{{.GCEWrapType}}.List(%v, %v) called", ctx, fl)
{{- end -}}
{{- end -}}
{{- if .KeyIsRegional}}
{{- if .KeyIsRegional}}
func (g *{{.GCEWrapType}}) List(ctx context.Context, region string, fl *filter.F) ([]*{{.FQObjectType}}, error) {
func (g *{{.GCEWrapType}}) List(ctx context.Context, region string, fl *filter.F) ([]*{{.FQObjectType}}, error) {
glog.V(5).Infof("{{.GCEWrapType}}.List(%v, %v, %v) called", ctx, region, fl)
{{- end -}}
{{- end -}}
{{- if .KeyIsZonal}}
{{- if .KeyIsZonal}}
func (g *{{.GCEWrapType}}) List(ctx context.Context, zone string, fl *filter.F) ([]*{{.FQObjectType}}, error) {
func (g *{{.GCEWrapType}}) List(ctx context.Context, zone string, fl *filter.F) ([]*{{.FQObjectType}}, error) {
glog.V(5).Infof("{{.GCEWrapType}}.List(%v, %v, %v) called", ctx, zone, fl)
{{- end}}
{{- end}}
projectID := g.s.ProjectRouter.ProjectID(ctx, "{{.Version}}", "{{.Service}}")
projectID := g.s.ProjectRouter.ProjectID(ctx, "{{.Version}}", "{{.Service}}")
rk := &RateLimitKey{
rk := &RateLimitKey{
ProjectID: projectID,
ProjectID: projectID,
Operation: "List",
Operation: "List",
Version: meta.Version("{{.Version}}"),
Version: meta.Version("{{.Version}}"),
...
@@ -706,12 +716,15 @@ rk := &RateLimitKey{
...
@@ -706,12 +716,15 @@ rk := &RateLimitKey{
return nil, err
return nil, err
}
}
{{- if .KeyIsGlobal}}
{{- if .KeyIsGlobal}}
glog.V(5).Infof("{{.GCEWrapType}}.List(%v, %v): projectID = %v, rk = %+v", ctx, fl, projectID, rk)
call := g.s.{{.VersionTitle}}.{{.Service}}.List(projectID)
call := g.s.{{.VersionTitle}}.{{.Service}}.List(projectID)
{{- end -}}
{{- end -}}
{{- if .KeyIsRegional}}
{{- if .KeyIsRegional}}
glog.V(5).Infof("{{.GCEWrapType}}.List(%v, %v, %v): projectID = %v, rk = %+v", ctx, region, fl, projectID, rk)
call := g.s.{{.VersionTitle}}.{{.Service}}.List(projectID, region)
call := g.s.{{.VersionTitle}}.{{.Service}}.List(projectID, region)
{{- end -}}
{{- end -}}
{{- if .KeyIsZonal}}
{{- if .KeyIsZonal}}
glog.V(5).Infof("{{.GCEWrapType}}.List(%v, %v, %v): projectID = %v, rk = %+v", ctx, zone, fl, projectID, rk)
call := g.s.{{.VersionTitle}}.{{.Service}}.List(projectID, zone)
call := g.s.{{.VersionTitle}}.{{.Service}}.List(projectID, zone)
{{- end}}
{{- end}}
if fl != filter.None {
if fl != filter.None {
...
@@ -719,12 +732,25 @@ rk := &RateLimitKey{
...
@@ -719,12 +732,25 @@ rk := &RateLimitKey{
}
}
var all []*{{.FQObjectType}}
var all []*{{.FQObjectType}}
f := func(l *{{.ObjectListType}}) error {
f := func(l *{{.ObjectListType}}) error {
glog.V(5).Infof("{{.GCEWrapType}}.List(%v, ..., %v): page %+v", ctx, fl, l)
all = append(all, l.Items...)
all = append(all, l.Items...)
return nil
return nil
}
}
if err := call.Pages(ctx, f); err != nil {
if err := call.Pages(ctx, f); err != nil {
glog.V(4).Infof("{{.GCEWrapType}}.List(%v, ..., %v) = %v, %v", ctx, fl, nil, err)
return nil, err
return nil, err
}
}
if glog.V(4) {
glog.V(4).Infof("{{.GCEWrapType}}.List(%v, ..., %v) = [%v items], %v", ctx, fl, len(all), nil)
} else if glog.V(5) {
var asStr []string
for _, o := range all {
asStr = append(asStr, fmt.Sprintf("%+v", o))
}
glog.V(5).Infof("{{.GCEWrapType}}.List(%v, ..., %v) = %v, %v", ctx, fl, asStr, nil)
}
return all, nil
return all, nil
}
}
{{- end}}
{{- end}}
...
@@ -732,7 +758,9 @@ rk := &RateLimitKey{
...
@@ -732,7 +758,9 @@ rk := &RateLimitKey{
{{- if .GenerateInsert}}
{{- if .GenerateInsert}}
// Insert {{.Object}} with key of value obj.
// Insert {{.Object}} with key of value obj.
func (g *{{.GCEWrapType}}) Insert(ctx context.Context, key *meta.Key, obj *{{.FQObjectType}}) error {
func (g *{{.GCEWrapType}}) Insert(ctx context.Context, key *meta.Key, obj *{{.FQObjectType}}) error {
glog.V(5).Infof("{{.GCEWrapType}}.Insert(%v, %v, %+v): called", ctx, key, obj)
if ! key.Valid() {
if ! key.Valid() {
glog.V(2).Infof("{{.GCEWrapType}}.Insert(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
return fmt.Errorf("invalid GCE key (%+v)", key)
return fmt.Errorf("invalid GCE key (%+v)", key)
}
}
projectID := g.s.ProjectRouter.ProjectID(ctx, "{{.Version}}", "{{.Service}}")
projectID := g.s.ProjectRouter.ProjectID(ctx, "{{.Version}}", "{{.Service}}")
...
@@ -742,7 +770,9 @@ func (g *{{.GCEWrapType}}) Insert(ctx context.Context, key *meta.Key, obj *{{.FQ
...
@@ -742,7 +770,9 @@ func (g *{{.GCEWrapType}}) Insert(ctx context.Context, key *meta.Key, obj *{{.FQ
Version: meta.Version("{{.Version}}"),
Version: meta.Version("{{.Version}}"),
Service: "{{.Service}}",
Service: "{{.Service}}",
}
}
glog.V(5).Infof("{{.GCEWrapType}}.Insert(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
glog.V(4).Infof("{{.GCEWrapType}}.Insert(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
return err
return err
}
}
obj.Name = key.Name
obj.Name = key.Name
...
@@ -759,16 +789,22 @@ func (g *{{.GCEWrapType}}) Insert(ctx context.Context, key *meta.Key, obj *{{.FQ
...
@@ -759,16 +789,22 @@ func (g *{{.GCEWrapType}}) Insert(ctx context.Context, key *meta.Key, obj *{{.FQ
op, err := call.Do()
op, err := call.Do()
if err != nil {
if err != nil {
glog.V(4).Infof("{{.GCEWrapType}}.Insert(%v, %v, ...) = %+v", ctx, key, err)
return err
return err
}
}
return g.s.WaitForCompletion(ctx, op)
err = g.s.WaitForCompletion(ctx, op)
glog.V(4).Infof("{{.GCEWrapType}}.Insert(%v, %v, %+v) = %+v", ctx, key, obj, err)
return err
}
}
{{- end}}
{{- end}}
{{- if .GenerateDelete}}
{{- if .GenerateDelete}}
// Delete the {{.Object}} referenced by key.
// Delete the {{.Object}} referenced by key.
func (g *{{.GCEWrapType}}) Delete(ctx context.Context, key *meta.Key) error {
func (g *{{.GCEWrapType}}) Delete(ctx context.Context, key *meta.Key) error {
glog.V(5).Infof("{{.GCEWrapType}}.Delete(%v, %v): called", ctx, key)
if ! key.Valid() {
if ! key.Valid() {
glog.V(2).Infof("{{.GCEWrapType}}.Delete(%v, %v): key is invalid (%#v)", ctx, key, key)
return fmt.Errorf("invalid GCE key (%+v)", key)
return fmt.Errorf("invalid GCE key (%+v)", key)
}
}
projectID := g.s.ProjectRouter.ProjectID(ctx, "{{.Version}}", "{{.Service}}")
projectID := g.s.ProjectRouter.ProjectID(ctx, "{{.Version}}", "{{.Service}}")
...
@@ -778,7 +814,9 @@ func (g *{{.GCEWrapType}}) Delete(ctx context.Context, key *meta.Key) error {
...
@@ -778,7 +814,9 @@ func (g *{{.GCEWrapType}}) Delete(ctx context.Context, key *meta.Key) error {
Version: meta.Version("{{.Version}}"),
Version: meta.Version("{{.Version}}"),
Service: "{{.Service}}",
Service: "{{.Service}}",
}
}
glog.V(5).Infof("{{.GCEWrapType}}.Delete(%v, %v): projectID = %v, rk = %+v", ctx, key, projectID, rk)
if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
glog.V(4).Infof("{{.GCEWrapType}}.Delete(%v, %v): RateLimiter error: %v", ctx, key, err)
return err
return err
}
}
{{- if .KeyIsGlobal}}
{{- if .KeyIsGlobal}}
...
@@ -794,15 +832,21 @@ func (g *{{.GCEWrapType}}) Delete(ctx context.Context, key *meta.Key) error {
...
@@ -794,15 +832,21 @@ func (g *{{.GCEWrapType}}) Delete(ctx context.Context, key *meta.Key) error {
op, err := call.Do()
op, err := call.Do()
if err != nil {
if err != nil {
glog.V(4).Infof("{{.GCEWrapType}}.Delete(%v, %v) = %v", ctx, key, err)
return err
return err
}
}
return g.s.WaitForCompletion(ctx, op)
err = g.s.WaitForCompletion(ctx, op)
glog.V(4).Infof("{{.GCEWrapType}}.Delete(%v, %v) = %v", ctx, key, err)
return err
}
}
{{end -}}
{{end -}}
{{- if .AggregatedList}}
{{- if .AggregatedList}}
// AggregatedList lists all resources of the given type across all locations.
// AggregatedList lists all resources of the given type across all locations.
func (g *{{.GCEWrapType}}) AggregatedList(ctx context.Context, fl *filter.F) (map[string][]*{{.FQObjectType}}, error) {
func (g *{{.GCEWrapType}}) AggregatedList(ctx context.Context, fl *filter.F) (map[string][]*{{.FQObjectType}}, error) {
glog.V(5).Infof("{{.GCEWrapType}}.AggregatedList(%v, %v) called", ctx, fl)
projectID := g.s.ProjectRouter.ProjectID(ctx, "{{.Version}}", "{{.Service}}")
projectID := g.s.ProjectRouter.ProjectID(ctx, "{{.Version}}", "{{.Service}}")
rk := &RateLimitKey{
rk := &RateLimitKey{
ProjectID: projectID,
ProjectID: projectID,
...
@@ -810,7 +854,10 @@ func (g *{{.GCEWrapType}}) AggregatedList(ctx context.Context, fl *filter.F) (ma
...
@@ -810,7 +854,10 @@ func (g *{{.GCEWrapType}}) AggregatedList(ctx context.Context, fl *filter.F) (ma
Version: meta.Version("{{.Version}}"),
Version: meta.Version("{{.Version}}"),
Service: "{{.Service}}",
Service: "{{.Service}}",
}
}
glog.V(5).Infof("{{.GCEWrapType}}.AggregatedList(%v, %v): projectID = %v, rk = %+v", ctx, fl, projectID, rk)
if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
glog.V(5).Infof("{{.GCEWrapType}}.AggregatedList(%v, %v): RateLimiter error: %v", ctx, fl, err)
return nil, err
return nil, err
}
}
...
@@ -823,13 +870,24 @@ func (g *{{.GCEWrapType}}) AggregatedList(ctx context.Context, fl *filter.F) (ma
...
@@ -823,13 +870,24 @@ func (g *{{.GCEWrapType}}) AggregatedList(ctx context.Context, fl *filter.F) (ma
all := map[string][]*{{.FQObjectType}}{}
all := map[string][]*{{.FQObjectType}}{}
f := func(l *{{.ObjectAggregatedListType}}) error {
f := func(l *{{.ObjectAggregatedListType}}) error {
for k, v := range l.Items {
for k, v := range l.Items {
glog.V(5).Infof("{{.GCEWrapType}}.AggregatedList(%v, %v): page[%v]%+v", ctx, fl, k, v)
all[k] = append(all[k], v.{{.AggregatedListField}}...)
all[k] = append(all[k], v.{{.AggregatedListField}}...)
}
}
return nil
return nil
}
}
if err := call.Pages(ctx, f); err != nil {
if err := call.Pages(ctx, f); err != nil {
glog.V(4).Infof("{{.GCEWrapType}}.AggregatedList(%v, %v) = %v, %v", ctx, fl, nil, err)
return nil, err
return nil, err
}
}
if glog.V(4) {
glog.V(4).Infof("{{.GCEWrapType}}.AggregatedList(%v, %v) = [%v items], %v", ctx, fl, len(all), nil)
} else if glog.V(5) {
var asStr []string
for _, o := range all {
asStr = append(asStr, fmt.Sprintf("%+v", o))
}
glog.V(5).Infof("{{.GCEWrapType}}.AggregatedList(%v, %v) = %v, %v", ctx, fl, asStr, nil)
}
return all, nil
return all, nil
}
}
{{- end}}
{{- end}}
...
@@ -838,7 +896,10 @@ func (g *{{.GCEWrapType}}) AggregatedList(ctx context.Context, fl *filter.F) (ma
...
@@ -838,7 +896,10 @@ func (g *{{.GCEWrapType}}) AggregatedList(ctx context.Context, fl *filter.F) (ma
{{- range .}}
{{- range .}}
// {{.Name}} is a method on {{.GCEWrapType}}.
// {{.Name}} is a method on {{.GCEWrapType}}.
func (g *{{.GCEWrapType}}) {{.FcnArgs}} {
func (g *{{.GCEWrapType}}) {{.FcnArgs}} {
glog.V(5).Infof("{{.GCEWrapType}}.{{.Name}}(%v, %v, ...): called", ctx, key)
if ! key.Valid() {
if ! key.Valid() {
glog.V(2).Infof("{{.GCEWrapType}}.{{.Name}}(%v, %v, ...): key is invalid (%#v)", ctx, key, key)
{{- if .IsOperation}}
{{- if .IsOperation}}
return fmt.Errorf("invalid GCE key (%+v)", key)
return fmt.Errorf("invalid GCE key (%+v)", key)
{{- else if .IsGet}}
{{- else if .IsGet}}
...
@@ -854,7 +915,10 @@ func (g *{{.GCEWrapType}}) {{.FcnArgs}} {
...
@@ -854,7 +915,10 @@ func (g *{{.GCEWrapType}}) {{.FcnArgs}} {
Version: meta.Version("{{.Version}}"),
Version: meta.Version("{{.Version}}"),
Service: "{{.Service}}",
Service: "{{.Service}}",
}
}
glog.V(5).Infof("{{.GCEWrapType}}.{{.Name}}(%v, %v, ...): projectID = %v, rk = %+v", ctx, key, projectID, rk)
if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
if err := g.s.RateLimiter.Accept(ctx, rk); err != nil {
glog.V(4).Infof("{{.GCEWrapType}}.{{.Name}}(%v, %v, ...): RateLimiter error: %v", ctx, key, err)
{{- if .IsOperation}}
{{- if .IsOperation}}
return err
return err
{{- else}}
{{- else}}
...
@@ -874,21 +938,37 @@ func (g *{{.GCEWrapType}}) {{.FcnArgs}} {
...
@@ -874,21 +938,37 @@ func (g *{{.GCEWrapType}}) {{.FcnArgs}} {
call.Context(ctx)
call.Context(ctx)
op, err := call.Do()
op, err := call.Do()
if err != nil {
if err != nil {
glog.V(4).Infof("{{.GCEWrapType}}.{{.Name}}(%v, %v, ...) = %+v", ctx, key, err)
return err
return err
}
}
return g.s.WaitForCompletion(ctx, op)
err = g.s.WaitForCompletion(ctx, op)
glog.V(4).Infof("{{.GCEWrapType}}.{{.Name}}(%v, %v, ...) = %+v", ctx, key, err)
return err
{{- else if .IsGet}}
{{- else if .IsGet}}
call.Context(ctx)
call.Context(ctx)
return call.Do()
v, err := call.Do()
glog.V(4).Infof("{{.GCEWrapType}}.{{.Name}}(%v, %v, ...) = %+v, %v", ctx, key, v, err)
return v, err
{{- else if .IsPaged}}
{{- else if .IsPaged}}
var all []*{{.Version}}.{{.ItemType}}
var all []*{{.Version}}.{{.ItemType}}
f := func(l *{{.Version}}.{{.ReturnType}}) error {
f := func(l *{{.Version}}.{{.ReturnType}}) error {
glog.V(5).Infof("{{.GCEWrapType}}.{{.Name}}(%v, %v, ...): page %+v", ctx, key, l)
all = append(all, l.Items...)
all = append(all, l.Items...)
return nil
return nil
}
}
if err := call.Pages(ctx, f); err != nil {
if err := call.Pages(ctx, f); err != nil {
glog.V(4).Infof("{{.GCEWrapType}}.{{.Name}}(%v, %v, ...) = %v, %v", ctx, key, nil, err)
return nil, err
return nil, err
}
}
if glog.V(4) {
glog.V(4).Infof("{{.GCEWrapType}}.{{.Name}}(%v, %v, ...) = [%v items], %v", ctx, key, len(all), nil)
} else if glog.V(5) {
var asStr []string
for _, o := range all {
asStr = append(asStr, fmt.Sprintf("%+v", o))
}
glog.V(5).Infof("{{.GCEWrapType}}.{{.Name}}(%v, %v, ...) = %v, %v", ctx, key, asStr, nil)
}
return all, nil
return all, nil
{{- end}}
{{- end}}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment