{"record":{"id":"3230e79979a7d337","repo":"hashicorp/nomad","slug":"service-name-too-long","errorCode":null,"errorMessage":"service name too long","messagePattern":"service name too long","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/agent/monitor/export_monitor.go","lineNumber":128,"sourceCode":"\n\tsw := ExportMonitor{\n\t\tlogger:       hclog.Default().Named(\"export\"),\n\t\tdoneCh:       make(chan struct{}, 1),\n\t\tlogCh:        make(chan []byte, bufSize),\n\t\tbufSize:      bufSize,\n\t\tExportReader: exportReader,\n\t}\n\n\treturn &sw, nil\n}\n\n// ScanServiceName checks that the length, prefix and suffix conform to\n// systemd conventions and ensures the service name includes the word 'nomad'\nfunc ScanServiceName(input string) error {\n\tprefix := \"\"\n\t// invalid if prefix and suffix together are > 255 char\n\tif len(input) > 255 {\n\t\treturn errors.New(\"service name too long\")\n\t}\n\n\tif isNomad := strings.Contains(input, \"nomad\"); !isNomad {\n\t\treturn errors.New(`service name must include 'nomad`)\n\t}\n\n\t// if there is a suffix, check against list of valid suffixes\n\t// and set prefix to exclude suffix index, else set prefix\n\tsplitInput := strings.Split(input, \".\")\n\tif len(splitInput) < 2 {\n\t\tprefix = input\n\t} else {\n\t\tsuffix := splitInput[len(splitInput)-1]\n\t\tvalidSuffix := []string{\n\t\t\t\"service\",\n\t\t\t\"socket\",\n\t\t\t\"device\",\n\t\t\t\"mount\",","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/agent/monitor/export_monitor.go#L110-L146","documentation":"ScanServiceName in command/agent/monitor/export_monitor.go validates a systemd service name for log export. systemd limits unit names to 255 characters; if the combined input length exceeds 255, the check fails with this error before any further prefix/suffix validation. It enforces systemd's naming convention so the generated unit name will be usable by journald.","triggerScenarios":"Calling ScanServiceName (via AgentMonitorExport or cliReader) with a service/unit name string longer than 255 bytes — e.g. a generated name composed of a long job/task/allocation id chain.","commonSituations":"Deeply nested or templated job names producing very long systemd unit names; concatenating namespace/job/task IDs without truncation; users pasting fully-qualified names with long prefixes into monitoring config.","solutions":["Shorten the service name to <= 255 characters, truncating the middle segment (job/task portion) while keeping the 'nomad' token and suffix.","Check where the name is generated (nomad logmon/export template) and add length limiting there.","Strip redundant prefixes/namespace decorations from the configured service name.","Log/print the computed name length in config validation to catch this before issuing the monitor request."],"exampleFix":"// before\nname := \"nomad-\" + jobID + \"-\" + taskGroup + \"-\" + allocID + \".service\" // 300 chars\n// after\nif len(name) > 255 {\n    name = name[:252] + \".service\"\n}","handlingStrategy":"validation","validationCode":"if len(serviceName) > 255 {\n    serviceName = serviceName[:252] + \".service\" // truncate before calling\n}","typeGuard":null,"tryCatchPattern":"if err := monitor.ScanServiceName(name); err != nil {\n    if strings.Contains(err.Error(), \"too long\") {\n        return fmt.Errorf(\"truncate unit name (len=%d > 255): %s\", len(name), name)\n    }\n    return err\n}","preventionTips":["Cap generated unit names at 255 bytes where job/alloc IDs are concatenated.","Keep the 'nomad' token and suffix when truncating.","Validate names in CI for templated job definitions."],"tags":["systemd","validation","naming","journald"],"backgroundTag":"name-too-long","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}