diff --git a/agent/config/builder.go b/agent/config/builder.go index 7b99b49602..d0a3a353de 100644 --- a/agent/config/builder.go +++ b/agent/config/builder.go @@ -999,7 +999,7 @@ func (b *Builder) serviceVal(v *ServiceDefinition) *structs.ServiceDefinition { meta := make(map[string]string) if err := structs.ValidateMetadata(v.Meta, false); err != nil { - b.err = multierror.Append(fmt.Errorf("invalid meta for service %v: %v", v.Name, err)) + b.err = multierror.Append(fmt.Errorf("invalid meta for service %s: %v", *v.Name, err)) } else { meta = v.Meta } diff --git a/agent/config/runtime_test.go b/agent/config/runtime_test.go index 511ebc4a80..4306ce6ad9 100644 --- a/agent/config/runtime_test.go +++ b/agent/config/runtime_test.go @@ -1939,6 +1939,32 @@ func TestConfigFlagsAndEdgecases(t *testing.T) { rt.DataDir = dataDir }, }, + { + desc: "service with wrong meta: too long", + args: []string{ + `-data-dir=` + dataDir, + }, + json: []string{ + `{ "service": { "name": "a", "port": 80, "meta": { "a": "` + randomString(520) + `" } } }`, + }, + hcl: []string{ + `service = { name = "a" port = 80, meta={a="` + randomString(520) + `"} }`, + }, + err: `Value is too long`, + }, + { + desc: "service with wrong meta: too many meta", + args: []string{ + `-data-dir=` + dataDir, + }, + json: []string{ + `{ "service": { "name": "a", "port": 80, "meta": { ` + metaPairs(70, "json") + `} } }`, + }, + hcl: []string{ + `service = { name = "a" port = 80 meta={` + metaPairs(70, "hcl") + `} }`, + }, + err: `invalid meta for service a: Node metadata cannot contain more than 64 key`, + }, { desc: "translated keys", args: []string{