Skip to content

add Grafana Alloy and Loki for centralized log collection - #270

Open
IlyaMaluk wants to merge 2 commits into
mainfrom
infra/grafana-alloy-logging
Open

add Grafana Alloy and Loki for centralized log collection#270
IlyaMaluk wants to merge 2 commits into
mainfrom
infra/grafana-alloy-logging

Conversation

@IlyaMaluk

@IlyaMaluk IlyaMaluk commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features

    • Deployed unified logging platform with automatic log collection and indexing from all application containers, enabling better operational visibility and faster troubleshooting.
  • Chores

    • Optimized database instance configuration and Kubernetes infrastructure setup for improved resource efficiency.

@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@IlyaMaluk, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 39 minutes and 10 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e90d3ca3-3357-4ac0-ab0e-974f692f2584

📥 Commits

Reviewing files that changed from the base of the PR and between fbbd3b1 and eb047df.

📒 Files selected for processing (3)
  • deploy/k8s/infra/alloy-configmap.yaml
  • deploy/k8s/infra/alloy-daemonset.yaml
  • deploy/k8s/infra/loki.yaml
📝 Walkthrough

Walkthrough

Adds Loki and Grafana Alloy to the local Kubernetes infrastructure: a Loki Service/Deployment and an Alloy DaemonSet with RBAC and a ConfigMap defining a pod-log collection pipeline. The Kustomize resources list is updated to include all three new manifests. CNPG is scaled to one instance, and the Makefile readiness check switches from statefulset/postgres rollout to a kubectl wait on cluster/share-bite-cnpg.

Changes

Logging Stack and Infra Adjustments

Layer / File(s) Summary
Loki Service and Deployment
deploy/k8s/infra/loki.yaml
Defines a Service on port 3100 and a single-replica Deployment running grafana/loki:latest in the share-bite-local namespace.
Alloy RBAC, DaemonSet, and pipeline ConfigMap
deploy/k8s/infra/alloy-daemonset.yaml, deploy/k8s/infra/alloy-configmap.yaml
Creates the alloy ServiceAccount, ClusterRole (alloy-role) with get/list/watch on core resources, ClusterRoleBinding, and a DaemonSet running grafana/alloy:latest with host log volume mounts. The ConfigMap wires Kubernetes pod discovery → label relabeling → loki.source.kubernetesloki.write to the in-cluster Loki push URL.
Kustomization wiring, CNPG scale-down, and readiness gate
deploy/k8s/infra/kustomization.yaml, deploy/k8s/infra/cnpg.yaml, Makefile
Registers loki.yaml, alloy-configmap.yaml, and alloy-daemonset.yaml in the Kustomize resources list; reduces spec.instances in the CNPG cluster from 2 to 1; replaces the statefulset/postgres rollout wait with kubectl wait cluster/share-bite-cnpg --for=condition=Ready.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • ua-academy-projects/share-bite#228: Modifies the same k8s-up Makefile recipe's readiness-wait logic, adding Postgres/Redis rollout waits that this PR's change replaces with a CNPG cluster condition wait.

Suggested reviewers

  • escoutdoor
  • DmyMi

Poem

🐰 Hop hop, logs now flow,
Through Alloy's pipes they go,
Loki waits at port three-one-zero-zero,
One Postgres node — that's all we need, oh!
The cluster's Ready, the rabbit says so! 🪵

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main changes: adding Grafana Alloy and Loki for centralized log collection, which aligns with the new manifests (alloy-configmap.yaml, alloy-daemonset.yaml, loki.yaml) and kustomization updates.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch infra/grafana-alloy-logging

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 7

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@deploy/k8s/infra/alloy-configmap.yaml`:
- Around line 8-10: The discovery.kubernetes "pods" block in
alloy-configmap.yaml is performing global pod discovery, causing duplicate log
collection across DaemonSet replicas. Add a node_name selector to the
discovery.kubernetes "pods" configuration that filters pods to the local node by
using the NODE_NAME environment variable (which should reference spec.nodeName).
Additionally, in the alloy-daemonset.yaml container spec, add a NODE_NAME
environment variable that retrieves its value from the fieldRef spec.nodeName to
ensure each DaemonSet replica only discovers and ingests logs from pods running
on its own node.

In `@deploy/k8s/infra/alloy-daemonset.yaml`:
- Line 46: Replace the mutable image reference `grafana/alloy:latest` with a
specific pinned version tag combined with the image digest to ensure
reproducibility and prevent unexpected image changes between deployments. Use a
format like `grafana/alloy:<specific-version>`@sha256`:<digest>` where the version
is a tested release tag and the digest provides immutability verification.
- Around line 12-14: The RBAC rule in the alloy-daemonset.yaml is granting
overly broad permissions that exceed what the pipeline actually requires. The
discovery.kubernetes component with role "pod" only needs access to the pods
resource, so you should modify the resources array to contain only "pods"
instead of the current list that includes nodes, nodes/proxy, services, and
endpoints. This reduces the cluster read scope and follows the principle of
least privilege.
- Around line 56-61: The volumeMounts for varlog (/var/log) and
varlibdockercontainers (/var/lib/docker/containers) in the Alloy daemonset are
not utilized by the loki.source.kubernetes pipeline configuration, which obtains
pod logs through the Kubernetes API instead. Remove both the volumeMounts
entries for varlog and varlibdockercontainers from the containers spec, and then
remove their corresponding hostPath volume definitions from the volumes section
at the pod level to eliminate unnecessary node-level filesystem exposure and
reduce security risk.
- Around line 42-58: The Alloy DaemonSet spec lacks security hardening controls
required to restrict the container's privileges. Add a securityContext field at
the pod spec level (under the serviceAccountName field) to configure a seccomp
profile, and add a securityContext field within the alloy container definition
(alongside the image and args fields) to enforce non-root execution with
runAsNonRoot set to true, readOnlyRootFilesystem set to true, and drop all Linux
capabilities using capabilities.drop set to ["ALL"]. This hardens the DaemonSet
while maintaining compatibility with the standard log collection workload
(Kubernetes discovery and pod logs via Loki) that requires no elevated
privileges.

In `@deploy/k8s/infra/loki.yaml`:
- Line 31: The Loki image specification in the loki.yaml file uses the `:latest`
tag which creates non-reproducible deployments and supply chain risks. Replace
the `grafana/loki:latest` image reference with a pinned semantic version tag
(such as a specific release like 2.9.4) followed by the image digest using the
`@sha256:` format. You can find the correct digest for your chosen Loki version
from the Grafana container registry, ensuring both reproducibility and security.
- Around line 29-33: The Loki deployment in the spec section lacks security
restrictions that prevent privilege escalation and unauthorized access. Add a
securityContext at the pod spec level (before the containers array in the
template.spec section) to enforce RuntimeDefault seccomp and set fsGroup
settings. Additionally, add a securityContext within the container specification
(after the name and image fields of the loki container) to run the container as
a non-root user with UID 10001, drop all Linux capabilities, set
allowPrivilegeEscalation to false, and configure readOnlyRootFilesystem to true.
These settings will enforce the principle of least privilege while maintaining
Loki's functionality.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b10be3fd-f97c-4e39-8638-0bcc9b4c470a

📥 Commits

Reviewing files that changed from the base of the PR and between 39b3551 and fbbd3b1.

📒 Files selected for processing (6)
  • Makefile
  • deploy/k8s/infra/alloy-configmap.yaml
  • deploy/k8s/infra/alloy-daemonset.yaml
  • deploy/k8s/infra/cnpg.yaml
  • deploy/k8s/infra/kustomization.yaml
  • deploy/k8s/infra/loki.yaml

Comment thread deploy/k8s/infra/alloy-configmap.yaml
Comment thread deploy/k8s/infra/alloy-daemonset.yaml
Comment thread deploy/k8s/infra/alloy-daemonset.yaml Outdated
Comment thread deploy/k8s/infra/alloy-daemonset.yaml Outdated
Comment thread deploy/k8s/infra/alloy-daemonset.yaml Outdated
Comment thread deploy/k8s/infra/loki.yaml
Comment thread deploy/k8s/infra/loki.yaml Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant