Merge pull request #126 from jetstack-experimental/improve-logging

Consistent use of glog
This commit is contained in:
James Munnelly 2017-10-16 15:02:41 +01:00 committed by GitHub
commit e89423a057
6 changed files with 31 additions and 41 deletions

View File

@ -178,43 +178,40 @@ func (c *Controller) Run(workers int, stopCh <-chan struct{}) error {
func (c *Controller) worker(stopCh <-chan struct{}) {
defer c.workerWg.Done()
glog.V(4).Infof("Starting %s worker", ControllerName)
glog.V(4).Infof("Starting %q worker", ControllerName)
for {
obj, shutdown := c.queue.Get()
if shutdown {
break
}
var key string
err := func(obj interface{}) error {
defer c.queue.Done(obj)
var key string
var ok bool
if key, ok = obj.(string); !ok {
runtime.HandleError(fmt.Errorf("expected string in workqueue but got %T", obj))
return nil
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx = util.ContextWithStopCh(ctx, stopCh)
glog.V(6).Infof("%s controller: syncing item '%s'", ControllerName, key)
glog.Infof("%s controller: syncing item '%s'", ControllerName, key)
if err := c.syncHandler(ctx, key); err != nil {
glog.V(4).Infof("%s controller: error syncing item '%s': %s", ControllerName, key, err.Error())
return err
}
glog.V(4).Infof("%s controller: synced item '%s'", ControllerName, key)
c.queue.Forget(obj)
return nil
}(obj)
if err != nil {
glog.V(2).Infof("Requeuing object due to error processing: %s", err.Error())
glog.Errorf("%s controller: Re-queuing item %q due to error processing: %s", ControllerName, key, err.Error())
c.queue.AddRateLimited(obj)
continue
}
glog.V(4).Infof("Finished processing work item")
glog.Infof("%s controller: Finished processing work item %q", ControllerName, key)
}
glog.V(4).Infof("Exiting %s worker loop", ControllerName)
glog.V(4).Infof("Exiting %q worker loop", ControllerName)
}
func (c *Controller) processNextWorkItem(ctx context.Context, key string) error {

View File

@ -3,7 +3,6 @@ package issuers
import (
"context"
"fmt"
"log"
"sync"
"time"
@ -121,43 +120,40 @@ func (c *Controller) Run(workers int, stopCh <-chan struct{}) error {
func (c *Controller) worker(stopCh <-chan struct{}) {
defer c.workerWg.Done()
log.Printf("starting worker")
glog.V(4).Infof("Starting %q worker", ControllerName)
for {
obj, shutdown := c.queue.Get()
if shutdown {
break
}
var key string
err := func(obj interface{}) error {
defer c.queue.Done(obj)
var key string
var ok bool
if key, ok = obj.(string); !ok {
runtime.HandleError(fmt.Errorf("expected string in workqueue but got %T", obj))
return nil
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx = util.ContextWithStopCh(ctx, stopCh)
glog.V(6).Infof("%s controller: syncing item '%s'", ControllerName, key)
glog.Infof("%s controller: syncing item '%s'", ControllerName, key)
if err := c.syncHandler(ctx, key); err != nil {
glog.V(4).Infof("%s controller: error syncing item '%s': %s", ControllerName, key, err.Error())
return err
}
glog.V(4).Infof("%s controller: synced item '%s'", ControllerName, key)
c.queue.Forget(obj)
return nil
}(obj)
if err != nil {
log.Printf("requeuing item due to error processing: %s", err.Error())
glog.Errorf("%s controller: Re-queuing item %q due to error processing: %s", ControllerName, key, err.Error())
c.queue.AddRateLimited(obj)
continue
}
log.Printf("finished processing work item")
glog.Infof("%s controller: Finished processing work item %q", ControllerName, key)
}
log.Printf("exiting worker loop")
glog.V(4).Infof("Exiting %q worker loop", ControllerName)
}
func (c *Controller) processNextWorkItem(ctx context.Context, key string) error {
@ -171,7 +167,7 @@ func (c *Controller) processNextWorkItem(ctx context.Context, key string) error
if err != nil {
if k8sErrors.IsNotFound(err) {
runtime.HandleError(fmt.Errorf("issuer '%s' in work queue no longer exists", key))
runtime.HandleError(fmt.Errorf("issuer %q in work queue no longer exists", key))
return nil
}

View File

@ -3,7 +3,6 @@ package issuers
import (
"context"
"fmt"
"log"
"sync"
"time"
@ -119,43 +118,40 @@ func (c *Controller) Run(workers int, stopCh <-chan struct{}) error {
func (c *Controller) worker(stopCh <-chan struct{}) {
defer c.workerWg.Done()
log.Printf("starting worker")
glog.V(4).Infof("Starting %q worker", ControllerName)
for {
obj, shutdown := c.queue.Get()
if shutdown {
break
}
var key string
err := func(obj interface{}) error {
defer c.queue.Done(obj)
var key string
var ok bool
if key, ok = obj.(string); !ok {
runtime.HandleError(fmt.Errorf("expected string in workqueue but got %T", obj))
return nil
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx = util.ContextWithStopCh(ctx, stopCh)
glog.V(6).Infof("%s controller: syncing item '%s'", ControllerName, key)
glog.Infof("%s controller: syncing item '%s'", ControllerName, key)
if err := c.syncHandler(ctx, key); err != nil {
glog.V(4).Infof("%s controller: error syncing item '%s': %s", ControllerName, key, err.Error())
return err
}
glog.V(4).Infof("%s controller: synced item '%s'", ControllerName, key)
c.queue.Forget(obj)
return nil
}(obj)
if err != nil {
log.Printf("requeuing item due to error processing: %s", err.Error())
glog.Errorf("%s controller: Re-queuing item %q due to error processing: %s", ControllerName, key, err.Error())
c.queue.AddRateLimited(obj)
continue
}
log.Printf("finished processing work item")
glog.Infof("%s controller: Finished processing work item %q", ControllerName, key)
}
log.Printf("exiting worker loop")
glog.V(4).Infof("Exiting %q worker loop", ControllerName)
}
func (c *Controller) processNextWorkItem(ctx context.Context, key string) error {

View File

@ -3,9 +3,9 @@ package dns
import (
"context"
"fmt"
"log"
"time"
"github.com/golang/glog"
"k8s.io/client-go/kubernetes"
corev1listers "k8s.io/client-go/listers/core/v1"
@ -38,7 +38,7 @@ func (s *Solver) Present(ctx context.Context, crt *v1alpha1.Certificate, domain,
if err != nil {
return err
}
log.Printf("presenting key: %s", key)
glog.V(4).Infof("Presenting DNS01 challenge for domain %q", domain)
return slv.Present(domain, token, key)
}
@ -55,7 +55,7 @@ func (s *Solver) Wait(ctx context.Context, crt *v1alpha1.Certificate, domain, to
fqdn, value, ttl := util.DNS01Record(domain, key)
log.Printf("[%s] Checking DNS record propagation using %+v", domain, util.RecursiveNameservers)
glog.V(4).Infof("Checking DNS propagation for %q using name servers: %v", domain, util.RecursiveNameservers)
timeout, interval := slv.Timeout()
ctx, cancel := context.WithTimeout(ctx, timeout)
@ -74,11 +74,12 @@ func (s *Solver) Wait(ctx context.Context, crt *v1alpha1.Certificate, domain, to
if r.bool {
// TODO: move this to somewhere else
// TODO: make this wait for whatever the record *was*, not is now
log.Printf("sleeping for dns record for '%s' ttl %ds before returning from Wait", fqdn, ttl)
glog.V(4).Infof("Waiting DNS record TTL (%ds) to allow propagation for propagation of DNS record for domain %q", ttl, fqdn)
time.Sleep(time.Second * time.Duration(ttl))
glog.V(4).Infof("ACME DNS01 validation record propagated for %q", fqdn)
return nil
}
log.Printf("[%s] dns record not yet propegated", domain)
glog.V(4).Infof("DNS record for %q not yet propagated", domain)
time.Sleep(interval)
case <-ctx.Done():
return ctx.Err()

View File

@ -2,11 +2,11 @@ package util
import (
"fmt"
"log"
"net"
"strings"
"time"
"github.com/golang/glog"
"github.com/miekg/dns"
"golang.org/x/net/publicsuffix"
)
@ -90,7 +90,7 @@ func checkAuthoritativeNss(fqdn, value string, nameservers []string) (bool, erro
return false, fmt.Errorf("NS %s returned %s for %s", ns, dns.RcodeToString[r.Rcode], fqdn)
}
log.Printf("looking up txt record for fqdn '%s'", fqdn)
glog.V(6).Infof("Looking up TXT records for %q", fqdn)
var found bool
for _, rr := range r.Answer {
if txt, ok := rr.(*dns.TXT); ok {
@ -102,7 +102,7 @@ func checkAuthoritativeNss(fqdn, value string, nameservers []string) (bool, erro
}
if !found {
return false, fmt.Errorf("NS %s did not return the expected TXT record", ns)
return false, fmt.Errorf("nameserver %q did not return the expected TXT record for domain %q", ns, fqdn)
}
}

View File

@ -5,12 +5,12 @@ import (
"errors"
"fmt"
"io/ioutil"
"log"
"net/http"
"net/url"
"strings"
"time"
"github.com/golang/glog"
corev1 "k8s.io/api/core/v1"
extv1beta1 "k8s.io/api/extensions/v1beta1"
k8sErrors "k8s.io/apimachinery/pkg/api/errors"
@ -409,11 +409,11 @@ func (s *Solver) Wait(ctx context.Context, crt *v1alpha1.Certificate, domain, to
return out
}():
if err != nil {
log.Printf("[%s] Error self checking HTTP01 challenge: %s", domain, err.Error())
glog.V(4).Infof("ACME HTTP01 self check failed for domain %q, waiting 5s: %v", domain, err)
time.Sleep(time.Second * 5)
continue
}
log.Printf("[%s] HTTP01 challenge self checking passed", domain)
glog.V(4).Infof("ACME HTTP01 self check for %q passed", domain)
return nil
case <-ctx.Done():
return ctx.Err()