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

Commit

Permalink
record successful retrievals served (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
aarshkshah1992 authored Aug 30, 2022
1 parent 9c8a3fc commit 9be5e9e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 18 deletions.
6 changes: 6 additions & 0 deletions carserver/station_api_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,16 @@ func (s *StationAPIImpl) RecordRetrievalServed(ctx context.Context, bytesServed,
return s.createOrUpdateReqStatsUnlocked(ctx, func(r *station.ReqStats) {
r.TotalBytesUploaded = bytesServed
r.NContentRequests = 1
if nErrors == 0 {
r.NSuccessfulRetrievals = 1
}
r.NContentReqErrors = nErrors
}, func(r *station.ReqStats) {
r.TotalBytesUploaded += bytesServed
r.NContentRequests += 1
if nErrors == 0 {
r.NSuccessfulRetrievals += 1
}
r.NContentReqErrors += nErrors
})
}
Expand Down
41 changes: 30 additions & 11 deletions carserver/station_api_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ func TestStationAPIImpl(t *testing.T) {
BytesCurrentlyStored: 790,
},
ReqStats: station.ReqStats{
TotalBytesUploaded: 100,
NContentRequests: 1,
TotalBytesDownloaded: 300,
TotalBytesUploaded: 100,
NContentRequests: 1,
TotalBytesDownloaded: 300,
NSuccessfulRetrievals: 1,
}}, as)

require.NoError(t, sapi.RecordRetrievalServed(ctx, 500, 2))
Expand All @@ -67,10 +68,11 @@ func TestStationAPIImpl(t *testing.T) {
BytesCurrentlyStored: 790,
},
ReqStats: station.ReqStats{
TotalBytesUploaded: 600,
NContentRequests: 2,
NContentReqErrors: 2,
TotalBytesDownloaded: 300,
TotalBytesUploaded: 600,
NContentRequests: 2,
NContentReqErrors: 2,
TotalBytesDownloaded: 300,
NSuccessfulRetrievals: 1,
}}, as)

// restart API -> we should still get the same values
Expand All @@ -84,11 +86,28 @@ func TestStationAPIImpl(t *testing.T) {
BytesCurrentlyStored: 790,
},
ReqStats: station.ReqStats{
TotalBytesUploaded: 600,
NContentRequests: 2,
NContentReqErrors: 2,
TotalBytesDownloaded: 300,
TotalBytesUploaded: 600,
NContentRequests: 2,
NContentReqErrors: 2,
NSuccessfulRetrievals: 1,
TotalBytesDownloaded: 300,
}}, as)

require.NoError(t, sapi.RecordRetrievalServed(ctx, 500, 0))
as, err = sapi.AllStats(ctx)
require.NoError(t, err)
require.Equal(t, station.StationStats{RPInfo: station.RPInfo{Version: Version},
StorageStats: station.StorageStats{
BytesCurrentlyStored: 790,
},
ReqStats: station.ReqStats{
TotalBytesUploaded: 1100,
NContentRequests: 3,
NContentReqErrors: 2,
NSuccessfulRetrievals: 2,
TotalBytesDownloaded: 300,
}}, as)

}

type mockStorageStatsFetcher struct {
Expand Down
6 changes: 3 additions & 3 deletions cmd/saturn-l2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const (

// L1_DISCOVERY_URL_VAR configures the environment variable that determines the URL of the L1 Discovery API to invoke to
// get back the L1 nodes this L2 node will connect and serve CAR files to.
// Defaults to `defaultOrchestratorURL`.
// Defaults to `defaultL1DiscoveryURL`.
L1_DISCOVERY_URL_VAR = "L1_DISCOVERY_API_URL"

// MAX_L1s_VAR configures the environment variable that determines the maximum
Expand Down Expand Up @@ -111,7 +111,7 @@ var (
// DNS Hostname of Saturn L1 Nodes
saturn_l1_hostName = "strn.pl"

defaultOrchestratorURL = "https://orchestrator.strn.pl/nodes/nearby"
defaultL1DiscoveryURL = "https://orchestrator.strn.pl/nodes/nearby"
)

type config struct {
Expand Down Expand Up @@ -349,7 +349,7 @@ func mkConfig() (config, error) {
// parse L1 Discovery API URL
durl, exists = os.LookupEnv(L1_DISCOVERY_URL_VAR)
if !exists {
durl = defaultOrchestratorURL
durl = defaultL1DiscoveryURL
}
if _, err := url.Parse(durl); err != nil {
return config{}, fmt.Errorf("l1 discovery api url is invalid, failed to parse, err=%w", err)
Expand Down
9 changes: 5 additions & 4 deletions station/station.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ type StorageStats struct {
}

type ReqStats struct {
TotalBytesUploaded uint64
TotalBytesDownloaded uint64
NContentRequests uint64
NContentReqErrors uint64
TotalBytesUploaded uint64
TotalBytesDownloaded uint64
NContentRequests uint64
NContentReqErrors uint64
NSuccessfulRetrievals uint64
}

0 comments on commit 9be5e9e

Please sign in to comment.