Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

write: Set partition key salt using HTTP header #135

Merged
merged 3 commits into from
Sep 28, 2017
Merged
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
12 changes: 7 additions & 5 deletions internal/write/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ import (
)

const (
HttpHeaderInternalWrite = "X-AthensDB-Internal-Write-Version"
HttpHeaderInternalWriteVersion = "0.0.1"
HTTPHeaderInternalWrite = "X-AthensDB-Internal-Write-Version"
HTTPHeaderInternalWriteVersion = "0.0.1"
HTTPHeaderPartitionKeySalt = "X-AthensDB-Partition-Key-Salt"
Route = "/receive"

httpHeaderRemoteWrite = "X-Prometheus-Remote-Write-Version"
Expand Down Expand Up @@ -79,7 +80,7 @@ func (wr *writer) Handler(w http.ResponseWriter, r *http.Request) {

// This is an internal write, so don't replicate it to other nodes
// This case is very common, to make it fast
if r.Header.Get(HttpHeaderInternalWrite) != "" {
if r.Header.Get(HTTPHeaderInternalWrite) != "" {
wr.mu.Lock()
appender, err := wr.store.Appender()
if err != nil {
Expand Down Expand Up @@ -116,6 +117,7 @@ func (wr *writer) Handler(w http.ResponseWriter, r *http.Request) {
seriesToNodes[*n] = make(seriesMap, numPreallocTimeseries)
}

pSalt := []byte(r.Header.Get(HTTPHeaderPartitionKeySalt))
for _, ts := range req.Timeseries {
m := make(labels.Labels, 0, len(ts.Labels))
for _, l := range ts.Labels {
Expand All @@ -131,7 +133,7 @@ func (wr *writer) Handler(w http.ResponseWriter, r *http.Request) {
for _, s := range ts.Samples {
timestamp := time.Unix(s.Timestamp/1000, (s.Timestamp-s.Timestamp/1000)*1e6)
// FIXME: Avoid panic if the cluster is not yet initialised
pKey := cluster.PartitionKey([]byte{}, timestamp)
pKey := cluster.PartitionKey(pSalt, timestamp)
for _, n := range wr.clstr.NodesByPartitionKey(pKey) {
if _, ok := seriesToNodes[*n][mHash]; !ok {
// FIXME handle change in cluster size
Expand Down Expand Up @@ -239,7 +241,7 @@ func (wr *writer) remoteWrite(sNodeMap seriesNodeMap) error {
nodeReq.Header.Add("Content-Encoding", "snappy")
nodeReq.Header.Set("Content-Type", "application/x-protobuf")
nodeReq.Header.Set(httpHeaderRemoteWrite, httpHeaderRemoteWriteVersion)
nodeReq.Header.Set(HttpHeaderInternalWrite, HttpHeaderInternalWriteVersion)
nodeReq.Header.Set(HTTPHeaderInternalWrite, HTTPHeaderInternalWriteVersion)

// FIXME set timeout using context
httpResp, err := ctxhttp.Do(context.TODO(), http.DefaultClient, nodeReq)
Expand Down