mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-28 01:31:17 +00:00
Inline StoreBytes
This commit is contained in:
@@ -208,14 +208,9 @@ func (c *MemcacheClient) FetchReports(keys []string) (map[string]report.Report,
|
||||
func (c *MemcacheClient) StoreReport(key string, report *report.Report) (int, error) {
|
||||
var buf bytes.Buffer
|
||||
report.WriteBinary(&buf, c.compressionLevel)
|
||||
err := c.StoreBytes(key, buf.Bytes())
|
||||
return buf.Len(), err
|
||||
}
|
||||
|
||||
// StoreBytes stores a report, expecting the report to be serialized already.
|
||||
func (c *MemcacheClient) StoreBytes(key string, content []byte) error {
|
||||
return instrument.TimeRequestHistogramStatus("Put", memcacheRequestDuration, memcacheStatusCode, func() error {
|
||||
item := memcache.Item{Key: key, Value: content, Expiration: c.expiration}
|
||||
err := instrument.TimeRequestHistogramStatus("Put", memcacheRequestDuration, memcacheStatusCode, func() error {
|
||||
item := memcache.Item{Key: key, Value: buf.Bytes(), Expiration: c.expiration}
|
||||
return c.client.Set(&item)
|
||||
})
|
||||
return buf.Len(), err
|
||||
}
|
||||
|
||||
@@ -91,19 +91,13 @@ func (store *S3Store) fetchReport(key string) (*report.Report, error) {
|
||||
func (store *S3Store) StoreReport(key string, report *report.Report) (int, error) {
|
||||
var buf bytes.Buffer
|
||||
report.WriteBinary(&buf, gzip.BestCompression)
|
||||
err := store.StoreBytes(key, buf.Bytes())
|
||||
return buf.Len(), err
|
||||
}
|
||||
|
||||
// StoreBytes stores a report in S3, expecting the report to be serialized
|
||||
// already.
|
||||
func (store *S3Store) StoreBytes(key string, content []byte) error {
|
||||
return instrument.TimeRequestHistogram("Put", s3RequestDuration, func() error {
|
||||
err := instrument.TimeRequestHistogram("Put", s3RequestDuration, func() error {
|
||||
_, err := store.s3.PutObject(&s3.PutObjectInput{
|
||||
Body: bytes.NewReader(content),
|
||||
Body: bytes.NewReader(buf.Bytes()),
|
||||
Bucket: aws.String(store.bucketName),
|
||||
Key: aws.String(key),
|
||||
})
|
||||
return err
|
||||
})
|
||||
return buf.Len(), err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user