Skip to content

Commit

Permalink
Merge pull request #33 from RedisTimeSeries/updated-api
Browse files Browse the repository at this point in the history
adjust the adapter to the new redis-timeseries api
  • Loading branch information
danni-m authored Mar 7, 2019
2 parents 990a087 + d515d1a commit bb7c050
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 35 deletions.
27 changes: 2 additions & 25 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,11 @@ jobs:

working_directory: /go/src/github.com/RedisLabs/redis-ts-adapter
steps:
- setup_remote_docker
- checkout

# install redis
- run: git clone -b 5.0 --depth 1 https://github.com/antirez/redis.git
- run: cd redis && sudo make -j install

# install redis-timeseries
- run: git clone -b labels https://github.com/RedisLabsModules/redis-timeseries.git
- run: |
cd redis-timeseries
git submodule init
git submodule update
cd src
make -j all
# run redis with module
- run: |
redis-server --daemonize yes --loadmodule redis-timeseries/src/redis-tsdb-module.so RETENTION_POLICY 0 MAX_SAMPLE_PER_CHUNK 360
sleep 1
# run sentinel
- run: |
echo daemonize yes > sentinel.conf
echo sentinel monitor mymaster 127.0.0.1 6379 1 >> sentinel.conf
redis-sentinel sentinel.conf
# run tests and lint
- run: make test
- run: make dockerized_test
- run: curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sudo bash -s -- -b $GOPATH/bin v1.11.1
- run: make lint

Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ SRC_PKG = github.com/RedisLabs/redis-ts-adapter
DOCKER_IMAGE ?= redislabs/redis-ts-adapter
DOCKER_IMAGE_TAG ?= beta
DOCKER_BUILDER = redislabs/adapter-builder
TESTER_IMAGE = redislabs/ts-adapter-tester
BIN_PATH = $(BINDIR)/redis_ts_adapter

build:
Expand All @@ -27,6 +28,10 @@ clean:
test:
go test -v -cover ./...

dockerized_test:
docker build -t $(TESTER_IMAGE) -f build/tester.Dockerfile .
docker run $(TESTER_IMAGE)

lint:
golangci-lint run -E gofmt

Expand Down
23 changes: 23 additions & 0 deletions build/tester.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM circleci/golang:1.11
RUN echo /go && git clone -b 5.0 --depth 1 https://github.com/antirez/redis.git
RUN cd redis && sudo make -j install

RUN echo /go && git clone https://github.com/RedisLabsModules/redis-timeseries.git
RUN cd redis-timeseries && \
git submodule init && \
git submodule update && \
cd src && \
make -j all

RUN echo daemonize yes > /tmp/sentinel.conf
RUN echo sentinel monitor mymaster 127.0.0.1 6379 1 >> /tmp/sentinel.conf

WORKDIR /go/src/github.com/RedisLabs/redis-ts-adapter
RUN mkdir -p /go/src/github.com/RedisLabs/redis-ts-adapter

# This is not nessecerly the right way to do it, but it makes circleci works because it uses a remote docker host
COPY . /go/src/github.com/RedisLabs/redis-ts-adapter
#ENTRYPOINT /bin/bash
CMD redis-sentinel /tmp/sentinel.conf && \
redis-server --daemonize yes --loadmodule /go/redis-timeseries/src/redistimeseries.so RETENTION_POLICY 0 MAX_SAMPLE_PER_CHUNK 360 && \
sleep 1 && redis-cli ping && make test
21 changes: 12 additions & 9 deletions internal/redis_ts/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ func NewFailoverClient(failoverOpt *redis.FailoverOptions) *Client {
return (*Client)(client)
}

func add(key *string, labels *[]string, metric *string, timestamp *int64, value *float64) redis.Cmder {
args := make([]interface{}, 0, len(*labels)+3)
func add(key *string, labels []*prompb.Label, metric *string, timestamp *int64, value *float64) redis.Cmder {
args := make([]interface{}, 0, len(labels)+3)
args = append(args, "TS.ADD", *key)
for i := range *labels {
args = append(args, (*labels)[i])
}
args = append(args, "__name__="+*metric)
args = append(args, strconv.FormatInt(*timestamp/1000, 10))
args = append(args, strconv.FormatFloat(*value, 'f', 6, 64))
args = append(args, "LABELS")
for i := range labels {
args = append(args, labels[i].Name, labels[i].Value)
}
args = append(args, "__name__", *metric)
cmd := redis.NewStatusCmd(args...)
return cmd
}
Expand Down Expand Up @@ -68,7 +69,7 @@ func (c *Client) Write(timeseries []*prompb.TimeSeries) (returnErr error) {
continue
}

cmd := add(&key, labels, metric, &sample.Timestamp, &sample.Value)
cmd := add(&key, timeseries[i].Labels, metric, &sample.Timestamp, &sample.Value)
err := pipe.Process(cmd)
if err != nil {
return err
Expand Down Expand Up @@ -181,10 +182,12 @@ func (c *Client) Read(req *prompb.ReadRequest) (returnVal *prompb.ReadResponse,

func (c *Client) rangeByLabels(labelMatchers []interface{}, start int64, end int64) *redis.SliceCmd {
args := make([]interface{}, 0, len(labelMatchers)+3)
args = append(args, "TS.RANGEBYLABELS")
args = append(args, labelMatchers...)
args = append(args, "TS.MRANGE")
args = append(args, start)
args = append(args, end)
args = append(args, "FILTER")
args = append(args, labelMatchers...)
log.WithFields(log.Fields{"args": args}).Debug("ts.mrange")
cmd := redis.NewSliceCmd(args...)
return cmd
}
Expand Down
2 changes: 1 addition & 1 deletion internal/redis_ts/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestWriteSingleSample(t *testing.T) {
},
Samples: []prompb.Sample{
{
Timestamp: now.Unix(),
Timestamp: now.Unix() * 1000,
Value: answerToLifeTheUniverse,
},
},
Expand Down

0 comments on commit bb7c050

Please sign in to comment.