Skip to content

Commit

Permalink
[proto] Annotate timeseries field of WriteRequest as non-nullable (#2025
Browse files Browse the repository at this point in the history
)
  • Loading branch information
jeromefroe authored Oct 29, 2019
1 parent 7da4640 commit 8e64151
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/query/api/v1/handler/prometheus/remote/test/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
// write request.
func GeneratePromWriteRequest() *prompb.WriteRequest {
req := &prompb.WriteRequest{
Timeseries: []*prompb.TimeSeries{{
Timeseries: []prompb.TimeSeries{{
Labels: []prompb.Label{
{Name: []byte("__name__"), Value: []byte("first")},
{Name: []byte("foo"), Value: []byte("bar")},
Expand Down
2 changes: 1 addition & 1 deletion src/query/api/v1/handler/prometheus/remote/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ func (h *PromWriteHandler) forward(
return nil
}

func newPromTSIter(timeseries []*prompb.TimeSeries, tagOpts models.TagOptions) *promTSIter {
func newPromTSIter(timeseries []prompb.TimeSeries, tagOpts models.TagOptions) *promTSIter {
// Construct the tags and datapoints upfront so that if the iterator
// is reset, we don't have to generate them twice.
var (
Expand Down
10 changes: 5 additions & 5 deletions src/query/benchmark/benchmarker/main/convert_to_prom.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func convertToProm(fromFile, dir, toFile string, workers int, batchSize int, log
if err != nil {
return 0, err
}
series := make([]*prompb.TimeSeries, 0, batchSize)
series := make([]prompb.TimeSeries, 0, batchSize)

for line := 0; line < batchSize; line++ {
if scanner.Scan() {
Expand All @@ -139,7 +139,7 @@ func convertToProm(fromFile, dir, toFile string, workers int, batchSize int, log
return lines, nil
}

func encodeWriteRequest(ts []*prompb.TimeSeries) []byte {
func encodeWriteRequest(ts []prompb.TimeSeries) []byte {
req := &prompb.WriteRequest{
Timeseries: ts,
}
Expand All @@ -155,11 +155,11 @@ type metrics struct {
Value float64 `json:"value"`
}

func marshalTSDBToProm(opentsdb string) (*prompb.TimeSeries, error) {
func marshalTSDBToProm(opentsdb string) (prompb.TimeSeries, error) {
var m metrics
data := []byte(opentsdb)
if err := json.Unmarshal(data, &m); err != nil {
return nil, err
return prompb.TimeSeries{}, err
}

tags := models.EmptyTags()
Expand All @@ -169,7 +169,7 @@ func marshalTSDBToProm(opentsdb string) (*prompb.TimeSeries, error) {

labels := storage.TagsToPromLabels(tags)
samples := metricsPointsToSamples(m.Value, m.Time)
return &prompb.TimeSeries{
return prompb.TimeSeries{
Labels: labels,
Samples: samples,
}, nil
Expand Down
8 changes: 4 additions & 4 deletions src/query/benchmark/common/parse_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func id(lowerCaseTags map[string]string, name string) string {
return buffer.String()
}

func metricsToPromTS(m Metrics) *prompb.TimeSeries {
func metricsToPromTS(m Metrics) prompb.TimeSeries {
tags := models.NewTags(len(m.Tags), nil)
for n, v := range m.Tags {
tags = tags.AddTagWithoutNormalizing(
Expand All @@ -180,14 +180,14 @@ func metricsToPromTS(m Metrics) *prompb.TimeSeries {
tags.Normalize()
labels := storage.TagsToPromLabels(tags)
samples := metricsPointsToSamples(m.Value, m.Time)
return &prompb.TimeSeries{
return prompb.TimeSeries{
Labels: labels,
Samples: samples,
}
}

func marshalTSDBToProm(dataChannel <-chan []byte, metricChannel chan<- *bytes.Reader, batchSize int) {
timeseries := make([]*prompb.TimeSeries, batchSize)
timeseries := make([]prompb.TimeSeries, batchSize)
idx := 0
for data := range dataChannel {
if len(data) == 0 {
Expand All @@ -210,7 +210,7 @@ func marshalTSDBToProm(dataChannel <-chan []byte, metricChannel chan<- *bytes.Re
}
}

func encodeWriteRequest(ts []*prompb.TimeSeries) *bytes.Reader {
func encodeWriteRequest(ts []prompb.TimeSeries) *bytes.Reader {
req := &prompb.WriteRequest{
Timeseries: ts,
}
Expand Down
55 changes: 29 additions & 26 deletions src/query/generated/proto/prompb/remote.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/query/generated/proto/prompb/remote.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ package prometheus;
option go_package = "prompb";

import "github.com/m3db/m3/src/query/generated/proto/prompb/types.proto";
import "github.com/gogo/protobuf/gogoproto/gogo.proto";

message WriteRequest {
repeated prometheus.TimeSeries timeseries = 1;
repeated prometheus.TimeSeries timeseries = 1 [(gogoproto.nullable) = false];
}

message ReadRequest {
Expand Down

0 comments on commit 8e64151

Please sign in to comment.