-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(eventindexer): add stats tracking (#13810)
- Loading branch information
1 parent
10be2fb
commit bfbbb97
Showing
37 changed files
with
1,414 additions
and
330 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 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
Large diffs are not rendered by default.
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
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,19 @@ | ||
package http | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/cyberhorsey/webutils" | ||
"github.com/labstack/echo/v4" | ||
) | ||
|
||
func (srv *Server) GetStats(c echo.Context) error { | ||
stats, err := srv.statRepo.Find( | ||
c.Request().Context(), | ||
) | ||
if err != nil { | ||
return webutils.LogAndRenderErrors(c, http.StatusUnprocessableEntity, err) | ||
} | ||
|
||
return c.JSON(http.StatusOK, stats) | ||
} |
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,58 @@ | ||
package http | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/cyberhorsey/webutils/testutils" | ||
"github.com/labstack/echo/v4" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/taikoxyz/taiko-mono/packages/eventindexer" | ||
) | ||
|
||
func Test_GetStats(t *testing.T) { | ||
srv := newTestServer("") | ||
|
||
var proofTime uint64 = 5 | ||
|
||
var proofReward uint64 = 7 | ||
|
||
_, err := srv.statRepo.Save(context.Background(), eventindexer.SaveStatOpts{ | ||
ProofTime: &proofTime, | ||
ProofReward: &proofReward, | ||
}) | ||
|
||
assert.Equal(t, nil, err) | ||
|
||
tests := []struct { | ||
name string | ||
address string | ||
wantStatus int | ||
wantBodyRegexpMatches []string | ||
}{ | ||
{ | ||
"success", | ||
"0x123", | ||
http.StatusOK, | ||
[]string{`{"id":1,"averageProofTime":5,"averageProofReward":7,"numProofs":1}`}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
req := testutils.NewUnauthenticatedRequest( | ||
echo.GET, | ||
"/stats", | ||
nil, | ||
) | ||
|
||
rec := httptest.NewRecorder() | ||
|
||
srv.ServeHTTP(rec, req) | ||
|
||
testutils.AssertStatusAndBody(t, rec, tt.wantStatus, tt.wantBodyRegexpMatches) | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.