Skip to content

Commit

Permalink
(DAL) Simplify api endpoint (#1865)
Browse files Browse the repository at this point in the history
* feat: simplify api endpoint

* feat: updates sentinel healthcheck endpoints

* test: update test endpoints
  • Loading branch information
nick-bisonai authored Jul 22, 2024
1 parent 75700a8 commit 98e63ea
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion node/pkg/dal/api/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

func Routes(router fiber.Router) {
api := router.Group("/dal")
api := router.Group("")

api.Get("/symbols", getSymbols)
api.Get("/latest-data-feeds/all", getAllLatestFeeds)
Expand Down
2 changes: 1 addition & 1 deletion node/pkg/dal/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func Run(ctx context.Context) error {
_ = app.Shutdown()
}()

v1 := app.Group("/api/v1")
v1 := app.Group("")
v1.Get("/", func(c *fiber.Ctx) error {
return c.SendString("Orakl Node DAL API")
})
Expand Down
10 changes: 5 additions & 5 deletions node/pkg/dal/tests/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestApiGetLatestAll(t *testing.T) {
}

time.Sleep(10 * time.Millisecond)
result, err := request.Request[[]common.OutgoingSubmissionData](request.WithEndpoint("http://localhost:8090/api/v1/dal/latest-data-feeds/all"), request.WithHeaders(map[string]string{"X-API-Key": testItems.ApiKey}))
result, err := request.Request[[]common.OutgoingSubmissionData](request.WithEndpoint("http://localhost:8090/latest-data-feeds/all"), request.WithHeaders(map[string]string{"X-API-Key": testItems.ApiKey}))
if err != nil {
t.Fatalf("error getting latest data: %v", err)
}
Expand Down Expand Up @@ -89,14 +89,14 @@ func TestShouldFailWithoutApiKey(t *testing.T) {
}()

go testItems.App.Listen(":8090")
resp, err := request.RequestRaw(request.WithEndpoint("http://localhost:8090/api/v1"))
resp, err := request.RequestRaw(request.WithEndpoint("http://localhost:8090/"))
if err != nil {
t.Fatalf("error getting latest data: %v", err)
}

assert.Equal(t, 200, resp.StatusCode)

result, err := request.RequestRaw(request.WithEndpoint("http://localhost:8090/api/v1/dal/latest-data-feeds/test-aggregate"))
result, err := request.RequestRaw(request.WithEndpoint("http://localhost:8090/latest-data-feeds/test-aggregate"))

if err != nil {
t.Fatalf("error getting latest data: %v", err)
Expand Down Expand Up @@ -136,7 +136,7 @@ func TestApiGetLatest(t *testing.T) {

time.Sleep(10 * time.Millisecond)

result, err := request.Request[[]common.OutgoingSubmissionData](request.WithEndpoint("http://localhost:8090/api/v1/dal/latest-data-feeds/test-aggregate"), request.WithHeaders(map[string]string{"X-API-Key": testItems.ApiKey}))
result, err := request.Request[[]common.OutgoingSubmissionData](request.WithEndpoint("http://localhost:8090/latest-data-feeds/test-aggregate"), request.WithHeaders(map[string]string{"X-API-Key": testItems.ApiKey}))
if err != nil {
t.Fatalf("error getting latest data: %v", err)
}
Expand All @@ -163,7 +163,7 @@ func TestApiWebsocket(t *testing.T) {

go testItems.App.Listen(":8090")

conn, err := wss.NewWebsocketHelper(ctx, wss.WithEndpoint("ws://localhost:8090/api/v1/dal/ws"), wss.WithRequestHeaders(headers))
conn, err := wss.NewWebsocketHelper(ctx, wss.WithEndpoint("ws://localhost:8090/ws"), wss.WithRequestHeaders(headers))
if err != nil {
t.Fatalf("error creating websocket helper: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion node/pkg/dal/tests/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestCollectorStream(t *testing.T) {
assert.True(t, collector.IsRunning)

headers := map[string]string{"X-API-Key": testItems.ApiKey}
conn, err := wss.NewWebsocketHelper(ctx, wss.WithEndpoint("ws://localhost:8090/api/v1/dal/ws"), wss.WithRequestHeaders(headers))
conn, err := wss.NewWebsocketHelper(ctx, wss.WithEndpoint("ws://localhost:8090/ws"), wss.WithRequestHeaders(headers))
if err != nil {
t.Fatalf("error creating websocket helper: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion node/pkg/dal/tests/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func setup(ctx context.Context) (func() error, *TestItems, error) {
testItems.Controller = apiController
testItems.MockAdmin = mockAdminServer

v1 := app.Group("/api/v1")
v1 := app.Group("")
v1.Get("/", func(c *fiber.Ctx) error {
return c.SendString("Orakl Node DAL API")
})
Expand Down
2 changes: 1 addition & 1 deletion node/pkg/dal/utils/initializer/initializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func CustomStackTraceHandler(_ *fiber.Ctx, e interface{}) {

func authFilter(c *fiber.Ctx) bool {
originalURL := strings.ToLower(c.OriginalURL())
return originalURL == "/api/v1"
return originalURL == "/"
}

func validator(c *fiber.Ctx, s string) (bool, error) {
Expand Down
2 changes: 1 addition & 1 deletion node/pkg/dal/utils/stats/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func StatsMiddleware(c *fiber.Ctx) error {
}
duration := time.Since(start)

if c.Path() == "/api/v1" {
if c.Path() == "/" {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion sentinel/pkg/checker/health/baobab_healthcheck.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
{
"name": "orakl-dal",
"url": "http://orakl-dal.orakl.svc.cluster.local:80/api/v1"
"url": "http://orakl-dal.orakl.svc.cluster.local:80/"
},
{
"name": "orakl-delegator",
Expand Down
4 changes: 4 additions & 0 deletions sentinel/pkg/checker/health/cypress_healthcheck.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
"name": "orakl-boot-api",
"url": "http://orakl-boot-api.orakl.svc.cluster.local:5050/api/v1/"
},
{
"name": "orakl-dal",
"url": "http://orakl-dal.orakl.svc.cluster.local:80/"
},
{
"name": "orakl-delegator",
"url": "http://orakl-delegator.orakl.svc.cluster.local:80/api/v1/"
Expand Down

0 comments on commit 98e63ea

Please sign in to comment.