-
Notifications
You must be signed in to change notification settings - Fork 209
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
[NOT FOR MERGING]: prototype: Send logs to team account based on namespace #1292
Open
bmcfeely
wants to merge
1
commit into
newrelic:master
Choose a base branch
from
bmcfeely:NR-227419-write-logs-to-team-accounts
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,67 @@ | ||
apiVersion: batch/v1 | ||
kind: Job | ||
metadata: | ||
name: newrelic-logging-config-creator | ||
# TODO: do we need namespace and labels like in configmap.yml?annotations: | ||
annotations: | ||
# This makes it so that this job is run first before any other resources | ||
# are created during chart installation/upgrade | ||
"helm.sh/hook": post-install,post-upgrade | ||
spec: | ||
template: | ||
spec: | ||
containers: | ||
- name: config-creator | ||
image: node # TODO: what image should we use | ||
command: | ||
- node | ||
- -e | ||
- | | ||
const fs = require('fs'); | ||
|
||
// Read configuration information | ||
const mappingFileName = '/etc/namespace-to-api-key-mapping/fluent-bit-namespace-to-api-key-mapping.json'; | ||
const mappingFileContents = fs.readFileSync(mappingFileName); | ||
const keysByNamespace = JSON.parse(mappingFileContents); | ||
|
||
// Write out the Fluent Bit config file | ||
const outputBlock = (namespace, key) => { | ||
return `[OUTPUT] | ||
Name newrelic | ||
Match_regex .*_${namespace}_.* | ||
apiKey ${key} | ||
endpoint \${ENDPOINT}`; | ||
}; | ||
const namespaces = Object.keys(keysByNamespace); | ||
const regexTerms = namespaces | ||
.map(namespace => `_${namespace}_`) | ||
.join('|'); | ||
const fallbackRegex = `^(?:(?!${regexTerms}).)*$` | ||
const fallbackBlock = `[OUTPUT] | ||
Name newrelic | ||
Match_regex ${fallbackRegex} | ||
apiKey \${LICENSE_KEY} | ||
endpoint \${ENDPOINT}`; | ||
const teamOutputBlocks = Object.entries(keysByNamespace) | ||
.map(([namespace, key]) => outputBlock(namespace, key)); | ||
const outputBlocks = [ | ||
...teamOutputBlocks, | ||
fallbackBlock, | ||
]; | ||
const configFileContents = outputBlocks.join('\n\n'); | ||
const configFileName = '/etc/fluent-bit-teams-config/newrelic-teams-output.conf'; | ||
fs.writeFileSync(configFileName, configFileContents); | ||
volumeMounts: | ||
- name: fluent-bit-namespace-to-api-key-mapping-volume | ||
mountPath: /etc/namespace-to-api-key-mapping | ||
- name: fluent-bit-teams-config-volume | ||
mountPath: /etc/fluent-bit-teams-config | ||
volumes: | ||
- name: fluent-bit-namespace-to-api-key-mapping-volume | ||
configMap: | ||
name: fluent-bit-namespace-to-api-key-mapping | ||
- name: fluent-bit-teams-config-volume | ||
hostPath: | ||
path: /etc/teams-config | ||
# TODO: docs had this, but do we need it? https://docs.openshift.com/dedicated/3/dev_guide/configmaps.html | ||
restartPolicy: Never |
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
13 changes: 13 additions & 0 deletions
13
charts/newrelic-logging/templates/fluent-bit-namespace-to-api-key-mapping.yml
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 @@ | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: fluent-bit-namespace-to-api-key-mapping | ||
# TODO: do we need namespace and labels? I stole them from configmap.yml | ||
namespace: {{ .Release.Namespace }} | ||
labels: {{ include "newrelic-logging.labels" . | indent 4 }} | ||
data: | ||
# TODO: this needs to be a Vault path instead of hard-coding keys | ||
fluent-bit-namespace-to-api-key-mapping.json: | | ||
{ | ||
"logging": "<REDACTED_KEY_FOR_PRODUCTION_756053>" | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure that we have a way to get secrets from Vault into k8s secrets so that they can be used. I'm assuming that's possible, I'm skipping it here (and just hardcoding keys locally) just so I can get done with the prototype sooner.