Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.build
build
1 change: 1 addition & 0 deletions cmd/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type options struct {
flushInterval time.Duration
backend backends.StorageBackend
backendRoot string
prefix string

verbosity log.Level
}
Expand Down
7 changes: 7 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ func rootCmd() *cobra.Command {
"root path/location for the specified backend (e.g. bucket name for AWS S3)",
)

root.PersistentFlags().StringVar(
&opts.prefix,
prefixFlag,
"",
"directory prefix for saving parquet files",
)

root.PersistentFlags().VarP(
enumflag.New(&opts.verbosity, verbosityFlag, logLevelIDs, enumflag.EnumCaseInsensitive),
verbosityFlag,
Expand Down
13 changes: 11 additions & 2 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,17 @@ func (self *promserver) sendTimeseries(ctx context.Context, timeserieses []promp
var ok bool

nameLabel, _ := lo.Find(ts.Labels, func(i prompb.Label) bool { return i.Name == model.MetricNameLabel })
prefixLabel, _ := lo.Find(ts.Labels, func(i prompb.Label) bool { return i.Name == prefixLabelKey })
channelName := prefixLabel.Value + "/" + nameLabel.Value
prefixLabel, prefixFound := lo.Find(ts.Labels, func(i prompb.Label) bool { return i.Name == prefixLabelKey })

prefix := prefixLabel.Value
if !prefixFound || prefix == "" {
prefix = self.opts.prefix
}

channelName := prefix + "/" + nameLabel.Value
if prefix == "" {
channelName = nameLabel.Value
}

log.Debugf("received timeseries data for %s", channelName)

Expand Down
66 changes: 66 additions & 0 deletions cmd/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,69 @@ func TestSpawnWriter(t *testing.T) {
assert.Nil(t, err)
assert.Contains(t, srv.channels, channelName)
}

func TestSendTimeseriesWithCLIPrefix(t *testing.T) {
cliPrefix := "cli-prefix"
srv := newServer(&options{prefix: cliPrefix})
expectedChannelName := cliPrefix + "/" + metricName
srv.channels[expectedChannelName] = make(chan prompb.TimeSeries)

ts := prompb.TimeSeries{
Labels: []prompb.Label{
{
Name: model.MetricNameLabel,
Value: metricName,
},
{
Name: "foo",
Value: "bar",
},
},
Samples: []prompb.Sample{
{
Value: 1.0,
Timestamp: 0,
},
},
}

go func() {
err := srv.sendTimeseries(context.TODO(), []prompb.TimeSeries{ts})
assert.Nil(t, err)
}()

val := <-srv.channels[expectedChannelName]
assert.Equal(t, ts, val)
}

func TestSendTimeseriesWithoutPrefix(t *testing.T) {
srv := newServer(&options{})
srv.channels[metricName] = make(chan prompb.TimeSeries)

ts := prompb.TimeSeries{
Labels: []prompb.Label{
{
Name: model.MetricNameLabel,
Value: metricName,
},
{
Name: "foo",
Value: "bar",
},
},
Samples: []prompb.Sample{
{
Value: 1.0,
Timestamp: 0,
},
},
}

go func() {
err := srv.sendTimeseries(context.TODO(), []prompb.TimeSeries{ts})
assert.Nil(t, err)
}()

val := <-srv.channels[metricName]
assert.Equal(t, ts, val)
}
Comment on lines +125 to +189
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing test case for label priority: The implementation correctly prioritizes the prom2parquet_prefix label over the CLI --prefix argument (lines 122-125 in server.go), but there is no test verifying this behavior. Consider adding a test case that provides both a CLI prefix and a label prefix to ensure the label takes precedence as documented.

Copilot uses AI. Check for mistakes.
Loading