Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add version to health endpoint. #756

Merged
merged 2 commits into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
294 changes: 147 additions & 147 deletions api/generated/common/routes.go

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions api/generated/common/types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

163 changes: 82 additions & 81 deletions api/generated/v2/routes.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions api/generated/v2/types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions api/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"github.com/algorand/indexer/version"
winder marked this conversation as resolved.
Show resolved Hide resolved
"net/http"
"strconv"

Expand Down Expand Up @@ -75,6 +76,7 @@ func (si *ServerImplementation) MakeHealthCheck(ctx echo.Context) error {
}

return ctx.JSON(http.StatusOK, common.HealthCheckResponse{
Version: version.LongVersion(),
Data: health.Data,
Round: health.Round,
IsMigrating: health.IsMigrating,
Expand Down
31 changes: 31 additions & 0 deletions api/handlers_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,34 @@ func TestPagingRootTxnDeduplication(t *testing.T) {
})
}
}

func TestVersion(t *testing.T) {
///////////
// Given // An API and context
///////////
db, shutdownFunc := setupIdb(t, test.MakeGenesis(), test.MakeGenesisBlock())
defer shutdownFunc()
api := &ServerImplementation{db: db}

e := echo.New()
req := httptest.NewRequest(http.MethodGet, "/", nil)
rec1 := httptest.NewRecorder()
c := e.NewContext(req, rec1)

//////////
// When // we call the health endpoint
//////////
err := api.MakeHealthCheck(c)

//////////
// Then // We get the health information.
//////////
require.NoError(t, err)
require.Equal(t, http.StatusOK, rec1.Code)
var response generated.HealthCheckResponse
json.Decode(rec1.Body.Bytes(), &response)

require.Equal(t, uint64(0), response.Round)
require.False(t, response.IsMigrating)
require.Contains(t, response.Version, "from git hash")
}
5 changes: 5 additions & 0 deletions api/indexer.oas2.json
Original file line number Diff line number Diff line change
Expand Up @@ -1394,12 +1394,17 @@
"description": "A health check response.",
"type": "object",
"required": [
"version",
"message",
"round",
"is-migrating",
"db-available"
],
"properties": {
"version": {
"description": "Current version.",
"type": "string"
},
"data": {
"type": "object"
},
Expand Down
7 changes: 6 additions & 1 deletion api/indexer.oas3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1239,13 +1239,18 @@
},
"round": {
"type": "integer"
},
"version": {
"description": "Current version.",
"type": "string"
}
},
"required": [
"db-available",
"is-migrating",
"message",
"round"
"round",
"version"
],
"type": "object"
},
Expand Down