Use StoreReport in main AWS routine

This commit is contained in:
Jonathan Lange
2016-07-15 10:05:55 +01:00
parent 46dfeb627d
commit 1fd8a5fb88
3 changed files with 12 additions and 14 deletions

View File

@@ -1,8 +1,6 @@
package multitenant
import (
"bytes"
"compress/gzip"
"crypto/md5"
"fmt"
"io"
@@ -361,26 +359,22 @@ func (c *awsCollector) Add(ctx context.Context, rep report.Report) error {
return err
}
// first, encode the report into a buffer and record its size
var buf bytes.Buffer
rep.WriteBinary(&buf, gzip.BestCompression)
reportSizeHistogram.Observe(float64(buf.Len()))
// second, put the report on s3
// first, put the report on s3
rowKey, colKey := calculateDynamoKeys(userid, time.Now())
reportKey, err := calculateReportKey(rowKey, colKey)
if err != nil {
return err
}
err = c.s3.StoreBytes(reportKey, buf.Bytes())
reportSize, err := c.s3.StoreReport(reportKey, &rep)
if err != nil {
return err
}
reportSizeHistogram.Observe(float64(reportSize))
// third, put it in memcache
if c.memcache != nil {
err = c.memcache.StoreBytes(reportKey, buf.Bytes())
_, err = c.memcache.StoreReport(reportKey, &rep)
if err != nil {
// NOTE: We don't abort here because failing to store in memcache
// doesn't actually break anything else -- it's just an

View File

@@ -204,10 +204,11 @@ func (c *MemcacheClient) FetchReports(keys []string) (map[string]report.Report,
}
// StoreReport serializes and stores a report.
func (c *MemcacheClient) StoreReport(key string, report *report.Report) error {
func (c *MemcacheClient) StoreReport(key string, report *report.Report) (int, error) {
var buf bytes.Buffer
report.WriteBinary(&buf, gzip.BestCompression)
return c.StoreBytes(key, buf.Bytes())
err := c.StoreBytes(key, buf.Bytes())
return buf.Len(), err
}
// StoreBytes stores a report, expecting the report to be serialized already.

View File

@@ -86,10 +86,13 @@ func (store *S3Store) fetchReport(key string) (*report.Report, error) {
}
// StoreReport serializes and stores a report.
func (store *S3Store) StoreReport(key string, report *report.Report) error {
//
// Returns the size of the report. This only equals bytes written if err is nil.
func (store *S3Store) StoreReport(key string, report *report.Report) (int, error) {
var buf bytes.Buffer
report.WriteBinary(&buf, gzip.BestCompression)
return store.StoreBytes(key, buf.Bytes())
err := store.StoreBytes(key, buf.Bytes())
return buf.Len(), err
}
// StoreBytes stores a report in S3, expecting the report to be serialized