From a4e93ec573b4cff5c8a60da0b61203f91f98e37d Mon Sep 17 00:00:00 2001 From: Jacques Grove Date: Fri, 12 Jun 2020 10:03:44 -0700 Subject: [PATCH] Rework error messages on parse errors when reloading table ACL config file. Avoids log spam, since we try to interpret file as both proto or JSON. Also clarify table-acl-config-reload-interval flag in help. Lastly, print data as string in error; bytes are not helpful. Signed-off-by: Jacques Grove --- go/cmd/vttablet/vttablet.go | 2 +- go/vt/tableacl/tableacl.go | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/go/cmd/vttablet/vttablet.go b/go/cmd/vttablet/vttablet.go index d55ecb554dc..a742d70b042 100644 --- a/go/cmd/vttablet/vttablet.go +++ b/go/cmd/vttablet/vttablet.go @@ -39,7 +39,7 @@ import ( var ( enforceTableACLConfig = flag.Bool("enforce-tableacl-config", false, "if this flag is true, vttablet will fail to start if a valid tableacl config does not exist") tableACLConfig = flag.String("table-acl-config", "", "path to table access checker config file; send SIGHUP to reload this file") - tableACLConfigReloadInterval = flag.Duration("table-acl-config-reload-interval", 0, "Ticker to reload ACLs") + tableACLConfigReloadInterval = flag.Duration("table-acl-config-reload-interval", 0, "Ticker to reload ACLs. Duration flag, format e.g.: 30s. Default: do not reload") tabletPath = flag.String("tablet-path", "", "tablet alias") tabletConfig = flag.String("tablet_config", "", "YAML file config for tablet") diff --git a/go/vt/tableacl/tableacl.go b/go/vt/tableacl/tableacl.go index 9a21dcd3d6a..80380d55d5c 100644 --- a/go/vt/tableacl/tableacl.go +++ b/go/vt/tableacl/tableacl.go @@ -109,19 +109,17 @@ func (tacl *tableACL) init(configFile string, aclCB func()) error { if configFile == "" { return nil } - log.Infof("Loading Table ACL from local file: %v", configFile) data, err := ioutil.ReadFile(configFile) if err != nil { - log.Infof("unable to read tableACL config file: %v", err) + log.Infof("unable to read tableACL config file: %v Error: %v", configFile, err) return err } config := &tableaclpb.Config{} if err := proto.Unmarshal(data, config); err != nil { - log.Infof("unable to parse tableACL config file as a protobuf file: %v, will try as json", err) // try to parse tableacl as json file if jsonErr := json2.Unmarshal(data, config); jsonErr != nil { - log.Infof("unable to parse tableACL config file as a json file: %v", jsonErr) - return fmt.Errorf("unable to unmarshal Table ACL data: %v", data) + log.Infof("unable to parse tableACL config file as a protobuf or json file. protobuf err: %v json err: %v", err, jsonErr) + return fmt.Errorf("unable to unmarshal Table ACL data: %s", data) } } return tacl.Set(config)