Compare commits
4 Commits
main
...
cloudwatch
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
165b25392b | ||
|
|
15e396ca92 | ||
|
|
f884f0809f | ||
|
|
9aad0aa428 |
@ -214,6 +214,8 @@ func genericCreateCommand(
|
||||
continue
|
||||
}
|
||||
|
||||
logger.Ctx(ictx).Infow("graph api stats", "stats", bo.Results.APIStats)
|
||||
|
||||
bIDs = append(bIDs, string(bo.Results.BackupID))
|
||||
|
||||
if !DisplayJSONFormat() {
|
||||
|
||||
@ -5,6 +5,9 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/alcionai/clues"
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/service/cloudwatch"
|
||||
"github.com/aws/aws-sdk-go/service/cloudwatch/cloudwatchiface"
|
||||
"github.com/google/uuid"
|
||||
|
||||
"github.com/alcionai/corso/src/internal/common/crash"
|
||||
@ -34,6 +37,7 @@ import (
|
||||
"github.com/alcionai/corso/src/pkg/path"
|
||||
"github.com/alcionai/corso/src/pkg/selectors"
|
||||
"github.com/alcionai/corso/src/pkg/store"
|
||||
"github.com/aws/aws-sdk-go/aws/session"
|
||||
)
|
||||
|
||||
// BackupOperation wraps an operation with backup-specific props.
|
||||
@ -70,6 +74,7 @@ type BackupResults struct {
|
||||
BackupID model.StableID `json:"backupID"`
|
||||
// keys are found in /pkg/count/keys.go
|
||||
Counts map[string]int64 `json:"counts"`
|
||||
stats.APIStats
|
||||
}
|
||||
|
||||
// NewBackupOperation constructs and validates a backup operation.
|
||||
@ -321,9 +326,56 @@ func (op *BackupOperation) Run(ctx context.Context) (err error) {
|
||||
logger.Ctx(ctx).Infow("completed backup", "results", op.Results)
|
||||
}
|
||||
|
||||
awsSession := session.Must(session.NewSession())
|
||||
cwClient := cloudwatch.New(awsSession)
|
||||
|
||||
tokens := op.Results.Counts[string(count.APICallTokensConsumed)]
|
||||
|
||||
logger.Ctx(ctx).Infow("publishing graph metrics",
|
||||
"tokens_used", tokens)
|
||||
PublishGraphMetrics(
|
||||
ctx,
|
||||
cwClient,
|
||||
op.Selectors.Service.String(),
|
||||
"tenantID",
|
||||
tokens)
|
||||
|
||||
return op.Errors.Failure()
|
||||
}
|
||||
|
||||
func PublishGraphMetrics(
|
||||
ctx context.Context,
|
||||
cwClient cloudwatchiface.CloudWatchAPI,
|
||||
serviceName, tenantID string,
|
||||
value int64) {
|
||||
_, err := cwClient.PutMetricData(&cloudwatch.PutMetricDataInput{
|
||||
Namespace: aws.String("mynamespace"),
|
||||
MetricData: []*cloudwatch.MetricDatum{
|
||||
// one metric at the tenant-level.
|
||||
{
|
||||
MetricName: aws.String("graph_api_tokens"),
|
||||
Unit: aws.String("Count"),
|
||||
Value: aws.Float64(float64(value)),
|
||||
Dimensions: []*cloudwatch.Dimension{
|
||||
{
|
||||
Name: aws.String("Service"),
|
||||
Value: aws.String(serviceName),
|
||||
},
|
||||
{
|
||||
Name: aws.String("TenantID"),
|
||||
Value: aws.String(tenantID),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
// do not block operations based on cloudwatch metrics
|
||||
logger.CtxErr(ctx, err).Info("error sending metric %s to cloudwatch", "onedrive_graph_api_tokens")
|
||||
}
|
||||
}
|
||||
|
||||
// do is purely the action of running a backup. All pre/post behavior
|
||||
// is found in Run().
|
||||
func (op *BackupOperation) do(
|
||||
@ -846,6 +898,10 @@ func (op *BackupOperation) persistResults(
|
||||
|
||||
op.Results.ItemsRead = opStats.ctrl.Successes
|
||||
|
||||
// API stats
|
||||
apiStats := getAPIStats(op.Counter)
|
||||
op.Results.APITokensConsumed = apiStats.APITokensConsumed
|
||||
|
||||
// Only return non-recoverable errors at this point.
|
||||
return op.Errors.Failure()
|
||||
}
|
||||
|
||||
@ -6,9 +6,11 @@ import (
|
||||
"github.com/alcionai/clues"
|
||||
|
||||
"github.com/alcionai/corso/src/internal/model"
|
||||
"github.com/alcionai/corso/src/internal/stats"
|
||||
"github.com/alcionai/corso/src/internal/streamstore"
|
||||
"github.com/alcionai/corso/src/pkg/backup"
|
||||
"github.com/alcionai/corso/src/pkg/backup/details"
|
||||
"github.com/alcionai/corso/src/pkg/count"
|
||||
"github.com/alcionai/corso/src/pkg/fault"
|
||||
"github.com/alcionai/corso/src/pkg/store"
|
||||
)
|
||||
@ -59,3 +61,12 @@ func getDetailsFromBackup(
|
||||
|
||||
return &deets, nil
|
||||
}
|
||||
|
||||
func getAPIStats(
|
||||
ctr *count.Bus,
|
||||
) stats.APIStats {
|
||||
s := stats.APIStats{}
|
||||
s.APITokensConsumed = ctr.Total(count.APICallTokensConsumed)
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
@ -43,3 +43,7 @@ type SkippedCounts struct {
|
||||
SkippedMalware int `json:"skippedMalware"`
|
||||
SkippedInvalidOneNoteFile int `json:"skippedInvalidOneNoteFile"`
|
||||
}
|
||||
|
||||
type APIStats struct {
|
||||
APITokensConsumed int64 `json:"apiTokensConsumed"`
|
||||
}
|
||||
|
||||
@ -4,7 +4,8 @@ type key string
|
||||
|
||||
const (
|
||||
// count of bucket-tokens consumed by api calls.
|
||||
APICallTokensConsumed key = "api-call-tokens-consumed"
|
||||
APICallTokensConsumed key = "api-call-tokens-consumed"
|
||||
PeakAPITokenUsagePerMin key = "peak-api-token-usage-per-min"
|
||||
// count of api calls that resulted in failure due to throttling.
|
||||
ThrottledAPICalls key = "throttled-api-calls"
|
||||
)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user