Move code around
This commit is contained in:
parent
f884f0809f
commit
15e396ca92
@ -6,7 +6,6 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync/atomic"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/alcionai/clues"
|
"github.com/alcionai/clues"
|
||||||
@ -326,8 +325,6 @@ func (mw RetryMiddleware) getRetryDelay(
|
|||||||
// MetricsMiddleware aggregates per-request metrics on the events bus
|
// MetricsMiddleware aggregates per-request metrics on the events bus
|
||||||
type MetricsMiddleware struct{}
|
type MetricsMiddleware struct{}
|
||||||
|
|
||||||
var xmCount int64
|
|
||||||
|
|
||||||
const xmruHeader = "x-ms-resource-unit"
|
const xmruHeader = "x-ms-resource-unit"
|
||||||
|
|
||||||
func (mw *MetricsMiddleware) Intercept(
|
func (mw *MetricsMiddleware) Intercept(
|
||||||
@ -365,9 +362,6 @@ func (mw *MetricsMiddleware) Intercept(
|
|||||||
xmrui = 1
|
xmrui = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
atomic.AddInt64(&xmCount, int64(xmrui))
|
|
||||||
logger.Ctx(req.Context()).Info("xmcount ", xmCount)
|
|
||||||
|
|
||||||
countBus := count.Ctx(req.Context())
|
countBus := count.Ctx(req.Context())
|
||||||
countBus.Add(count.APICallTokensConsumed, int64(xmrui))
|
countBus.Add(count.APICallTokensConsumed, int64(xmrui))
|
||||||
|
|
||||||
|
|||||||
@ -848,8 +848,8 @@ func (op *BackupOperation) persistResults(
|
|||||||
op.Results.ItemsRead = opStats.ctrl.Successes
|
op.Results.ItemsRead = opStats.ctrl.Successes
|
||||||
|
|
||||||
// API stats
|
// API stats
|
||||||
apiStats := stats.GetAPIStats(op.Counter)
|
apiStats := getAPIStats(op.Counter)
|
||||||
op.Results.TokensConsumed = apiStats.TokensConsumed
|
op.Results.APITokensConsumed = apiStats.APITokensConsumed
|
||||||
|
|
||||||
// Only return non-recoverable errors at this point.
|
// Only return non-recoverable errors at this point.
|
||||||
return op.Errors.Failure()
|
return op.Errors.Failure()
|
||||||
|
|||||||
@ -6,9 +6,11 @@ import (
|
|||||||
"github.com/alcionai/clues"
|
"github.com/alcionai/clues"
|
||||||
|
|
||||||
"github.com/alcionai/corso/src/internal/model"
|
"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/internal/streamstore"
|
||||||
"github.com/alcionai/corso/src/pkg/backup"
|
"github.com/alcionai/corso/src/pkg/backup"
|
||||||
"github.com/alcionai/corso/src/pkg/backup/details"
|
"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/fault"
|
||||||
"github.com/alcionai/corso/src/pkg/store"
|
"github.com/alcionai/corso/src/pkg/store"
|
||||||
)
|
)
|
||||||
@ -59,3 +61,12 @@ func getDetailsFromBackup(
|
|||||||
|
|
||||||
return &deets, nil
|
return &deets, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getAPIStats(
|
||||||
|
ctr *count.Bus,
|
||||||
|
) stats.APIStats {
|
||||||
|
s := stats.APIStats{}
|
||||||
|
s.APITokensConsumed = ctr.Total(count.APICallTokensConsumed)
|
||||||
|
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|||||||
@ -3,8 +3,6 @@ package stats
|
|||||||
import (
|
import (
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/alcionai/corso/src/pkg/count"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ReadWrites tracks the total count of reads and writes. ItemsRead
|
// ReadWrites tracks the total count of reads and writes. ItemsRead
|
||||||
@ -47,15 +45,5 @@ type SkippedCounts struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type APIStats struct {
|
type APIStats struct {
|
||||||
TokensConsumed int64 `json:"tokensConsumed"`
|
APITokensConsumed int64 `json:"apiTokensConsumed"`
|
||||||
}
|
|
||||||
|
|
||||||
func GetAPIStats(
|
|
||||||
ctr *count.Bus,
|
|
||||||
) APIStats {
|
|
||||||
s := APIStats{}
|
|
||||||
|
|
||||||
s.TokensConsumed = ctr.Total(count.APICallTokensConsumed)
|
|
||||||
|
|
||||||
return s
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user