Skip to content

Commit 60e010c

Browse files
feat(go/adbc): align default trace path with ADBC config layout (#4527)
Update the Go driverbase adbcfile trace writer to use the ADBC config-directory layout Use temp directories for the existing rotating-file tests Closes #4501
1 parent 5c80f65 commit 60e010c

4 files changed

Lines changed: 74 additions & 17 deletions

File tree

docs/source/driver/flight_sql.rst

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -265,18 +265,13 @@ Database options
265265
Overrides the output folder used by the ``adbcfile`` exporter.
266266
This option is ignored for other exporters.
267267

268-
If unset, the ``adbcfile`` exporter writes traces under the user's
269-
configuration directory in:
268+
If unset, the ``adbcfile`` exporter writes traces under a
269+
platform-specific directory:
270270

271-
- Windows: ``%APPDATA%\.adbc\traces``
272-
- macOS: ``~/Library/Application Support/.adbc/traces``
273-
- Linux: ``$XDG_CONFIG_HOME/.adbc/traces`` or ``~/.config/.adbc/traces``
274-
275-
.. note::
276-
277-
These default paths reflect the current implementation. See
278-
`issue #4501 <https://github.com/apache/arrow-adbc/issues/4501>`_
279-
for the planned config-path redesign.
271+
- Windows: ``%LOCALAPPDATA%\ADBC\Traces``
272+
- macOS: ``~/Library/Application Support/ADBC/Traces``
273+
- Linux: ``$XDG_STATE_HOME/adbc/traces`` or ``~/.local/state/adbc/traces``
274+
if ``$XDG_STATE_HOME`` is not set
280275

281276
``adbc.telemetry.trace_parent``
282277
Sets the W3C Trace Context ``traceparent`` value used as the parent

go/adbc/adbc.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,10 @@ const (
280280
// traces exporter. When the exporter is "adbcfile" and this option
281281
// is set, rotated trace files are written to the supplied folder
282282
// (which is created if it does not exist) instead of the default
283-
// "<user-config-dir>/.adbc/traces" path. The option is ignored for
283+
// platform-specific ADBC traces path (for example,
284+
// "<user-config-dir>/ADBC/Traces" on macOS,
285+
// "<local-app-data-dir>/ADBC/Traces" on Windows, or
286+
// "<xdg-state-dir>/adbc/traces" on Linux). The option is ignored for
284287
// other exporters; it exists so an operator can route trace files
285288
// to a location their support workflow already collects (e.g. a
286289
// shared diagnostics folder) via the ADBC driver-manager / TOML

go/adbc/driver/internal/driverbase/rotating_file_writer.go

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"io/fs"
2323
"os"
2424
"path/filepath"
25+
"runtime"
2526
"strings"
2627
"time"
2728
)
@@ -152,12 +153,30 @@ func NewRotatingFileWriter(options ...rotatingFileWriterOption) (*rotatingFileWr
152153
}
153154

154155
func getDefaultTracingFolderPath() (string, error) {
155-
userConfigDir, err := os.UserConfigDir()
156-
if err != nil {
157-
return "", err
156+
switch runtime.GOOS {
157+
case "darwin":
158+
userConfigDir, err := os.UserConfigDir()
159+
if err != nil {
160+
return "", err
161+
}
162+
return filepath.Join(userConfigDir, "ADBC", "Traces"), nil
163+
case "windows":
164+
userCacheDir, err := os.UserCacheDir()
165+
if err != nil {
166+
return "", err
167+
}
168+
return filepath.Join(userCacheDir, "ADBC", "Traces"), nil
169+
default:
170+
stateDir := os.Getenv("XDG_STATE_HOME")
171+
if strings.TrimSpace(stateDir) == "" {
172+
home, err := os.UserHomeDir()
173+
if err != nil {
174+
return "", err
175+
}
176+
stateDir = filepath.Join(home, ".local", "state")
177+
}
178+
return filepath.Join(stateDir, "adbc", "traces"), nil
158179
}
159-
fullPath := filepath.Join(userConfigDir, ".adbc", "traces")
160-
return fullPath, nil
161180
}
162181

163182
// Closes the rotating file write

go/adbc/driver/internal/driverbase/rotating_file_writer_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,51 @@
1818
package driverbase_test
1919

2020
import (
21+
"os"
22+
"path/filepath"
23+
"runtime"
2124
"testing"
2225

2326
"github.com/apache/arrow-adbc/go/adbc/driver/internal/driverbase"
2427
"github.com/stretchr/testify/require"
2528
)
2629

30+
func TestDefaultTracingFolderPath(t *testing.T) {
31+
tempDir := t.TempDir()
32+
33+
var expected string
34+
switch runtime.GOOS {
35+
case "windows":
36+
localAppDataDir := filepath.Join(tempDir, "AppData", "Local")
37+
t.Setenv("LocalAppData", localAppDataDir)
38+
expected = filepath.Join(localAppDataDir, "ADBC", "Traces")
39+
case "darwin":
40+
t.Setenv("HOME", tempDir)
41+
expected = filepath.Join(tempDir, "Library", "Application Support", "ADBC", "Traces")
42+
default:
43+
stateDir := filepath.Join(tempDir, ".local", "state")
44+
t.Setenv("XDG_STATE_HOME", stateDir)
45+
t.Setenv("HOME", tempDir)
46+
expected = filepath.Join(stateDir, "adbc", "traces")
47+
}
48+
49+
fw, err := driverbase.NewRotatingFileWriter()
50+
require.NoError(t, err)
51+
defer func() {
52+
err := fw.Clear()
53+
require.NoError(t, err)
54+
}()
55+
56+
require.Equal(t, expected, fw.GetTracingFolderPath())
57+
_, err = os.Stat(expected)
58+
require.NoError(t, err)
59+
}
60+
2761
func TestRotatingFileWriter(t *testing.T) {
62+
traceDir := t.TempDir()
2863

2964
fw, err := driverbase.NewRotatingFileWriter(
65+
driverbase.WithTracingFolderPath(traceDir),
3066
driverbase.WithFileSizeMaxKb(1),
3167
driverbase.WithFileCountMax(10),
3268
)
@@ -49,7 +85,10 @@ func TestRotatingFileWriter(t *testing.T) {
4985
}
5086

5187
func TestFileResuse(t *testing.T) {
88+
traceDir := t.TempDir()
89+
5290
fw1, err := driverbase.NewRotatingFileWriter(
91+
driverbase.WithTracingFolderPath(traceDir),
5392
driverbase.WithFileSizeMaxKb(1000),
5493
driverbase.WithFileCountMax(10),
5594
)
@@ -70,6 +109,7 @@ func TestFileResuse(t *testing.T) {
70109
require.NoError(t, err)
71110

72111
fw2, err := driverbase.NewRotatingFileWriter(
112+
driverbase.WithTracingFolderPath(traceDir),
73113
driverbase.WithFileSizeMaxKb(1000),
74114
driverbase.WithFileCountMax(10),
75115
)

0 commit comments

Comments
 (0)