Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Smalley <tyler.smalley@elastic.co>
  • Loading branch information
Tyler Smalley committed Sep 1, 2020
1 parent cd8dfd9 commit 45b86cd
Show file tree
Hide file tree
Showing 24 changed files with 143,684 additions and 97,737 deletions.
13 changes: 0 additions & 13 deletions packages/kbn-apm/package.json

This file was deleted.

6 changes: 0 additions & 6 deletions packages/kbn-apm/tsconfig.json

This file was deleted.

1 change: 0 additions & 1 deletion packages/kbn-apm/yarn.lock

This file was deleted.

2 changes: 1 addition & 1 deletion packages/kbn-optimizer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"dependencies": {
"@babel/cli": "^7.10.5",
"@kbn/apm": "1.0.0",
"@kbn/utils": "1.0.0",
"@kbn/babel-preset": "1.0.0",
"@kbn/dev-utils": "1.0.0",
"@kbn/ui-shared-deps": "1.0.0",
Expand Down
8 changes: 4 additions & 4 deletions packages/kbn-optimizer/src/apm_optimizer_stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { Agent } from '@kbn/apm';
import { apm } from '@kbn/utils';
import { tap } from 'rxjs/operators';

import { OptimizerConfig } from './optimizer';
Expand All @@ -37,10 +37,10 @@ export function apmOptimizerStats(config: OptimizerConfig) {
if (!loggedInit) {
loggedInit = true;

trans = Agent.startTransaction('@kbn/optimizer', 'cli');
trans = apm.Agent.startTransaction('@kbn/optimizer', 'cli');

const bundlesCount = state.onlineBundles.length + state.offlineBundles.length;
Agent.addLabels({
apm.Agent.addLabels({
optimizer_bundle_count: bundlesCount,
optimizer_bundle_cache_count: state.offlineBundles.length,
optimizer_bundle_cache_pct: Math.round(
Expand All @@ -61,7 +61,7 @@ export function apmOptimizerStats(config: OptimizerConfig) {
if (state.phase === 'issue') {
for (const b of state.compilerStates) {
if (b.type === 'compiler issue') {
Agent.captureError(b.failure, {
apm.Agent.captureError(b.failure, {
custom: {
optimizer_bundle_id: b.bundleId,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-optimizer/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import apm from '@kbn/apm';
import { apm } from '@kbn/utils';

apm.start({
metricsInterval: 1,
Expand Down
241,061 changes: 143,410 additions & 97,651 deletions packages/kbn-pm/dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/kbn-pm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"write-pkg": "^4.0.0"
},
"dependencies": {
"@kbn/apm": "1.0.0",
"@kbn/utils": "1.0.0",
"tslib": "^2.0.0"
}
}
2 changes: 1 addition & 1 deletion packages/kbn-pm/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import apm from '@kbn/apm';
import { apm } from '@kbn/utils';

apm.start({
metricsInterval: 1,
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-pm/src/commands/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import apm from '@kbn/apm';
import { apm } from '@kbn/utils';
import { linkProjectExecutables } from '../utils/link_project_executables';
import { log } from '../utils/log';
import { parallelizeBatches } from '../utils/parallelize';
Expand Down
5 changes: 4 additions & 1 deletion packages/kbn-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
"kbn:bootstrap": "yarn build",
"kbn:watch": "yarn build --watch"
},
"dependencies": {},
"dependencies": {
"@kbn/config-schema": "1.0.0",
"elastic-apm-node": "^3.7.0"
},
"devDependencies": {
"typescript": "3.9.5"
}
Expand Down
76 changes: 39 additions & 37 deletions packages/kbn-apm/index.js → packages/kbn-utils/src/apm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
* under the License.
*/

const os = require('os');
const { resolve } = require('path');
const { readFileSync } = require('fs');
const { execSync } = require('child_process');
import os from 'os';
import path from 'path';
import { readFileSync } from 'fs';
import { execSync } from 'child_process';

const Agent = require('elastic-apm-node');
const { REPO_ROOT, readKibanaPackageJSON } = require('@kbn/utils');
import Agent from 'elastic-apm-node';

const { version, build } = readKibanaPackageJSON();
import { getVersion } from '../read_kibana_package_json';
import { getDataPath } from '../path';

function gitRev() {
function gitRev(): string {
try {
return execSync('git rev-parse --short HEAD', {
encoding: 'utf-8',
Expand All @@ -36,56 +36,58 @@ function gitRev() {
.toString()
.trim();
} catch (e) {
return null;
return '';
}
}

const config = {
function isActive(): boolean {
if (process.env.kbnWorkerType === 'optmzr') {
return false;
}

return Boolean(process.env.ELASTIC_APM_ACTIVE || false);
}

function readUUID(): string {
try {
const filename = path.resolve(getDataPath(), 'uuid');
return readFileSync(filename, 'utf-8');
} catch (e) {
return '';
}
}

export const config = {
secretToken: 'VCRNqoV777Vs3mJ1VF',
serverUrl: 'https://b60e8f2199cf4713b3a11b3fce770101.apm.us-west1.gcp.cloud.es.io:443',
environment: process.env.ELASTIC_APM_ENVIRONMENT,
environment: process.env.ELASTIC_APM_ENVIRONMENT || 'development',
serviceName: 'kibana',
serviceVersion: version,
serviceVersion: getVersion(),
globalLabels: {
os_kernel: os.release(),
system_cpu_cores: os.cpus().length,
system_cpu_name: os.cpus()[0].model,
system_cpu_speed: os.cpus()[0].speed,
// kibana_uuid: readUUID(),
// git_rev: gitRev(),
},
centralConfig: false,
logUncaughtExceptions: true,
active: process.env.ELASTIC_APM_ACTIVE || 'false',
active: isActive(),
};

function active() {
return config.active;
}

try {
const filename = resolve(REPO_ROOT, 'data', 'uuid');
config.globalLabels.kibana_uuid = readFileSync(filename, 'utf-8');
} catch (e) {} // eslint-disable-line no-empty

const rev = gitRev();
if (rev !== null) config.globalLabels.git_rev = rev;

module.exports.config = config;

module.exports.isKibanaDistributable = Boolean(build && build.distributable === true);

module.exports.active = active;

module.exports.start = function start(options = {}) {
export function start(options = {}): typeof Agent | undefined {
if (process.env.kbnWorkerType === 'optmzr') return;

Agent.start({ ...config, ...options });
return Agent;
};
}

module.exports.flush = function flush() {
export function flush(): Promise<undefined> {
return new Promise((resolve) => {
active() ? Agent.flush(resolve) : resolve();
if (!isActive()) return resolve();
Agent.flush(resolve);
});
};
}

module.exports.Agent = Agent;
export { Agent };
3 changes: 2 additions & 1 deletion packages/kbn-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
* under the License.
*/

export * from './repo_root';
export * as apm from './apm';
export * from './read_kibana_package_json';
export * from './repo_root';
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,10 @@
* under the License.
*/

import Agent from 'elastic-apm-node';
import { readKibanaPackageJSON } from './read_kibana_package_json';

export const isKibanaDistributable: boolean;
const { build } = readKibanaPackageJSON();

export function start(options?: any): typeof Agent;

export function active(): boolean;

export function addSystemLabels(): undefined;

export function getConfig(options?: any): any;

export function flush(): Promise<undefined>;

export { Agent };
export function isKibanaDistributable(): boolean {
return Boolean(build && build.distributable === true);
}
31 changes: 31 additions & 0 deletions packages/kbn-utils/src/kibana_package_json.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import path from 'path';
import { kibanaPackageJSON } from './kibana_package_json';

it('parses package.json', () => {
expect(kibanaPackageJSON.name).toEqual('kibana');
});

it('includes __dirname and __filename', () => {
const root = path.resolve(__dirname, '../../../');
expect(kibanaPackageJSON.__filename).toEqual(path.resolve(root, 'package.json'));
expect(kibanaPackageJSON.__dirname).toEqual(root);
});
27 changes: 27 additions & 0 deletions packages/kbn-utils/src/kibana_package_json.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { dirname, resolve } from 'path';
import { REPO_ROOT } from './repo_root';

export const kibanaPackageJSON = {
__filename: resolve(REPO_ROOT, 'package.json'),
__dirname: dirname(resolve(REPO_ROOT, 'package.json')),
...require(resolve(REPO_ROOT, 'package.json')),
};
18 changes: 18 additions & 0 deletions packages/kbn-utils/src/kibana_paths.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
1 change: 1 addition & 0 deletions packages/kbn-utils/src/path/__fixtures__/kibana.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
path.data: '/tmp/data'
38 changes: 38 additions & 0 deletions packages/kbn-utils/src/path/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { accessSync, constants } from 'fs';
import { getConfigPath, getDataPath, getConfigDirectory } from './';

describe('Default path finder', () => {
it('should find a kibana.yml', () => {
const configPath = getConfigPath();
expect(() => accessSync(configPath, constants.R_OK)).not.toThrow();
});

it('should find a data directory', () => {
const dataPath = getDataPath();
expect(() => accessSync(dataPath, constants.R_OK)).not.toThrow();
});

it('should find a config directory', () => {
const configDirectory = getConfigDirectory();
expect(() => accessSync(configDirectory, constants.R_OK)).not.toThrow();
});
});
Loading

0 comments on commit 45b86cd

Please sign in to comment.