Skip to content

Commit 1e6506d

Browse files
committed
cli: fix cost estimate in tsdump upload
Previously, tsdump upload over-estimated the cost by not de-duplicating identical metrics. This is now corrected. Epic: none Release note: None
1 parent c63a85b commit 1e6506d

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

pkg/cli/testdata/tsdump_upload_e2e

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ cr.store.rocksdb.block.cache.usage,2021-01-01T00:00:00Z,2,75.2
88
----
99
{"series":[{"interval":10,"metric":"crdb.tsdump.admission.admitted.elastic-cpu","points":[{"timestamp":1748248320,"value":1}],"tags":["node_id:1","cluster_type:SELF_HOSTED","cluster_label:\"test-cluster\"","cluster_id:test-cluster-id","zendesk_ticket:zd-test","org_name:test-org","user_name:test-user","upload_id:\"test-cluster\"-20241114000000","upload_timestamp:2024-11-14 00:00:00","upload_year:2024","upload_month:11","upload_day:14"],"type":0},{"interval":10,"metric":"crdb.tsdump.sql.query.count","points":[{"timestamp":1609459200,"value":100.5}],"tags":["node_id:1","cluster_type:SELF_HOSTED","cluster_label:\"test-cluster\"","cluster_id:test-cluster-id","zendesk_ticket:zd-test","org_name:test-org","user_name:test-user","upload_id:\"test-cluster\"-20241114000000","upload_timestamp:2024-11-14 00:00:00","upload_year:2024","upload_month:11","upload_day:14"],"type":0},{"interval":10,"metric":"crdb.tsdump.sql.query.count","points":[{"timestamp":1609459210,"value":102.3}],"tags":["node_id:1","cluster_type:SELF_HOSTED","cluster_label:\"test-cluster\"","cluster_id:test-cluster-id","zendesk_ticket:zd-test","org_name:test-org","user_name:test-user","upload_id:\"test-cluster\"-20241114000000","upload_timestamp:2024-11-14 00:00:00","upload_year:2024","upload_month:11","upload_day:14"],"type":0},{"interval":10,"metric":"crdb.tsdump.rocksdb.block.cache.usage","points":[{"timestamp":1609459200,"value":75.2}],"tags":["store:2","cluster_type:SELF_HOSTED","cluster_label:\"test-cluster\"","cluster_id:test-cluster-id","zendesk_ticket:zd-test","org_name:test-org","user_name:test-user","upload_id:\"test-cluster\"-20241114000000","upload_timestamp:2024-11-14 00:00:00","upload_year:2024","upload_month:11","upload_day:14"],"type":0}]}
1010

11-
[{"ddsource":"tsdump_upload","ddtags":"cluster_type:SELF_HOSTED,cluster_label:\"test-cluster\",cluster_id:test-cluster-id,zendesk_ticket:zd-test,org_name:test-org,user_name:test-user,upload_id:\"test-cluster\"-20241114000000,upload_timestamp:2024-11-14 00:00:00,upload_year:2024,upload_month:11,upload_day:14,series_uploaded:4","hostname":"hostname","message":"{\"message\":\"tsdump upload completed: uploaded 4 series overall\",\"series_uploaded\":4,\"estimated_cost\":0.00024931506849315067,\"duration\":0,\"dry_run\":false,\"success\":true}","service":"tsdump_upload"}]
11+
[{"ddsource":"tsdump_upload","ddtags":"cluster_type:SELF_HOSTED,cluster_label:\"test-cluster\",cluster_id:test-cluster-id,zendesk_ticket:zd-test,org_name:test-org,user_name:test-user,upload_id:\"test-cluster\"-20241114000000,upload_timestamp:2024-11-14 00:00:00,upload_year:2024,upload_month:11,upload_day:14,series_uploaded:4","hostname":"hostname","message":"{\"message\":\"tsdump upload completed: uploaded 4 series overall\",\"series_uploaded\":4,\"estimated_cost\":0.000186986301369863,\"duration\":0,\"dry_run\":false,\"success\":true}","service":"tsdump_upload"}]
1212
----
1313
----

pkg/cli/tsdump_upload.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"fmt"
1515
"io"
1616
"os"
17+
"sort"
1718
"strconv"
1819
"strings"
1920
"sync"
@@ -372,6 +373,7 @@ func (d *datadogWriter) upload(fileName string) error {
372373
}
373374

374375
dec := gob.NewDecoder(f)
376+
allMetrics := make(map[string]struct{})
375377
decodeOne := func() ([]datadogV2.MetricSeries, error) {
376378
var ddSeries []datadogV2.MetricSeries
377379

@@ -387,6 +389,11 @@ func (d *datadogWriter) upload(fileName string) error {
387389
return nil, err
388390
}
389391
ddSeries = append(ddSeries, *datadogSeries)
392+
tags := datadogSeries.Tags
393+
sort.Strings(tags)
394+
tagsStr := strings.Join(tags, ",")
395+
metricCtx := datadogSeries.Metric + "|" + tagsStr
396+
allMetrics[metricCtx] = struct{}{}
390397
}
391398

392399
return ddSeries, nil
@@ -470,14 +477,16 @@ func (d *datadogWriter) upload(fileName string) error {
470477
}
471478
fmt.Printf("\nUpload status: %s!\n", uploadStatus)
472479
fmt.Printf("Uploaded %d series overall\n", seriesUploaded)
480+
fmt.Printf("Uploaded %d unique series overall\n", len(allMetrics))
481+
473482
// Estimate cost. The cost of historical metrics ingest is based on how many
474483
// metrics were active during the upload window. Assuming the entire upload
475484
// happens during a given hour, that means the cost will be equal to the count
476485
// of uploaded series times $4.55/100 custom metrics (our rate) divided by
477486
// 730 hours per month.
478487
// For a single node upload that has 6500 unique series, that's about $.40
479488
// per upload.
480-
estimatedCost := float64(seriesUploaded) * 4.55 / 100 / 730
489+
estimatedCost := float64(len(allMetrics)) * 4.55 / 100 / 730
481490
fmt.Printf("Estimated cost of this upload: $%.2f\n", estimatedCost)
482491

483492
tags := getUploadTags(d)

0 commit comments

Comments
 (0)