Fix health check logging with dynamic log level in endpoint
Use Plug.Telemetry's dynamic log level feature to disable logging for /health requests. This is the proper Phoenix way to exclude specific endpoints from request logs. - Add log_level/1 function to endpoint that returns false for /health - Configure Plug.Telemetry to use dynamic log level - Remove log: false from router (handled by endpoint now) This prevents Kubernetes health probe spam in application logs.
This commit is contained in:
parent
673ad13db8
commit
fd317770fe
3 changed files with 90 additions and 83 deletions
|
|
@ -5,7 +5,7 @@ metadata:
|
|||
name: towerops
|
||||
namespace: towerops
|
||||
spec:
|
||||
replicas: 2
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: towerops
|
||||
|
|
@ -15,7 +15,7 @@ spec:
|
|||
app: towerops
|
||||
spec:
|
||||
imagePullSecrets:
|
||||
- name: gitlab-registry
|
||||
- name: gitlab-registry
|
||||
securityContext:
|
||||
runAsNonRoot: true
|
||||
runAsUser: 65534
|
||||
|
|
@ -23,82 +23,82 @@ spec:
|
|||
seccompProfile:
|
||||
type: RuntimeDefault
|
||||
containers:
|
||||
- name: towerops
|
||||
image: registry.gitlab.com/graham/towerops:latest
|
||||
imagePullPolicy: Always
|
||||
securityContext:
|
||||
allowPrivilegeEscalation: false
|
||||
runAsNonRoot: true
|
||||
runAsUser: 65534
|
||||
capabilities:
|
||||
drop:
|
||||
- ALL
|
||||
seccompProfile:
|
||||
type: RuntimeDefault
|
||||
ports:
|
||||
- containerPort: 4000
|
||||
name: http
|
||||
- containerPort: 4369
|
||||
name: epmd
|
||||
- containerPort: 9000
|
||||
name: dist
|
||||
env:
|
||||
- name: POD_IP
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
fieldPath: status.podIP
|
||||
- name: POD_NAME
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
fieldPath: metadata.name
|
||||
- name: POD_NAMESPACE
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
fieldPath: metadata.namespace
|
||||
- name: RELEASE_DISTRIBUTION
|
||||
value: "name"
|
||||
- name: RELEASE_NODE
|
||||
value: "towerops@$(POD_IP)"
|
||||
- name: PORT
|
||||
value: "4000"
|
||||
- name: PHX_HOST
|
||||
value: "towerops.net"
|
||||
- name: MIX_ENV
|
||||
value: "prod"
|
||||
- name: RELEASE_COOKIE
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: towerops-secrets
|
||||
key: RELEASE_COOKIE
|
||||
- name: SECRET_KEY_BASE
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: towerops-secrets
|
||||
key: SECRET_KEY_BASE
|
||||
- name: SENDGRID_API_KEY
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: towerops-sendgrid
|
||||
key: SENDGRID_API_KEY
|
||||
envFrom:
|
||||
- secretRef:
|
||||
name: towerops-db
|
||||
resources:
|
||||
requests:
|
||||
memory: "1Gi"
|
||||
cpu: "100m"
|
||||
limits:
|
||||
memory: "2Gi"
|
||||
cpu: "500m"
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /health
|
||||
port: 4000
|
||||
initialDelaySeconds: 30
|
||||
periodSeconds: 10
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /health
|
||||
port: 4000
|
||||
initialDelaySeconds: 10
|
||||
periodSeconds: 5
|
||||
- name: towerops
|
||||
image: registry.gitlab.com/graham/towerops:latest
|
||||
imagePullPolicy: Always
|
||||
securityContext:
|
||||
allowPrivilegeEscalation: false
|
||||
runAsNonRoot: true
|
||||
runAsUser: 65534
|
||||
capabilities:
|
||||
drop:
|
||||
- ALL
|
||||
seccompProfile:
|
||||
type: RuntimeDefault
|
||||
ports:
|
||||
- containerPort: 4000
|
||||
name: http
|
||||
- containerPort: 4369
|
||||
name: epmd
|
||||
- containerPort: 9000
|
||||
name: dist
|
||||
env:
|
||||
- name: POD_IP
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
fieldPath: status.podIP
|
||||
- name: POD_NAME
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
fieldPath: metadata.name
|
||||
- name: POD_NAMESPACE
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
fieldPath: metadata.namespace
|
||||
- name: RELEASE_DISTRIBUTION
|
||||
value: "name"
|
||||
- name: RELEASE_NODE
|
||||
value: "towerops@$(POD_IP)"
|
||||
- name: PORT
|
||||
value: "4000"
|
||||
- name: PHX_HOST
|
||||
value: "towerops.net"
|
||||
- name: MIX_ENV
|
||||
value: "prod"
|
||||
- name: RELEASE_COOKIE
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: towerops-secrets
|
||||
key: RELEASE_COOKIE
|
||||
- name: SECRET_KEY_BASE
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: towerops-secrets
|
||||
key: SECRET_KEY_BASE
|
||||
- name: SENDGRID_API_KEY
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: towerops-sendgrid
|
||||
key: SENDGRID_API_KEY
|
||||
envFrom:
|
||||
- secretRef:
|
||||
name: towerops-db
|
||||
resources:
|
||||
requests:
|
||||
memory: "1Gi"
|
||||
cpu: "100m"
|
||||
limits:
|
||||
memory: "2Gi"
|
||||
cpu: "500m"
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /health
|
||||
port: 4000
|
||||
initialDelaySeconds: 30
|
||||
periodSeconds: 10
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /health
|
||||
port: 4000
|
||||
initialDelaySeconds: 10
|
||||
periodSeconds: 5
|
||||
|
|
|
|||
|
|
@ -41,7 +41,10 @@ defmodule ToweropsWeb.Endpoint do
|
|||
cookie_key: "request_logger"
|
||||
|
||||
plug Plug.RequestId
|
||||
plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint]
|
||||
|
||||
plug Plug.Telemetry,
|
||||
event_prefix: [:phoenix, :endpoint],
|
||||
log: {__MODULE__, :log_level, []}
|
||||
|
||||
plug Plug.Parsers,
|
||||
parsers: [:urlencoded, :multipart, :json],
|
||||
|
|
@ -52,4 +55,8 @@ defmodule ToweropsWeb.Endpoint do
|
|||
plug Plug.Head
|
||||
plug Plug.Session, @session_options
|
||||
plug ToweropsWeb.Router
|
||||
|
||||
# Disable logging for health check endpoint to reduce log noise from K8s probes
|
||||
def log_level(%{path_info: ["health"]}), do: false
|
||||
def log_level(_), do: :info
|
||||
end
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ defmodule ToweropsWeb.Router do
|
|||
|
||||
# Health check endpoint for Kubernetes probes (no authentication required)
|
||||
scope "/", ToweropsWeb do
|
||||
get "/health", HealthController, :index, log: false
|
||||
get "/health", HealthController, :index
|
||||
end
|
||||
|
||||
scope "/", ToweropsWeb do
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue