Skip to content

Commit

Permalink
Allow use of external NewRelic daemon [sc-176579]
Browse files Browse the repository at this point in the history
  • Loading branch information
chrislrobinson committed Jan 23, 2025
1 parent 6295285 commit 6c73fca
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 14 deletions.
22 changes: 11 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ COPY --from=node:18.19-bookworm /usr/local/lib/node_modules /usr/local/lib/node_
RUN npm install --global tsx

RUN sed -i 's/providers = provider_sect/providers = provider_sect\n\
ssl_conf = ssl_sect\n\
\n\
[ssl_sect]\n\
system_default = system_default_sect\n\
\n\
[system_default_sect]\n\
Options = UnsafeLegacyRenegotiation/' /etc/ssl/openssl.cnf
ssl_conf = ssl_sect\n\
\n\
[ssl_sect]\n\
system_default = system_default_sect\n\
\n\
[system_default_sect]\n\
Options = UnsafeLegacyRenegotiation/' /etc/ssl/openssl.cnf

RUN set -e \
&& printf '; priority=20\nextension=protobuf.so' > /etc/php/8.3/mods-available/protobuf.ini \
Expand Down Expand Up @@ -135,16 +135,16 @@ RUN set -e \
&& addgroup --gid 1085 nginx \
&& adduser --system --shell /bin/false --no-create-home --disabled-password --uid 1085 --gid 1085 nginx \
# initialize dirs and owners
&& mkdir -p /var/log/nginx /var/log/php /var/log/deskpro /var/log/supervisor /var/lib/vector \
&& mkdir -p /var/log/nginx /var/log/php /var/log/deskpro /var/log/supervisor /var/lib/vector /var/log/newrelic \
&& mkdir -p /srv/deskpro/INSTANCE_DATA/deskpro-config.d \
&& chown root:root /usr/local/bin/vector \
&& chown vector:adm /var/lib/vector \
&& chown nginx:adm /var/log/nginx \
&& chown dp_app:adm /var/log/php /var/log/deskpro \
&& chmod -R 0775 /var/log/php /var/log/deskpro \
&& chown dp_app:adm /var/log/php /var/log/deskpro /var/log/newrelic \
&& chmod -R 0775 /var/log/php /var/log/deskpro /var/log/newrelic \
# set group sticky bit on these dirs so
# new logs get created with adm group (so vector can read them)
&& chmod g+s /var/log/nginx /var/log/php /var/log/deskpro \
&& chmod g+s /var/log/nginx /var/log/php /var/log/deskpro /var/log/newrelic \
# extract var names from our reference list
# (these lists are used from various helper scripts or entrypoint scripts)
&& jq -r '.[] | select(.isPrivate|not) | .name' /usr/local/share/deskpro/container-var-reference.json > /usr/local/share/deskpro/container-public-var-list \
Expand Down
3 changes: 3 additions & 0 deletions etc/php/8.3/mods-available/newrelic.ini.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ newrelic.logfile = "/var/log/newrelic/php_agent.log"
newrelic.appname = {{ getenv "DESKPRO_NR_APP_NAME" "Deskpro" | quote }}
newrelic.daemon.logfile = "/var/log/newrelic/newrelic-daemon.log"
newrelic.daemon.location = "/usr/local/bin/newrelic-daemon"
{{if getenv "DESKPRO_NR_DAEMON_ADDRESS"}}
newrelic.daemon.address = {{ getenv "DESKPRO_NR_DAEMON_ADDRESS" "" | quote }}
{{end}}
{{else}}
# To enable newrelic extension, set DESKPRO_ENABLE_NEWRELIC=true
# extension = "newrelic.so"
Expand Down
57 changes: 57 additions & 0 deletions etc/vector/vector.d/10-newrelic.toml.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# newrelic php agent logs
[sources.newrelic_php_agent_raw]
type = "file"
include = ["/var/log/newrelic/php_agent.log"]
ignore_not_found = true

