How newrelic/nri-kube-events works
Project Type and Purpose
• This project is an integration for Kubernetes events, designed to actively watch Kubernetes event resources and push them to various configurable “sinks” (endpoints). In short, it is an event router that captures Kubernetes events and forwards them, for example to standard output or a New Relic infrastructure agent.
• Its purpose is both monitoring and integration. It integrates Kubernetes by watching for event changes and then dispatching notifications based on a configuration specified in a YAML file.
File Structure
• Top-level directories such as “cmd”, “pkg”, “charts”, “deploy”, “e2e”, and “test” indicate that this is both a production application (with deployment engineering in Dockerfile, Helm charts, and Kubernetes manifests) and a well-tested project (integration and end-to-end tests).
• The “cmd/nri-kube-events” folder contains the main application (main.go) that initializes and configures the event router.
• “pkg/events” – Contains the event router logic.
• “pkg/router” – Likely handles configuration and routing logic.
• “pkg/sinks” – Contains implementations for different sinks (stdout, newRelicInfra) as well as test data.
• “pkg/common” – Likely holds shared utilities or common components.
• There are also configuration and orchestration files:
• YAML configuration files for sinks and deployment (deploy/local.yaml.example).
• Helm charts (in the “charts” directory) that are used to deploy the integration within a Kubernetes cluster.
• Dockerfile and Skaffold configuration for containerizing and running the application locally.
• The numerous GitHub workflow files and CI/CD scripts indicate a strong focus on continuous integration and code quality.
a. Event Source:
• Kubernetes Cluster – The integration acts as a watcher for Kubernetes events.
b. Main Application – “nri-kube-events”:
• Event Router: Responsible for listening to events from the Kubernetes API.
• Configuration Manager: Uses the YAML file to load configurations including sink settings.
c. Sinks:
• Stdout Sink – Logs events to standard output.
• newRelicInfra Sink – Sends events to the New Relic Infrastructure Agent.
d. Supporting Components:
• Deployment and Containerization: Dockerfile, Helm Chart, and Skaffold scripts indicate container orchestration.
• Testing and Validation: E2E tests and integration tests validate functionality.
• CI/CD Workflows – Automated tests and linting pipelines ensure ongoing quality and deployment readiness.
Relationships and Interactions
• The Event Router obtains events from the Kubernetes API (represented by the “Kubernetes Cluster”).
• Once an event is received, the router processes the event (using logic spread across pkg/events and pkg/router) and dispatches it to one or more sinks.
• The sinks then act upon the received event – for instance, logging it to stdout or sending it to a New Relic agent via HTTP (using configurations from pkg/sinks/new_relic_infra.go).
• The configuration file (YAML) is used to specify which sinks to use, along with their individual settings (such as agentEndpoint and clusterName).
Architectural Patterns and Principles
• Separation of Concerns: The project clearly separates event capturing (watching k8s events), event processing (routing), and event handling (sinks).
• Extensibility: With the design implemented in separate packages (especially in pkg/sinks), adding new sinks or modifying existing ones is streamlined.
• Containerized Deployment: Docker and Helm charts show a microservice-like approach that facilitates deployment in Kubernetes.
• Testability: Inclusion of unit tests, integration tests, and E2E tests highlights a robust testing strategy.