Skip to content

Commit

Permalink
Add build_date to kbn:api/status (#157905)
Browse files Browse the repository at this point in the history
## Summary

Adds build date to `GET kbn:api/status` similar to ES. Example output
running locally:

```json
{
  "name": "ES-DMVD5M3",
  "uuid": "545ba70c-063e-449b-af21-6c8e7b30f77e",
  "version": {
    "number": "8.9.0",
    "build_hash": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    "build_number": 9007199254740991,
    "build_snapshot": false,
    "build_date": "2023-05-15T23:12:09.000Z"
  },
  ...rest
}
```


### Checklist

- [x]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios


## Release Note

The status endpoint now returns the build date alongside other build
information.

---------

Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
Ikuni17 and kibanamachine authored May 25, 2023
1 parent 97a93b3 commit 0c3ca36
Show file tree
Hide file tree
Showing 33 changed files with 96 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ Some features require special configuration when running in different modes (dev
|`12345`
|The build SHA (typically refers to the last commit's SHA)

|`buildDate`
|`2023-05-15T23:12:09+0000`
|The ISO 8601 date of the build

|===

To use any of the references listed above in a config validation schema, they can be accessed via `schema.contextRef('{CONTEXT_REFERENCE}')`:
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"tsdocMetadata": "./build/tsdoc-metadata.json",
"build": {
"number": 8467,
"sha": "6cb7fec4e154faa0a4a3fee4b33dfef91b9870d9"
"sha": "6cb7fec4e154faa0a4a3fee4b33dfef91b9870d9",
"date": "2023-05-15T23:12:09+0000"
},
"homepage": "https://www.elastic.co/products/kibana",
"bugs": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const buildServerVersion = (parts: Partial<ServerVersion> = {}): ServerVersion =
build_hash: 'build_hash',
build_number: 9000,
build_snapshot: false,
build_date: '2023-05-15T23:12:09.000Z',
...parts,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const mockedResponse: StatusResponse = {
build_hash: '9007199254740991',
build_number: 12,
build_snapshot: false,
build_date: '2023-05-15T23:12:09.000Z',
},
status: {
overall: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const createPackageInfo = (parts: Partial<PackageInfo> = {}): PackageInfo => ({
dist: true,
branch: 'master',
version: '8.0.0',
buildDate: new Date('2023-05-15T23:12:09.000Z'),
});

const createUiPlugins = (...ids: string[]): UiPlugins => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function createCoreContext({ production = false }: { production?: boolean } = {}
buildNum: 100,
buildSha: 'buildSha',
dist: false,
buildDate: new Date('2023-05-15T23:12:09.000Z'),
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@
* Side Public License, v 1.
*/

import { REPO_ROOT } from '@kbn/repo-info';
import type { DeeplyMockedKeys } from '@kbn/utility-types-jest';
import { Env, IConfigService } from '@kbn/config';
import type { LoggerFactory } from '@kbn/logging';
import { loggerMock } from '@kbn/logging-mocks';
import { configServiceMock, getEnvOptions } from '@kbn/config-mocks';
import { configServiceMock, createTestEnv } from '@kbn/config-mocks';
import type { CoreContext } from '@kbn/core-base-server-internal';

function create({
env = Env.createDefault(REPO_ROOT, getEnvOptions()),
env = createTestEnv(),
logger = loggerMock.create(),
configService = configServiceMock.create(),
}: {
Expand Down
1 change: 0 additions & 1 deletion packages/core/base/core-base-server-mocks/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"@kbn/logging",
"@kbn/logging-mocks",
"@kbn/core-base-server-internal",
"@kbn/repo-info",
],
"exclude": [
"target/**/*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const createPluginInitializerContextMock = (config: unknown = {}) => {
buildNum: 100,
buildSha: 'buildSha',
dist: false,
buildDate: new Date('2023-05-15T23:12:09.000Z'),
},
},
logger: loggerMock.create(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const createPluginInitializerContextMock = (config: unknown = {}) => {
buildNum: 100,
buildSha: 'buildSha',
dist: false,
buildDate: new Date('2023-05-15T23:12:09.000Z'),
},
},
logger: loggerMock.create(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const packageInfo = {
buildSha: '',
version: '7.0.0-alpha1',
dist: false,
buildDate: new Date('2023-05-15T23:12:09.000Z'),
};

afterEach(() => {
Expand Down

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

Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const createPackageInfo = (parts: Partial<PackageInfo> = {}): PackageInfo => ({
branch: 'master',
buildNum: 42,
buildSha: 'buildSha',
buildDate: new Date('2023-05-15T23:12:09.000Z'),
dist: false,
version: '8.0.0',
...parts,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { InternalRenderingServicePreboot, InternalRenderingServiceSetup } from '
import { RenderingService } from './rendering_service';
import { AuthStatus } from '@kbn/core-http-server';

const BUILD_DATE = '2023-05-15T23:12:09+0000';
const INJECTED_METADATA = {
version: expect.any(String),
branch: expect.any(String),
Expand All @@ -43,6 +44,7 @@ const INJECTED_METADATA = {
buildSha: expect.any(String),
dist: expect.any(Boolean),
version: expect.any(String),
buildDate: new Date(BUILD_DATE).toISOString(),
},
},
};
Expand Down Expand Up @@ -387,6 +389,15 @@ function renderDarkModeTestCases(
describe('RenderingService', () => {
let service: RenderingService;

beforeAll(() => {
jest.useFakeTimers();
jest.setSystemTime(new Date(BUILD_DATE));
});

afterAll(() => {
jest.useRealTimers();
});

beforeEach(() => {
jest.clearAllMocks();
service = new RenderingService(mockRenderingServiceParams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface ServerVersion {
build_hash: string;
build_number: number;
build_snapshot: boolean;
build_date: string;
}

export interface StatusInfo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export const registerStatusRoute = ({
},
},
async (context, req, res) => {
const { version, buildSha, buildNum } = config.packageInfo;
const { version, buildSha, buildNum, buildDate } = config.packageInfo;
const versionWithoutSnapshot = version.replace(SNAPSHOT_POSTFIX, '');
const [overall, coreOverall, core, plugins] = await firstValueFrom(combinedStatus$);

Expand Down Expand Up @@ -121,6 +121,7 @@ export const registerStatusRoute = ({
build_hash: buildSha,
build_number: buildNum,
build_snapshot: SNAPSHOT_POSTFIX.test(version),
build_date: buildDate.toISOString(),
},
status: statusInfo,
metrics: {
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-config-mocks/src/env.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const createTestPackageInfo = ({ dist = true }: { dist?: boolean } = {}):
distributable: dist,
number: 123456789,
sha: 'XXXXXX',
date: '2023-05-15T23:12:09+0000',
},
};
};
Expand Down
6 changes: 6 additions & 0 deletions packages/kbn-config/src/__snapshots__/env.test.ts.snap

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

2 changes: 2 additions & 0 deletions packages/kbn-config/src/config_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const packageInfos: RawPackageInfo = {
build: {
number: 42,
sha: 'one',
date: '2023-05-15T23:12:09+0000',
},
};
const emptyArgv = getEnvOptions();
Expand Down Expand Up @@ -238,6 +239,7 @@ test('correctly passes context', async () => {
distributable: true,
number: 100,
sha: 'feature-v1-build-sha',
date: '2023-05-15T23:12:09+0000',
},
};

Expand Down
Loading

0 comments on commit 0c3ca36

Please sign in to comment.