Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
feat: record number of empty STI responses
Browse files Browse the repository at this point in the history
  • Loading branch information
guseggert committed Sep 15, 2022
1 parent 5ae1c96 commit b95d1f4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
9 changes: 8 additions & 1 deletion metrics/definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var (
defaultMillisecondsDistribution = view.Distribution(0.01, 0.05, 0.1, 0.3, 0.6, 0.8, 1, 2, 3, 4, 5, 6, 8, 10, 13, 16, 20, 25, 30, 40, 50, 65, 80, 100, 130, 160, 200, 250, 300, 400, 500, 650, 800, 1000, 2000, 5000, 10000, 20000, 50000, 100000)
// a coarser-grained milliseconds distribution for metrics with higher cardinality and where we don't need a more fine-grained distribution
coarseMillisecondsDistribution = view.Distribution(0, 1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000)
defaultProvidersDistribution = view.Distribution(0, 1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000)
defaultProvidersDistribution = view.Distribution(0.5, 1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000)
)

// Keys
Expand Down Expand Up @@ -69,6 +69,7 @@ var (
STIFindProvs = stats.Int64("sti_find_provs_total", "Total store the index find provider attempts that were found locally, or not found locally and succeeded, failed or were discarded", stats.UnitDimensionless)
STIFindProvsDuration = stats.Float64("sti_find_provs_duration", "The time it took storetheindex finds from the network to succeed or fail because of timeout or completion", stats.UnitMilliseconds)
STIFindProvsLength = stats.Int64("sti_find_provs_length", "Number of providers returned for successful responses", stats.UnitDimensionless)
STIFindProvsEmpty = stats.Int64("sti_find_provs_empty", "Number of empty responses returned", stats.UnitDimensionless)

AWSRequests = stats.Int64("aws_reqs", "Requests made to AWS", stats.UnitDimensionless)
AWSRequestDurationMillis = stats.Float64("aws_req_duration", "The time it took to make an AWS request and receive a response", stats.UnitMilliseconds)
Expand Down Expand Up @@ -208,6 +209,11 @@ var (
TagKeys: []tag.Key{KeyName},
Aggregation: defaultProvidersDistribution,
}
STIFindProvsEmptyView = &view.View{
Measure: STIFindProvsEmpty,
TagKeys: []tag.Key{KeyName},
Aggregation: view.Sum(),
}
// DHT views
ReceivedMessagesView = &view.View{
Measure: dhtmetrics.ReceivedMessages,
Expand Down Expand Up @@ -344,6 +350,7 @@ var DefaultViews = []*view.View{
STIFindProvsView,
STIFindProvsDurationView,
STIFindProvsLengthView,
STIFindProvsEmptyView,
ProviderRecordsPerKeyView,
PrefetchesView,
PrefetchDurationMillisView,
Expand Down
13 changes: 12 additions & 1 deletion providers/reframe.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ func (x *reframeProvider) AddProvider(ctx context.Context, key []byte, prov peer
return fmt.Errorf("reframe does not support adding providers")
}

func emptyIndicator(x int64) int64 {
if x == 0 {
return 1
}
return 0
}

func (x *reframeProvider) GetProviders(ctx context.Context, key []byte) ([]peer.AddrInfo, error) {
mh, err := multihash.Cast(key)
if err != nil {
Expand All @@ -47,12 +54,16 @@ func (x *reframeProvider) GetProviders(ctx context.Context, key []byte) ([]peer.
cid1 := cid.NewCidV1(cid.Raw, mh)
start := time.Now()
peers, err := x.reframe.FindProviders(ctx, cid1)

if err != nil {
log.Errorf("reframe error: %s", err)
recordReframeFindProvsComplete(ctx, metricsErrStr(err), time.Since(start))
} else {
recordReframeFindProvsComplete(ctx, "Success", time.Since(start))
stats.Record(ctx, metrics.STIFindProvsLength.M(int64(len(peers))))
numPeers := int64(len(peers))
stats.Record(ctx, metrics.STIFindProvsLength.M(numPeers))
stats.Record(ctx, metrics.STIFindProvsEmpty.M(emptyIndicator(numPeers)))
fmt.Printf("numPeers: %d\n", numPeers)
}
return peers, err
}
Expand Down

0 comments on commit b95d1f4

Please sign in to comment.