-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement deal and provider coverage calculation
Implement metrics that calculate deals and provider coverage by the indexer. Deal coverage is calculated as: sum of deals discoverable by the indexer divided by total discoverable deals. The term "discoverable" here implies that that the provider of the deal has a non-nil address discovered via FileCoin API. Provider coverage is calculated as: number of providers known by the indexer with at least one deal divided by total number of discoverable providers with at least one deal. This commit also removes WIP test files pushed by accident in earlier PRs. Fixes #5
- Loading branch information
Showing
9 changed files
with
398 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
) | ||
|
||
type dealStats struct { | ||
hf *heyFil | ||
refreshLock sync.RWMutex | ||
dealCountByParticipant map[string]int64 | ||
latestRefreshErr error | ||
} | ||
|
||
func (ds *dealStats) start(ctx context.Context) { | ||
go func() { | ||
for { | ||
ds.latestRefreshErr = ds.refresh(ctx) | ||
select { | ||
case <-ctx.Done(): | ||
return | ||
case <-ds.hf.dealStatsRefreshInterval.C: | ||
ds.latestRefreshErr = ds.refresh(ctx) | ||
} | ||
} | ||
}() | ||
} | ||
|
||
func (ds *dealStats) refresh(ctx context.Context) error { | ||
ch, err := ds.hf.chainHead(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
epoch := ch.Height | ||
|
||
deals, err := ds.hf.stateMarketDeals(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
dealCountByParticipant := make(map[string]int64) | ||
var totalDealCount int64 | ||
for { | ||
select { | ||
case <-ctx.Done(): | ||
return ctx.Err() | ||
case dr, ok := <-deals: | ||
if !ok { | ||
ds.refreshLock.Lock() | ||
ds.dealCountByParticipant = dealCountByParticipant | ||
ds.refreshLock.Unlock() | ||
ds.hf.metrics.notifyDealCount(totalDealCount) | ||
logger.Infow("fetched state market deals", "count", totalDealCount) | ||
return nil | ||
} | ||
switch { | ||
case dr.Err != nil: | ||
return dr.Err | ||
case dr.Deal.State.SectorStartEpoch == -1: | ||
case dr.Deal.State.SlashEpoch != -1: | ||
case dr.Deal.Proposal.EndEpoch < epoch: | ||
default: | ||
totalDealCount++ | ||
dealProvider := dr.Deal.Proposal.Provider | ||
dealCountByParticipant[dealProvider] = dealCountByParticipant[dealProvider] + 1 | ||
} | ||
} | ||
} | ||
} | ||
|
||
func (ds *dealStats) getDealCount(id string) int64 { | ||
ds.refreshLock.RLock() | ||
defer ds.refreshLock.RUnlock() | ||
return ds.dealCountByParticipant[id] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
|
||
"github.com/libp2p/go-libp2p/core/peer" | ||
) | ||
|
||
func (hf *heyFil) isKnownByIndexer(ctx context.Context, pid peer.ID) (bool, error) { | ||
url := hf.httpIndexerEndpoint + `/providers/` + pid.String() | ||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) | ||
if err != nil { | ||
return false, err | ||
} | ||
response, err := hf.httpClient.Do(req) | ||
if err != nil { | ||
return false, err | ||
} | ||
defer response.Body.Close() | ||
body, err := io.ReadAll(response.Body) | ||
if err != nil { | ||
return false, err | ||
} | ||
if response.StatusCode != http.StatusOK { | ||
return false, fmt.Errorf("unsuccessful response %d : %s", response.StatusCode, string(body)) | ||
} | ||
return true, nil | ||
} |
Oops, something went wrong.