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

Review: [Stack Monitoring] Add OpenTelemetry metrics to Monitoring Collection plugin #1

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
"@emotion/css": "^11.9.0",
"@emotion/react": "^11.9.0",
"@emotion/serialize": "^1.0.3",
"@grpc/grpc-js": "^1.5.9",
"@grpc/grpc-js": "^1.6.7",
"@hapi/accept": "^5.0.2",
"@hapi/boom": "^9.1.4",
"@hapi/cookie": "^11.0.2",
Expand Down Expand Up @@ -275,12 +275,12 @@
"@mapbox/mapbox-gl-draw": "1.3.0",
"@mapbox/mapbox-gl-rtl-text": "0.2.3",
"@mapbox/vector-tile": "1.3.1",
"@opentelemetry/api-metrics": "0.30.0",
"@opentelemetry/api-metrics": "^0.30.0",
"@opentelemetry/exporter-metrics-otlp-grpc": "^0.30.0",
"@opentelemetry/exporter-prometheus": "^0.30.0",
"@opentelemetry/resources": "^1.3.1",
"@opentelemetry/resources": "^1.4.0",
"@opentelemetry/sdk-metrics-base": "^0.30.0",
"@opentelemetry/semantic-conventions": "^1.3.1",
"@opentelemetry/semantic-conventions": "^1.4.0",
"@reduxjs/toolkit": "^1.6.1",
"@slack/webhook": "^5.0.4",
"@turf/along": "6.0.1",
Expand Down
22 changes: 21 additions & 1 deletion x-pack/plugins/monitoring_collection/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ This plugin allows for other plugins to add data to Kibana stack monitoring docu
prometheus.enabled: true
```

### Enable OpenTelemetry Metrics API exported as OpenTelemetry Protocol
### Enable OpenTelemetry Metrics API exported as OpenTelemetry Protocol over GRPC

1. Start [local setup with fleet](../fleet/README.md#running-fleet-server-locally-in-a-container) or a cloud cluster
2. Start Kibana
Expand All @@ -38,6 +38,26 @@ This plugin allows for other plugins to add data to Kibana stack monitoring docu
otlp.url: "http://127.0.0.1:8200"
```

You can also provide headers for OTLP endpoints that require authentication:

```yml
# Enable the OTLP exporter to an authenticated APM endpoint
monitoring_collection.opentelemetry.metrics:
otlp:
url: "https://DEPLOYMENT.apm.REGION.PROVIDER.elastic-cloud.com"
headers:
Authorization: "Bearer SECRET_TOKEN"
```

For connection-level debug information you can set these variables:

```bash
export GRPC_NODE_TRACE="xds_client,xds_resolver,cds_balancer,eds_balancer,priority,weighted_target,round_robin,resolving_load_balancer,subchannel,keepalive,dns_resolver,fault_injection,http_filter,csds"
export GRPC_NODE_VERBOSITY=DEBUG
```

See the [grpc-node docs](https://github.com/grpc/grpc-node/blob/master/doc/environment_variables.md) for details and other settings.

### Example of how to instrument the code

* First, we need to define what metrics we want to instrument with OpenTelemetry
Expand Down
10 changes: 3 additions & 7 deletions x-pack/plugins/monitoring_collection/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,8 @@ export class MonitoringCollectionPlugin implements Plugin<MonitoringCollectionSe

const otlpConfig = this.config.opentelemetry?.metrics.otlp;
if (otlpConfig?.url) {
// Add OTLP exporter
const url = otlpConfig.url;
this.logger.debug(`Registering OpenTelemetry metrics exporter to ${url}`);

const credentials = url.startsWith('https://')
? grpc.credentials.createSsl()
: grpc.credentials.createInsecure();

// Set Authorization headers
const metadata = new grpc.Metadata();
Expand All @@ -143,10 +139,10 @@ export class MonitoringCollectionPlugin implements Plugin<MonitoringCollectionSe
}
}

// Add OTLP exporter
this.logger.debug(`Registering OpenTelemetry metrics exporter to ${url}`);
meterProvider.addMetricReader(
new PeriodicExportingMetricReader({
exporter: new OTLPMetricExporter({ url, credentials, metadata }),
exporter: new OTLPMetricExporter({ url, metadata }),
exportIntervalMillis: otlpConfig.exportIntervalMillis,
})
);
Expand Down
53 changes: 11 additions & 42 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1997,26 +1997,15 @@
resolved "https://registry.yarnpkg.com/@gar/promisify/-/promisify-1.1.3.tgz#555193ab2e3bb3b6adc3d551c9c030d9e860daf6"
integrity sha512-k2Ty1JcVojjJFwrg/ThKi2ujJ7XNLYaFGNB/bWT9wGR+oSMJHMa5w+CUq6p/pVrKeNNgA7pCqEcjSnHVoqJQFw==

"@grpc/grpc-js@^1.5.9":
"@grpc/grpc-js@^1.5.9", "@grpc/grpc-js@^1.6.7":
version "1.6.7"
resolved "https://registry.yarnpkg.com/@grpc/grpc-js/-/grpc-js-1.6.7.tgz#4c4fa998ff719fe859ac19fe977fdef097bb99aa"
integrity sha512-eBM03pu9hd3VqDQG+kHahiG1x80RGkkqqRb1Pchcwqej/KkAH95gAvKs6laqaHCycYaPK+TKuNQnOz9UXYA8qw==
dependencies:
"@grpc/proto-loader" "^0.6.4"
"@types/node" ">=12.12.47"

"@grpc/proto-loader@^0.6.4":
version "0.6.12"
resolved "https://registry.yarnpkg.com/@grpc/proto-loader/-/proto-loader-0.6.12.tgz#459b619b8b9b67794bf0d1cb819653a38c63e164"
integrity sha512-filTVbETFnxb9CyRX98zN18ilChTuf/C5scZ2xyaOTp0EHGq0/ufX8rjqXUcSb1Gpv7eZq4M2jDvbh9BogKnrg==
dependencies:
"@types/long" "^4.0.1"
lodash.camelcase "^4.3.0"
long "^4.0.0"
protobufjs "^6.10.0"
yargs "^16.2.0"

"@grpc/proto-loader@^0.6.9":
"@grpc/proto-loader@^0.6.4", "@grpc/proto-loader@^0.6.9":
version "0.6.13"
resolved "https://registry.yarnpkg.com/@grpc/proto-loader/-/proto-loader-0.6.13.tgz#008f989b72a40c60c96cd4088522f09b05ac66bc"
integrity sha512-FjxPYDRTn6Ec3V0arm1FtSpmP6V50wuph2yILpyvTKzjc76oDdoihXqM1DzOW5ubvCC8GivfCnNtfaRE8myJ7g==
Expand Down Expand Up @@ -4421,7 +4410,7 @@
"@mattiasbuelens/web-streams-adapter" "~0.1.0"
web-streams-polyfill "~3.0.3"

"@opentelemetry/[email protected]":
"@opentelemetry/[email protected]", "@opentelemetry/api-metrics@^0.30.0":
version "0.30.0"
resolved "https://registry.yarnpkg.com/@opentelemetry/api-metrics/-/api-metrics-0.30.0.tgz#b5defd10756e81d1c7ce8669ff8a8d2465ba0be8"
integrity sha512-jSb7iiYPY+DSUKIyzfGt0a5K1QGzWY5fSWtUB8Alfi27NhQGHBeuYYC5n9MaBP/HNWw5GpEIhXGEYCF9Pf8IEg==
Expand All @@ -4433,13 +4422,6 @@
resolved "https://registry.yarnpkg.com/@opentelemetry/api/-/api-1.1.0.tgz#563539048255bbe1a5f4f586a4a10a1bb737f44a"
integrity sha512-hf+3bwuBwtXsugA2ULBc95qxrOqP2pOekLz34BJhcAKawt94vfeNyUKpYc0lZQ/3sCP6LqRa7UAdHA7i5UODzQ==

"@opentelemetry/[email protected]":
version "1.3.1"
resolved "https://registry.yarnpkg.com/@opentelemetry/core/-/core-1.3.1.tgz#6eef5c5efca9a4cd7daa0cd4c7ff28ca2317c8d7"
integrity sha512-k7lOC86N7WIyUZsUuSKZfFIrUtINtlauMGQsC1r7jNmcr0vVJGqK1ROBvt7WWMxLbpMnt1q2pXJO8tKu0b9auA==
dependencies:
"@opentelemetry/semantic-conventions" "1.3.1"

"@opentelemetry/[email protected]":
version "1.4.0"
resolved "https://registry.yarnpkg.com/@opentelemetry/core/-/core-1.4.0.tgz#26839ab9e36583a174273a1e1c5b33336c163725"
Expand Down Expand Up @@ -4510,22 +4492,14 @@
"@opentelemetry/sdk-metrics-base" "0.30.0"
"@opentelemetry/sdk-trace-base" "1.4.0"

"@opentelemetry/[email protected]":
"@opentelemetry/[email protected]", "@opentelemetry/resources@^1.4.0":
version "1.4.0"
resolved "https://registry.yarnpkg.com/@opentelemetry/resources/-/resources-1.4.0.tgz#5e23b0d7976158861059dec17e0ee36a35a5ab85"
integrity sha512-Q3pI5+pCM+Ur7YwK9GbG89UBipwJbfmuzSPAXTw964ZHFzSrz+JAgrETC9rqsUOYdUlj/V7LbRMG5bo72xE0Xw==
dependencies:
"@opentelemetry/core" "1.4.0"
"@opentelemetry/semantic-conventions" "1.4.0"

"@opentelemetry/resources@^1.3.1":
version "1.3.1"
resolved "https://registry.yarnpkg.com/@opentelemetry/resources/-/resources-1.3.1.tgz#9fd85ac4ffeefc35441404b384d5c1db8b243121"
integrity sha512-X8bl3X0YjlsHWy0Iv0KUETtZuRUznX4yr1iScKCtfy8AoRfZFc2xxWKMDJ0TrqYwSapgeg4YwpmRzUKmmnrbeA==
dependencies:
"@opentelemetry/core" "1.3.1"
"@opentelemetry/semantic-conventions" "1.3.1"

"@opentelemetry/[email protected]", "@opentelemetry/sdk-metrics-base@^0.30.0":
version "0.30.0"
resolved "https://registry.yarnpkg.com/@opentelemetry/sdk-metrics-base/-/sdk-metrics-base-0.30.0.tgz#242d9260a89a1ac2bf1e167b3fda758f3883c769"
Expand All @@ -4545,12 +4519,7 @@
"@opentelemetry/resources" "1.4.0"
"@opentelemetry/semantic-conventions" "1.4.0"

"@opentelemetry/[email protected]", "@opentelemetry/semantic-conventions@^1.3.1":
version "1.3.1"
resolved "https://registry.yarnpkg.com/@opentelemetry/semantic-conventions/-/semantic-conventions-1.3.1.tgz#ba07b864a3c955f061aa30ea3ef7f4ae4449794a"
integrity sha512-wU5J8rUoo32oSef/rFpOT1HIjLjAv3qIDHkw1QIhODV3OpAVHi5oVzlouozg9obUmZKtbZ0qUe/m7FP0y0yBzA==

"@opentelemetry/[email protected]":
"@opentelemetry/[email protected]", "@opentelemetry/semantic-conventions@^1.4.0":
version "1.4.0"
resolved "https://registry.yarnpkg.com/@opentelemetry/semantic-conventions/-/semantic-conventions-1.4.0.tgz#facf2c67d6063b9918d5a5e3fdf25f3a30d547b6"
integrity sha512-Hzl8soGpmyzja9w3kiFFcYJ7n5HNETpplY6cb67KR4QPlxp4FTTresO06qXHgHDhyIInmbLJXuwARjjpsKYGuQ==
Expand Down Expand Up @@ -6930,10 +6899,6 @@
version "0.0.0"
uid ""

"@types/kbn__core-http-server@link:bazel-bin/packages/core/http/core-http-server/npm_module_types":
version "0.0.0"
uid ""

"@types/kbn__core-http-browser-internal@link:bazel-bin/packages/core/http/core-http-browser-internal/npm_module_types":
version "0.0.0"
uid ""
Expand All @@ -6950,6 +6915,10 @@
version "0.0.0"
uid ""

"@types/kbn__core-http-server@link:bazel-bin/packages/core/http/core-http-server/npm_module_types":
version "0.0.0"
uid ""

"@types/kbn__core-i18n-browser-internal@link:bazel-bin/packages/core/i18n/core-i18n-browser-internal/npm_module_types":
version "0.0.0"
uid ""
Expand Down Expand Up @@ -24037,7 +24006,7 @@ [email protected]:
"@types/node" "^10.1.0"
long "^4.0.0"

protobufjs@^6.10.0, protobufjs@^6.11.3:
protobufjs@^6.11.3:
version "6.11.3"
resolved "https://registry.yarnpkg.com/protobufjs/-/protobufjs-6.11.3.tgz#637a527205a35caa4f3e2a9a4a13ddffe0e7af74"
integrity sha512-xL96WDdCZYdU7Slin569tFX712BxsxslWwAfAhCYjQKGTq7dAU91Lomy6nLLhh/dyGhk/YH4TwTSRxTzhuHyZg==
Expand Down Expand Up @@ -31008,7 +30977,7 @@ [email protected]:

[email protected], yargs@^16.2.0:
version "16.2.0"
resolved "https://registry.npmjs.org/yargs/-/yargs-16.2.0.tgz"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-16.2.0.tgz#1c82bf0f6b6a66eafce7ef30e376f49a12477f66"
integrity sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw==
dependencies:
cliui "^7.0.2"
Expand Down