Skip to content

Commit

Permalink
Changes to how NR APM configuration is setup
Browse files Browse the repository at this point in the history
  • Loading branch information
david-garcia-garcia authored Oct 15, 2024
1 parent 63770cd commit 117ffab
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 27 deletions.
2 changes: 1 addition & 1 deletion servercore2022iisnet48/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ services:
# Zona horaria del contenedor
- SBS_CONTAINERTIMEZONE=Pacific Standard Time
# Servicios de windows que quiero arrancar (que no lo estén por defecto), este de ejemplo es para debug
- SBS_SRVENSURE=WMSVC;newrelic-infra
- SBS_SRVENSURE=WMSVC;
# Acción cuando hay un fallo en el entrypoint, por defecto es Stop
- SBS_ENTRYPOINTERRORACTION=Stop
# Aprovisonamiento automático de certifciados con Chef, los coloca en el CCS
Expand Down
40 changes: 36 additions & 4 deletions servercore2022iisnet48/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,49 @@ Inherits behaviours from these other images:
* [Server Core 2022](../servercore2022/readme.md)
* [Server Core 2022 IIS](../servercore2022iis/readme.md)

Add the New Relic APM, the image has a default configuration in:
Adds the New Relic APM, the image has a default configuration in:

```powershell
C:\ProgramData\New Relic\.NET Agent\newrelic.config
C:\ProgramData\New Relic\.NET Agent\newrelic.config.template\newrelic.config
```

You can set the license key through environment:
Template is in it's own directory to deal with this issue: [EmptyDir not being cleaned up after pod terminated with open file handles · Issue #112630 · kubernetes/kubernetes (github.com)](https://github.com/kubernetes/kubernetes/issues/112630)

You can set the license key through environment

```
NEW_RELIC_LICENSE_KEY
```

or completely override the default configuratoin using a configmap.
setting the license key will both configure the license key and enable the agent in the configuration file.

To override the configuration in K8S, use a configmap:

```terraform
# Configmap
resource "kubernetes_config_map" "app_newrelic_customconfig" {
provider = kubernetes.cluster
metadata {
name = "${var.application_id}-app-newrelic-config"
namespace = kubernetes_namespace.app.metadata[0].name
}
data = {
"newrelic.config" = local.nri_config_contents
}
}
# Volume spec
volume {
name = "newrelic-config"
config_map {
name = kubernetes_config_map.app_newrelic_customconfig.metadata[0].name
}
}
# Volume mount (note that subpath is avoided on purpose)
volume_mount {
name = "newrelic-config"
mount_path = "C:/ProgramData/New Relic/.NET Agent/newrelic.config.template"
}
```

Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
<exclude>request.headers.authorization</exclude>
<exclude>request.headers.proxy-authorization</exclude>
<exclude>request.headers.x-*</exclude>
<exclude>request.headers.sec-*</exclude>
<exclude>request.headers.user-agent</exclude>
<exclude>request.headers.upgrade-insecure-requests</exclude>
<exclude>request.headers.sec-*</exclude>
<exclude>request.headers.user-agent</exclude>
<exclude>request.headers.upgrade-insecure-requests</exclude>
</attributes>
<transactionEvents enabled="true" maximumSamplesStored="50">
<attributes enabled="true">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1 @@
$envVar = [System.Environment]::GetEnvironmentVariable("NEW_RELIC_LICENSE_KEY");

if (![string]::IsNullOrEmpty($envVar)) {
$configPath = "C:\ProgramData\New Relic\.NET Agent\newrelic.config";
if (Test-Path $configPath) {
[xml]$config = Get-Content $configPath;
$config.configuration.SetAttribute("agentEnabled", "true");
$config.configuration.service.SetAttribute("licenseKey", $envVar);
$config.Save($configPath);
SbsWriteHost "New Relic agent has been enabled.";
}
else {
SbsWriteHost "Config file not found at $configPath";
}
}
else {
SbsWriteHost "NEW_RELIC_LICENSE_KEY environment variable is not set or empty.";
}
. "c:\entrypoint\refreshenv\SetupNrApm.ps1";
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
$NEW_RELIC_LICENSE_KEY = [System.Environment]::GetEnvironmentVariable("NEW_RELIC_LICENSE_KEY");

# We need to use these templates to overcome the configmap can only be readonly in K8S :/
$configTemplatePath = "C:\ProgramData\New Relic\.NET Agent\newrelic.config.template\newrelic.config";
$configPath = "C:\ProgramData\New Relic\.NET Agent\newrelic.config";

if (Test-Path $configTemplatePath) {
Copy-Item -Path $configTemplatePath -Destination $configPath -Force
if (![string]::IsNullOrEmpty($NEW_RELIC_LICENSE_KEY)) {
[xml]$config = Get-Content $configPath;
$config.configuration.SetAttribute("agentEnabled", "true");
$config.configuration.service.SetAttribute("licenseKey", $NEW_RELIC_LICENSE_KEY);
$config.Save($configPath);
SbsWriteHost "New Relic agent has been enabled through NEW_RELIC_LICENSE_KEY environment.";
}
else {
SbsWriteHost "NEW_RELIC_LICENSE_KEY environment variable is not set or empty, APM might not be enabled.";
}
}
else {
SbsWriteHost "Missing template $configTemplatePath"
}
2 changes: 1 addition & 1 deletion servercore2022iisnet48/setup/apm/setup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Write-Host "`n---------------------------------------";
Write-Host " Installing .Net agent";
Write-Host "-----------------------------------------`n";

choco upgrade newrelic-dotnet -y --version=10.27.0 --no-progress;
choco upgrade newrelic-dotnet -y --version=10.31.0 --no-progress;

# https://docs.newrelic.com/docs/apm/agents/net-agent/troubleshooting/no-data-appears-after-disabling-tls-10/#strongcrypto
# Esto hace falta para que el framework utilice por defecto TLS en lugar de SSL
Expand Down
26 changes: 26 additions & 0 deletions sqlserver2022base/compose-self-contained.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
services:
mssql:
stop_grace_period: 40s
build:
context: .
args:
IMG_SERVERCORE2022: ${IMG_SERVERCORE2022}
IMG_SQLSERVER2022AS: ${IMG_SQLSERVER2022AS}
IMG_SQLSERVER2022BASE: ${IMG_SQLSERVER2022BASE}
IMG_SQLSERVER2022K8S: ${IMG_SQLSERVER2022K8S}
MSSQLINSTALL_ISO_URL: ${MSSQLINSTALL_ISO_URL}
MSSQLINSTALL_CU_URL: ${MSSQLINSTALL_CU_URL}
MSSQLINSTALL_CUFIX_URL: ${MSSQLINSTALL_CUFIX_URL}
TEMP: ${BUILD_TEMP}
image: ${IMG_SQLSERVER2022BASE}
networks:
container_default:
ipv4_address: 172.18.8.8
environment:
- MSSQL_ADMIN_PWD_PROTECT=testpassword
- MSSQL_SERVERNAME=k8s
- SBS_ENTRYPOINTERRORACTION=Stop
- SBS_DEBUG=True
networks:
container_default:
external: true

0 comments on commit 117ffab

Please sign in to comment.