-
Notifications
You must be signed in to change notification settings - Fork 12
Add telemetry-to-caas kind for CaaS (Collector as a Service) support #436
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
base: main
Are you sure you want to change the base?
Changes from all commits
08837fe
79eaadc
12223ce
2da163c
46b0129
a10eb6b
41f70d5
6de322b
10140df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -129,6 +129,77 @@ function getCredsForCLSAsUPS() { | |||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| function getCredsForCaaS() { | ||||||||
| if (!process.env.VCAP_SERVICES) return | ||||||||
| const vcap = JSON.parse(process.env.VCAP_SERVICES) | ||||||||
|
|
||||||||
| // look for caas-service binding | ||||||||
| const caas = vcap['caas-service']?.[0] | ||||||||
| if (caas) return caas.credentials | ||||||||
| } | ||||||||
|
|
||||||||
| function getCredsForCertService() { | ||||||||
| if (!process.env.VCAP_SERVICES) return | ||||||||
| const vcap = JSON.parse(process.env.VCAP_SERVICES) | ||||||||
| const certSvc = vcap['certificate-service']?.[0] | ||||||||
| if (certSvc) return certSvc.credentials | ||||||||
| } | ||||||||
|
|
||||||||
| function getCredsForCaaSMtls() { | ||||||||
| if (!process.env.VCAP_SERVICES) return | ||||||||
| const vcap = JSON.parse(process.env.VCAP_SERVICES) | ||||||||
| // Look for user-provided service with name containing 'caas-mtls' or 'caas-cert' | ||||||||
| const mtlsCreds = vcap['user-provided']?.find(b => b.name.match(/caas-mtls|caas-cert/i)) | ||||||||
| if (mtlsCreds) return mtlsCreds.credentials | ||||||||
| } | ||||||||
|
|
||||||||
| function augmentCaaSCreds(credentials) { | ||||||||
| if (credentials._augmented) return | ||||||||
| credentials._augmented = true | ||||||||
|
|
||||||||
| // check for otlp endpoints | ||||||||
| if (!credentials.otlp?.http && !credentials.otlp?.grpc) { | ||||||||
| throw new Error('No OTLP endpoints found in CaaS binding. Make sure the CaaS instance is properly configured.') | ||||||||
| } | ||||||||
|
|
||||||||
| // Store the base URL - path will be added per signal type (traces: /v1/traces, metrics: /v1/metrics) | ||||||||
| credentials.baseUrl = credentials.otlp.http | ||||||||
| // Also set url for backwards compatibility (without path - exporter will append it) | ||||||||
| credentials.url = credentials.otlp.http | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Logic Error: When
Suggested change
Double-check suggestion before committing. Edit this comment for amendments. Please provide feedback on the review comment by checking the appropriate box:
|
||||||||
|
|
||||||||
| // Check for mTLS credentials (cert + key) in user-provided service | ||||||||
| const mtlsCreds = getCredsForCaaSMtls() | ||||||||
| if (mtlsCreds && mtlsCreds.cert && mtlsCreds.key) { | ||||||||
| LOG._info && LOG.info('Found CaaS mTLS credentials, configuring HTTPS agent options') | ||||||||
| try { | ||||||||
| const cert = Buffer.from(mtlsCreds.cert, 'base64').toString('utf-8') | ||||||||
| const key = Buffer.from(mtlsCreds.key, 'base64').toString('utf-8') | ||||||||
|
|
||||||||
| // Store the mTLS options for the exporter's httpAgentOptions | ||||||||
| // The OTLP HTTP exporter will create an https.Agent with these options | ||||||||
| credentials.httpAgentOptions = { | ||||||||
| cert: cert, | ||||||||
| key: key, | ||||||||
| keepAlive: true | ||||||||
| } | ||||||||
|
|
||||||||
| LOG._info && LOG.info('CaaS mTLS credentials configured successfully') | ||||||||
| } catch (err) { | ||||||||
| LOG._error && LOG.error('Failed to configure CaaS mTLS:', err.message) | ||||||||
| } | ||||||||
| } else { | ||||||||
| // Check for certificate-service binding (manual enrollment needed) | ||||||||
| const certServiceCreds = getCredsForCertService() | ||||||||
| if (certServiceCreds) { | ||||||||
| LOG._warn && LOG.warn('Found certificate-service binding but no caas-mtls-creds.') | ||||||||
| LOG._warn && LOG.warn('Run the certificate enrollment script and create caas-mtls-creds service.') | ||||||||
| } else { | ||||||||
| LOG._warn && LOG.warn('CaaS requires mTLS authentication. No mTLS credentials found.') | ||||||||
| LOG._warn && LOG.warn('Bind a caas-mtls-creds user-provided service with cert and key.') | ||||||||
| } | ||||||||
| } | ||||||||
| } | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Please provide feedback on the review comment by checking the appropriate box:
|
||||||||
|
|
||||||||
| function augmentCLCreds(credentials) { | ||||||||
| if (credentials._augmented) return | ||||||||
| credentials._augmented = true | ||||||||
|
|
@@ -194,7 +265,10 @@ module.exports = { | |||||||
| getDynatraceMetadata, | ||||||||
| getCredsForDTAsUPS, | ||||||||
| getCredsForCLSAsUPS, | ||||||||
| getCredsForCaaS, | ||||||||
| getCredsForCertService, | ||||||||
| augmentCLCreds, | ||||||||
| augmentCaaSCreds, | ||||||||
| hasDependency, | ||||||||
| _hrnow, | ||||||||
| _require | ||||||||
|
|
||||||||
Uh oh!
There was an error while loading. Please reload this page.