|
17 | 17 | * under the License.
|
18 | 18 | */
|
19 | 19 |
|
20 |
| -const { existsSync } = require('fs'); |
21 | 20 | const { join } = require('path');
|
22 |
| -const { name, version } = require('../package.json'); |
| 21 | +const { readFileSync } = require('fs'); |
| 22 | +const { execSync } = require('child_process'); |
| 23 | +const merge = require('lodash.merge'); |
| 24 | +const { name, version, build } = require('../package.json'); |
23 | 25 |
|
24 |
| -module.exports = function(serviceName = name) { |
25 |
| - if (process.env.kbnWorkerType === 'optmzr') return; |
| 26 | +const ROOT_DIR = join(__dirname, '..'); |
| 27 | + |
| 28 | +function gitRev() { |
| 29 | + try { |
| 30 | + return execSync('git rev-parse --short HEAD', { |
| 31 | + encoding: 'utf-8', |
| 32 | + stdio: ['ignore', 'pipe', 'ignore'], |
| 33 | + }).trim(); |
| 34 | + } catch (e) { |
| 35 | + return null; |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +function devConfig() { |
| 40 | + try { |
| 41 | + const apmDevConfigPath = join(ROOT_DIR, 'config', 'apm.dev.js'); |
| 42 | + return require(apmDevConfigPath); // eslint-disable-line import/no-dynamic-require |
| 43 | + } catch (e) { |
| 44 | + return {}; |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +const apmConfig = merge( |
| 49 | + { |
| 50 | + active: false, |
| 51 | + serverUrl: 'https://f1542b814f674090afd914960583265f.apm.us-central1.gcp.cloud.es.io:443', |
| 52 | + // The secretToken below is intended to be hardcoded in this file even though |
| 53 | + // it makes it public. This is not a security/privacy issue. Normally we'd |
| 54 | + // instead disable the need for a secretToken in the APM Server config where |
| 55 | + // the data is transmitted to, but due to how it's being hosted, it's easier, |
| 56 | + // for now, to simply leave it in. |
| 57 | + secretToken: 'R0Gjg46pE9K9wGestd', |
| 58 | + globalLabels: {}, |
| 59 | + breakdownMetrics: true, |
| 60 | + centralConfig: false, |
| 61 | + logUncaughtExceptions: true, |
| 62 | + }, |
| 63 | + devConfig() |
| 64 | +); |
| 65 | + |
| 66 | +try { |
| 67 | + const filename = join(ROOT_DIR, 'data', 'uuid'); |
| 68 | + apmConfig.globalLabels.kibana_uuid = readFileSync(filename, 'utf-8'); |
| 69 | +} catch (e) {} // eslint-disable-line no-empty |
26 | 70 |
|
27 |
| - const conf = { |
28 |
| - serviceName: `${serviceName}-${version.replace(/\./g, '_')}`, |
| 71 | +const rev = gitRev(); |
| 72 | +if (rev !== null) apmConfig.globalLabels.git_rev = rev; |
| 73 | + |
| 74 | +function getConfig(serviceName) { |
| 75 | + return { |
| 76 | + ...apmConfig, |
| 77 | + ...{ |
| 78 | + serviceName: `${serviceName}-${version.replace(/\./g, '_')}`, |
| 79 | + }, |
29 | 80 | };
|
| 81 | +} |
| 82 | + |
| 83 | +/** |
| 84 | + * Flag to disable APM RUM support on all kibana builds by default |
| 85 | + */ |
| 86 | +const isKibanaDistributable = Boolean(build && build.distributable === true); |
30 | 87 |
|
31 |
| - const configFile = join(__dirname, '..', 'config', 'apm.js'); |
| 88 | +module.exports = function(serviceName = name) { |
| 89 | + if (process.env.kbnWorkerType === 'optmzr') return; |
32 | 90 |
|
33 |
| - if (existsSync(configFile)) conf.configFile = configFile; |
34 |
| - else conf.active = false; |
| 91 | + const conf = getConfig(serviceName); |
35 | 92 |
|
36 | 93 | require('elastic-apm-node').start(conf);
|
37 | 94 | };
|
| 95 | + |
| 96 | +module.exports.getConfig = getConfig; |
| 97 | +module.exports.isKibanaDistributable = isKibanaDistributable; |
0 commit comments