{"record":{"id":"353fb296d3bbf73c","repo":"vitessio/vitess","slug":"failed-to-create-file-based-writer-for-opentsdb","errorCode":null,"errorMessage":"failed to create file-based writer for --opentsdb-uri %s: %v","messagePattern":"failed to create file-based writer for --opentsdb-uri (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/stats/opentsdb/init.go","lineNumber":91,"sourceCode":"\n\treturn b, nil\n}\n\nfunc newBackend(prefix string) (*backend, error) {\n\tif openTSDBURI == \"\" {\n\t\treturn nil, errors.New(\"cannot create opentsdb PushBackend with empty --opentsdb-uri\")\n\t}\n\n\tvar w writer\n\n\t// Use the file API when the uri is in format file://...\n\tu, err := url.Parse(openTSDBURI)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to parse --opentsdb-uri %s: %v\", openTSDBURI, err)\n\t} else if u.Scheme == \"file\" {\n\t\tfw, err := newFileWriter(u.Path)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to create file-based writer for --opentsdb-uri %s: %v\", openTSDBURI, err)\n\t\t} else {\n\t\t\tw = fw\n\t\t}\n\t} else {\n\t\tw = newHTTPWriter(&http.Client{}, openTSDBURI)\n\t}\n\n\treturn &backend{\n\t\tprefix:     prefix,\n\t\tcommonTags: stats.ParseCommonTags(stats.CommonTags),\n\t\twriter:     w,\n\t}, nil\n}\n","sourceCodeStart":73,"sourceCodeEnd":105,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/stats/opentsdb/init.go#L73-L105","documentation":"When --opentsdb-uri uses the file:// scheme, newBackend creates a file-based writer via newFileWriter(u.Path); this error wraps any failure from that creation (e.g. the target path cannot be used) together with the original URI. It signals the file writer could not be set up for the requested path.","triggerScenarios":"--opentsdb-uri file:///some/path where newFileWriter fails, typically because the path's directory does not exist or the file cannot be opened/created with the required permissions.","commonSituations":"Writing metrics to a read-only container filesystem; typo'd or missing output directory; running as a user without write permission to the path.","solutions":["Create the target directory (mkdir -p) and ensure the process user can write to it","Point --opentsdb-uri at a writable path, e.g. file:///var/tmp/vitess-metrics.jsonl","Check the wrapped error for the exact OS failure (ENOENT, EACCES) and fix accordingly"],"exampleFix":"// before\n--opentsdb-uri 'file:///nonexistent/dir/metrics'\n// after\nmkdir -p /var/lib/vitess/metrics && --opentsdb-uri 'file:///var/lib/vitess/metrics/opentsdb.jsonl'","handlingStrategy":"validation","validationCode":"u, _ := url.Parse(opentsdbURI)\nif u.Scheme == \"file\" {\n\tif st, err := os.Stat(filepath.Dir(u.Path)); err != nil || !st.IsDir() {\n\t\treturn fmt.Errorf(\"directory for --opentsdb-uri does not exist: %s\", filepath.Dir(u.Path))\n\t}\n}","typeGuard":null,"tryCatchPattern":"fw, err := newFileWriter(u.Path)\nif err != nil {\n\tif errors.Is(err, os.ErrPermission) || errors.Is(err, os.ErrNotExist) {\n\t\treturn fmt.Errorf(\"cannot write metrics file %s: %w\", u.Path, err)\n\t}\n}","preventionTips":["Pre-create the metrics output directory in deployment scripts","Ensure the container/filesystem path is writable by the process user","Prefer a path under /var/tmp or a mounted volume over read-only rootfs"],"tags":["go","opentsdb","filesystem","configuration"],"backgroundTag":"file-writer-init-failed","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}