Documentation
¶
Overview ¶
Package alloy provides business logic for Grafana Alloy configuration and installation.
Index ¶
- Constants
- func BaseHelmValues() []string
- func BlockNodeServiceMonitorManifest(namespace string) (string, error)
- func BuildHelmEnvVars(cfg models.AlloyConfig) []string
- func ConfigMapManifest(modules []ModuleConfig) (string, error)
- func GetModuleNames(modules []ModuleConfig) []string
- func HostNetworkHelmValues() []string
- func IndentLines(text, indent string) string
- func NamespaceManifest() (string, error)
- type BlockNodeServiceMonitorTemplateData
- type ConfigBuilder
- func (cb *ConfigBuilder) ClusterName() string
- func (cb *ConfigBuilder) LokiForwardTo() string
- func (cb *ConfigBuilder) LokiRemotes() []Remote
- func (cb *ConfigBuilder) MonitorBlockNode() bool
- func (cb *ConfigBuilder) PrometheusForwardTo() string
- func (cb *ConfigBuilder) PrometheusRemotes() []Remote
- func (cb *ConfigBuilder) RequiredSecrets() map[string][]string
- func (cb *ConfigBuilder) ResolvedLabels(labelProfile string) map[string]string
- func (cb *ConfigBuilder) ShouldUseHostNetwork() bool
- func (cb *ConfigBuilder) ToTemplateRemotes() ([]templates.AlloyRemote, []templates.AlloyRemote)
- type ConfigMapTemplateData
- type ModuleConfig
- type ModuleTemplateData
- type NamespaceTemplateData
- type Remote
Constants ¶
const ( // Kubernetes resource names ConfigMapName = "grafana-alloy-cm" SecretsName = "grafana-alloy-secrets" // Template paths CoreTemplatePath = "files/alloy/core.alloy" RemotesTemplatePath = "files/alloy/remotes.alloy" AgentMetricsTemplatePath = "files/alloy/agent-metrics.alloy" NodeExporterTemplatePath = "files/alloy/node-exporter.alloy" KubeletTemplatePath = "files/alloy/kubelet.alloy" SyslogTemplatePath = "files/alloy/syslog.alloy" BlockNodeTemplatePath = "files/alloy/block-node.alloy" BlockNodeServiceMonitorPath = "files/alloy/block-node-servicemonitor.yaml" )
Variables ¶
This section is empty.
Functions ¶
func BaseHelmValues ¶
func BaseHelmValues() []string
BaseHelmValues returns the base Helm values for Alloy installation. Configures Alloy to load config from a single config.alloy key in the ConfigMap.
func BlockNodeServiceMonitorManifest ¶
BlockNodeServiceMonitorManifest generates the ServiceMonitor manifest for block-node. This is required for Alloy to discover and scrape block-node metrics. The namespace parameter should be the block node's configured namespace.
func BuildHelmEnvVars ¶
func BuildHelmEnvVars(cfg models.AlloyConfig) []string
BuildHelmEnvVars builds the Helm values for environment variables from secrets. All passwords are sourced from the conventional K8s Secret "grafana-alloy-secrets" using keys derived from remote names (e.g., PROMETHEUS_PASSWORD_PRIMARY).
func ConfigMapManifest ¶
func ConfigMapManifest(modules []ModuleConfig) (string, error)
ConfigMapManifest generates the Alloy ConfigMap manifest. Uses the configmap.yaml template file.
func GetModuleNames ¶
func GetModuleNames(modules []ModuleConfig) []string
GetModuleNames returns just the module names from the configs.
func HostNetworkHelmValues ¶
func HostNetworkHelmValues() []string
HostNetworkHelmValues returns Helm values for enabling host network access.
func IndentLines ¶
IndentLines adds the specified indentation to each line of the text.
func NamespaceManifest ¶
NamespaceManifest generates the Alloy namespace manifest. Uses the namespace.yaml template file.
Types ¶
type BlockNodeServiceMonitorTemplateData ¶
type BlockNodeServiceMonitorTemplateData struct {
Namespace string
}
BlockNodeServiceMonitorTemplateData holds data for the block-node ServiceMonitor template.
type ConfigBuilder ¶
type ConfigBuilder struct {
// contains filtered or unexported fields
}
ConfigBuilder helps build Alloy configuration from various sources.
func NewConfigBuilder ¶
func NewConfigBuilder(cfg models.AlloyConfig, deployProfile string) (*ConfigBuilder, error)
NewConfigBuilder creates a new ConfigBuilder from the application config. Returns an error if cluster name cannot be determined (neither provided nor hostname available).
func (*ConfigBuilder) ClusterName ¶
func (cb *ConfigBuilder) ClusterName() string
ClusterName returns the cluster name.
func (*ConfigBuilder) LokiForwardTo ¶
func (cb *ConfigBuilder) LokiForwardTo() string
LokiForwardTo returns the forward_to string for Loki remotes.
func (*ConfigBuilder) LokiRemotes ¶
func (cb *ConfigBuilder) LokiRemotes() []Remote
LokiRemotes returns the Loki remote configurations.
func (*ConfigBuilder) MonitorBlockNode ¶
func (cb *ConfigBuilder) MonitorBlockNode() bool
MonitorBlockNode returns whether block node monitoring is enabled.
func (*ConfigBuilder) PrometheusForwardTo ¶
func (cb *ConfigBuilder) PrometheusForwardTo() string
PrometheusForwardTo returns the forward_to string for Prometheus remotes.
func (*ConfigBuilder) PrometheusRemotes ¶
func (cb *ConfigBuilder) PrometheusRemotes() []Remote
PrometheusRemotes returns the Prometheus remote configurations.
func (*ConfigBuilder) RequiredSecrets ¶
func (cb *ConfigBuilder) RequiredSecrets() map[string][]string
RequiredSecrets returns the K8s secret name and expected keys that must exist for the configured remotes. All passwords are expected in the conventional secret "grafana-alloy-secrets" under keys derived from remote names. Returns nil if no remotes are configured.
func (*ConfigBuilder) ResolvedLabels ¶ added in v0.14.0
func (cb *ConfigBuilder) ResolvedLabels(labelProfile string) map[string]string
ResolvedLabels returns the resolved label map for the given label profile. If labelProfile is empty, the default profile is used.
func (*ConfigBuilder) ShouldUseHostNetwork ¶
func (cb *ConfigBuilder) ShouldUseHostNetwork() bool
ShouldUseHostNetwork checks if any remote URL requires host network access.
func (*ConfigBuilder) ToTemplateRemotes ¶
func (cb *ConfigBuilder) ToTemplateRemotes() ([]templates.AlloyRemote, []templates.AlloyRemote)
ToTemplateRemotes converts internal remotes to template remotes. The resolved label rules are pre-rendered into AlloyRemote.CustomRules so templates can inject them. Each remote resolves labels from its own LabelProfile (defaulting to "eng", which produces only the cluster label).
type ConfigMapTemplateData ¶
type ConfigMapTemplateData struct {
ConfigMapName string
Namespace string
Modules []ModuleTemplateData
}
ConfigMapTemplateData holds data for the ConfigMap template.
type ModuleConfig ¶
type ModuleConfig struct {
Name string // Module name (e.g., "core", "remotes", "block-node")
Filename string // Filename for the ConfigMap key (e.g., "core.alloy")
Content string // Rendered template content
}
ModuleConfig represents a single Alloy configuration module.
func RenderModularConfigs ¶
func RenderModularConfigs(cb *ConfigBuilder) ([]ModuleConfig, error)
RenderModularConfigs renders all Alloy configuration modules as separate configs. Returns a slice of ModuleConfig with the module name, filename, and content. Returns an error if any required template fails to render.
type ModuleTemplateData ¶
ModuleTemplateData holds module data for the template.
type NamespaceTemplateData ¶
type NamespaceTemplateData struct {
Namespace string
}
NamespaceTemplateData holds data for the namespace template.