[transforms.newrelic_php_agent]
type = "remap"
inputs = ["newrelic_php_agent_raw"]
source = '''
if is_string(.message) && contains(string!(.message), get_env_var!("VECTOR_MARKER")) {
abort
}

.log_group = "newrelic-php-agent"
.app = "newrelic"
.chan = "agent"
.lvl = "INFO"

.parsed = parse_regex(.message, r'^(?P<ts>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} [+-]\d{4}) \((?P<pid>\d+ \d+)\) (?P<lvl>\w+): (?P<msg>.+)$') ?? {}
.ts = parse_timestamp(.parsed.ts, format: "%Y-%m-%d %H:%M:%S%.3f %z") ?? now()
if !is_nullish(.parsed.pid) {
.pid = .parsed.pid
}
if !is_nullish(.parsed.lvl) {
.lvl = upcase!(.parsed.lvl)
}
'''

# newrelic daemon
[sources.newrelic_daemon_raw]
type = "file"
include = ["/var/log/newrelic/newrelic-daemon.log"]
ignore_not_found = true

[transforms.newrelic_daemon]
type = "remap"
inputs = ["newrelic_daemon_raw"]
source = '''
if is_string(.message) && contains(string!(.message), get_env_var!("VECTOR_MARKER")) {
abort
}

.log_group = "newrelic-daemon"
.app = "newrelic"
.chan = "daemon"
.lvl = "INFO"

.parsed = parse_regex(.message, r'^(?P<ts>\S+ \S+) \((?P<pid>\d+)\) (?P<lvl>\w+): (?P<msg>.+)$') ?? {}
.ts = parse_timestamp(.parsed.ts, format: "%Y-%m-%d %H:%M:%S%.3f %z") ?? now()
if !is_nullish(.parsed.pid) {
.pid = to_int!(.parsed.pid)
}
if !is_nullish(.parsed.lvl) {
.lvl = upcase!(.parsed.lvl)
}
'''
5 changes: 4 additions & 1 deletion etc/vector/vector.d/90-output.toml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ inputs = [
"php_fpm_error",

"deskpro_logs",
"deskpro_services"
"deskpro_services",

"newrelic_php_agent",
"newrelic_daemon"
]
source = '''

Expand Down
6 changes: 4 additions & 2 deletions usr/local/sbin/entrypoint.d/00-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ for f in \
"/var/log/supervisor/php_fpm.log" \
"/var/log/supervisor/tasks.log" \
"/var/log/supervisor/svc_messenger.log" \
"/var/log/supervisor/svc_messenger_api.log"
"/var/log/supervisor/svc_messenger_api.log" \
"/var/log/newrelic/php_agent.log" \
"/var/log/newrelic/newrelic_daemon.log"
do
echo "[$(date -u +"%Y-%m-%dT%H:%M:%SZ")] Log file started: $f -- ${VECTOR_MARKER}" > "$f"
echo "[$(date -u +"%Y-%m-%dT%H:%M:%SZ")] Log file started: $f.1 -- ${VECTOR_MARKER}" > "$f.1"
done

chown -R nginx:adm /var/log/nginx/*.log
chown -R dp_app:adm /var/log/php/*.log
chown -R dp_app:adm /var/log/php/*.log /var/log/newrelic/*.log

touch /var/log/vector.log
chown vector:adm /var/log/vector.log
Expand Down
6 changes: 6 additions & 0 deletions usr/local/share/deskpro/container-var-reference.json
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@
"type": "string",
"default": "Deskpro"
},
{
"name": "DESKPRO_NR_DAEMON_ADDRESS",
"description": "Network address of an external NewRelic proxy daemon to use instead of the internal one.",
"type": "string",
"example": "1.2.3.4:31339"
},
{
"name": "DESKPRO_NR_LICENSE",
"description": "License key for NewRelic integration.",
Expand Down

0 comments on commit 6c73fca

Please sign in to comment.