deployment-service: skip internal pb fields in inspect-db
The `state` field in the configuration protobufs contain the entire
binary description of the protobuf. This makes inspect-db relatively
useless. This changes our pretty-printer to skip fields that look like
protobuf internals
@@ -152,10 +152,16 @@ func pretty(buf io.Writer, v reflect.Value, depth int) {
fmt.Fprint(buf, "{\n")
for i := 0; i < v.NumField(); i++ {
+ field := v.Field(i)
+ fieldName := v.Type().Field(i).Name
+ if skipPBInternal(fieldName, field) {
+ continue
+ }
+
fmt.Fprint(buf, nextIndent)
- fmt.Fprint(buf, v.Type().Field(i).Name)
+ fmt.Fprint(buf, fieldName)
fmt.Fprint(buf, ": ")
- pretty(buf, v.Field(i), depth+1)
+ pretty(buf, field, depth+1)
fmt.Fprint(buf, ",\n")
}
fmt.Fprint(buf, indent)
@@ -181,6 +187,25 @@ func pretty(buf io.Writer, v reflect.Value, depth int) {
}
}
+// skipPBInternal returns true if the field looks like protobuf
+// internal state that isn't useful to print.
+func skipPBInternal(fieldName string, field reflect.Value) bool {
+ switch fieldName {
+ case "state":
+ typeName := field.Type().Name()
+ if typeName == "MessageState" {
+ return true
+ }
+ case "sizeCache":
+ return true
+ case "unknownFields":
+ if field.Kind() == reflect.Slice && field.Len() == 0 {
+ return true
+ }
+ }
+ return false
+}
+
func fallbackDump(db *bolt.DB, err error) {
fmt.Fprintf(os.Stderr, "BoltDB database file does not not match known formats:\n%s\n", err.Error())
err = db.View(func(tx *bolt.Tx) error {
