-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Tyler Smalley <[email protected]>
- Loading branch information
Tyler Smalley
committed
Sep 1, 2020
1 parent
9a27beb
commit cd8dfd9
Showing
32 changed files
with
53,096 additions
and
19,949 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* 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 Agent from 'elastic-apm-node'; | ||
|
||
export const isKibanaDistributable: boolean; | ||
|
||
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
const os = require('os'); | ||
const { resolve } = require('path'); | ||
const { readFileSync } = require('fs'); | ||
const { execSync } = require('child_process'); | ||
|
||
const Agent = require('elastic-apm-node'); | ||
const { REPO_ROOT, readKibanaPackageJSON } = require('@kbn/utils'); | ||
|
||
const { version, build } = readKibanaPackageJSON(); | ||
|
||
function gitRev() { | ||
try { | ||
return execSync('git rev-parse --short HEAD', { | ||
encoding: 'utf-8', | ||
stdio: ['ignore', 'pipe', 'ignore'], | ||
}) | ||
.toString() | ||
.trim(); | ||
} catch (e) { | ||
return null; | ||
} | ||
} | ||
|
||
const config = { | ||
secretToken: 'VCRNqoV777Vs3mJ1VF', | ||
serverUrl: 'https://b60e8f2199cf4713b3a11b3fce770101.apm.us-west1.gcp.cloud.es.io:443', | ||
environment: process.env.ELASTIC_APM_ENVIRONMENT, | ||
serviceName: 'kibana', | ||
serviceVersion: version, | ||
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, | ||
}, | ||
centralConfig: false, | ||
logUncaughtExceptions: true, | ||
active: process.env.ELASTIC_APM_ACTIVE || 'false', | ||
}; | ||
|
||
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 = {}) { | ||
if (process.env.kbnWorkerType === 'optmzr') return; | ||
|
||
Agent.start({ ...config, ...options }); | ||
return Agent; | ||
}; | ||
|
||
module.exports.flush = function flush() { | ||
return new Promise((resolve) => { | ||
active() ? Agent.flush(resolve) : resolve(); | ||
}); | ||
}; | ||
|
||
module.exports.Agent = Agent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "@kbn/apm", | ||
"private": true, | ||
"version": "1.0.0", | ||
"description": "Kibana APM profiling", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"license": "Apache-2.0", | ||
"dependencies": { | ||
"@kbn/utils": "1.0.0", | ||
"elastic-apm-node": "^3.7.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"include": [ | ||
"index.d.ts" | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* 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 { Agent } from '@kbn/apm'; | ||
import { tap } from 'rxjs/operators'; | ||
|
||
import { OptimizerConfig } from './optimizer'; | ||
import { OptimizerUpdate$ } from './run_optimizer'; | ||
import { pipeClosure } from './common'; | ||
|
||
export function apmOptimizerStats(config: OptimizerConfig) { | ||
return pipeClosure((update$: OptimizerUpdate$) => { | ||
let loggedInit = false; | ||
let trans: any; | ||
|
||
return update$.pipe( | ||
tap(async (update) => { | ||
const { state } = update; | ||
|
||
if (state.phase === 'initialized') { | ||
if (!loggedInit) { | ||
loggedInit = true; | ||
|
||
trans = Agent.startTransaction('@kbn/optimizer', 'cli'); | ||
|
||
const bundlesCount = state.onlineBundles.length + state.offlineBundles.length; | ||
Agent.addLabels({ | ||
optimizer_bundle_count: bundlesCount, | ||
optimizer_bundle_cache_count: state.offlineBundles.length, | ||
optimizer_bundle_cache_pct: Math.round( | ||
(state.offlineBundles.length / bundlesCount) * 100 | ||
), | ||
optimizer_watch: config.watch, | ||
optimizer_production: config.dist, | ||
optimizer_profile_webpack: config.profileWebpack, | ||
optimizer_bundle_theme_tags_count: config.themeTags.length, | ||
optimizer_cache: config.cache, | ||
optimizer_max_worker_count: config.maxWorkerCount, | ||
}); | ||
} | ||
|
||
return; | ||
} | ||
|
||
if (state.phase === 'issue') { | ||
for (const b of state.compilerStates) { | ||
if (b.type === 'compiler issue') { | ||
Agent.captureError(b.failure, { | ||
custom: { | ||
optimizer_bundle_id: b.bundleId, | ||
}, | ||
}); | ||
} | ||
} | ||
return; | ||
} | ||
|
||
if (state.phase === 'success') { | ||
if (trans) { | ||
trans.end(); | ||
} | ||
|
||
return; | ||
} | ||
}) | ||
); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.