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

return git info in /extended/v1/status #724

Merged
merged 11 commits into from
Aug 27, 2021
9 changes: 9 additions & 0 deletions .github/workflows/stacks-blockchain-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Use Node.js
uses: actions/setup-node@v2
Expand Down Expand Up @@ -144,6 +146,7 @@ jobs:
- name: Setup integration environment
run: |
sudo ufw disable
npm run git-info
npm run devenv:deploy -- -d
npm run devenv:logs -- --no-color &> docker-compose-logs.txt &

Expand All @@ -166,6 +169,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Use Node.js
uses: actions/setup-node@v2
Expand Down Expand Up @@ -196,6 +201,7 @@ jobs:
- name: Setup integration environment
run: |
sudo ufw disable
npm run git-info
npm run devenv:deploy -- -d
npm run devenv:logs -- --no-color &> docker-compose-logs.txt &

Expand All @@ -218,6 +224,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Use Node.js
uses: actions/setup-node@v2
Expand Down Expand Up @@ -248,6 +256,7 @@ jobs:
- name: Setup integration environment
run: |
sudo ufw disable
npm run git-info
npm run devenv:deploy -- -d
npm run devenv:logs -- --no-color &> docker-compose-logs.txt &

Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,6 @@ openapitools.json

.env.local
yarn.lock

# Git info output
src/git-info.ts
4 changes: 4 additions & 0 deletions docs/api/info/get-status.example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"server_version": "stacks-blockchain-api v0.64.1 (master:439d4f46)",
"status": "ready"
}
21 changes: 21 additions & 0 deletions docs/api/info/get-status.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"description": "GET blockchain API status",
"title": "ServerStatusResponse",
"type": "object",
"additionalProperties": false,
"required": [
"server_version",
"status"
],
"properties": {
"server_version": {
"type": "string",
"description": "the server version that is currently running"
},
"status": {
"type": "string",
"description": "the current server status"
}
}
}
14 changes: 14 additions & 0 deletions docs/generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export type SchemaMergeRootStub =
| RunFaucetResponse
| NetworkBlockTimeResponse
| NetworkBlockTimesResponse
| ServerStatusResponse
| GetStxCirculatingSupplyPlainResponse
| GetStxSupplyLegacyFormatResponse
| GetStxTotalSupplyPlainResponse
Expand Down Expand Up @@ -1531,6 +1532,19 @@ export interface NetworkBlockTimesResponse {
target_block_time: number;
};
}
/**
* GET blockchain API status
*/
export interface ServerStatusResponse {
/**
* the server version that is currently running
*/
server_version: string;
/**
* the current server status
*/
status: string;
}
/**
* GET request that returns network target block times
*/
Expand Down
7 changes: 4 additions & 3 deletions docs/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1399,9 +1399,10 @@ paths:
description: Success
content:
application/json:
examples:
success:
value: { status: 'ready' }
schema:
$ref: ./api/info/get-status.schema.json
example:
$ref: ./api/info/get-status.example.json

/extended/v1/info/network_block_times:
get:
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"test:integration:rosetta": "npm run devenv:deploy -- -d && cross-env NODE_ENV=development jest --config ./jest.config.rosetta.js --coverage --no-cache --runInBand; npm run devenv:stop",
"test:integration:bns": "npm run devenv:deploy -- -d && cross-env NODE_ENV=development jest --config ./jest.config.bns.js --coverage --no-cache --runInBand; npm run devenv:stop",
"test:integration:microblocks": "npm run devenv:deploy:pg -- -d && cross-env NODE_ENV=development jest --config ./jest.config.microblocks.js --coverage --no-cache --runInBand; npm run devenv:stop:pg",
"build": "rimraf ./lib && tsc -p tsconfig.build.json",
"git-info": "echo export default \"{\\\"branch\\\":\\\"$(git rev-parse --abbrev-ref HEAD)\\\",\\\"commit\\\":\\\"$(git log -1 --pretty=format:%h)\\\",\\\"tag\\\":\\\"$(git describe --tags --abbrev=0)\\\"}\" > ./src/git-info.ts",
rafaelcr marked this conversation as resolved.
Show resolved Hide resolved
"build": "npm run git-info && rimraf ./lib && tsc -p tsconfig.build.json",
"build:tests": "tsc -p tsconfig.json",
"build:docs": "npm i --prefix client && npm run generate:docs --prefix client && npm i --prefix docs && npm run generate:docs --prefix docs",
"start": "node ./lib/index.js",
Expand Down
3 changes: 2 additions & 1 deletion src/api/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import * as pathToRegex from 'path-to-regexp';
import * as expressListEndpoints from 'express-list-endpoints';
import { createMiddleware as createPrometheusMiddleware } from '@promster/express';
import { createMicroblockRouter } from './routes/microblock';
import { createStatusRouter } from './routes/status';

export interface ApiServer {
expressApp: ExpressWithAsync;
Expand Down Expand Up @@ -149,7 +150,7 @@ export async function startApiServer(opts: {
router.use('/info', createInfoRouter(datastore));
router.use('/stx_supply', createStxSupplyRouter(datastore));
router.use('/debug', createDebugRouter(datastore));
router.use('/status', (req, res) => res.status(200).json({ status: 'ready' }));
router.use('/status', createStatusRouter(datastore));
router.use('/faucets', createFaucetRouter(datastore));
return router;
})()
Expand Down
19 changes: 19 additions & 0 deletions src/api/routes/status.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as express from 'express';
import { addAsync, RouterWithAsync } from '@awaitjs/express';
import { DataStore } from 'src/datastore/common';
import GitInfo from '../../git-info';
import { ServerStatusResponse } from 'docs/generated';

export function createStatusRouter(db: DataStore): RouterWithAsync {
const router = addAsync(express.Router());

router.get('/', (req, res) => {
const response: ServerStatusResponse = {
server_version: `stacks-blockchain-api ${GitInfo.tag} (${GitInfo.branch}:${GitInfo.commit})`,
status: 'ready',
};
res.json(response);
});

return router;
}