Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't generate any metrics bits if prometheus is disabled #65

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions internal/impl/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,17 @@ func (r *replicaSet) buildDeployment(cfg *KubeConfig) (*appsv1.Deployment, error
podLabels := map[string]string{
"appName": r.app.Name,
"depName": name,
"metrics": r.app.Name, // Needed by Prometheus to scrape the metrics.
}
if cfg.Observability[metricsConfigKey] != disabled {
podLabels["metrics"] = r.app.Name // Needed by Prometheus to scrape the metrics.
}

dnsPolicy := corev1.DNSClusterFirst
if cfg.UseHostNetwork {
dnsPolicy = corev1.DNSClusterFirstWithHostNet
}

container, err := r.buildContainer()
container, err := r.buildContainer(cfg)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -320,7 +323,7 @@ func (r *replicaSet) buildAutoscaler() (*autoscalingv2.HorizontalPodAutoscaler,
}

// buildContainer builds a container specification for a replica set.
func (r *replicaSet) buildContainer() (corev1.Container, error) {
func (r *replicaSet) buildContainer(cfg *KubeConfig) (corev1.Container, error) {
// Set the binary path in the deployment w.r.t. to the binary path in the
// docker image.
r.app.Binary = fmt.Sprintf("/weaver/%s", filepath.Base(r.app.Binary))
Expand All @@ -339,9 +342,7 @@ func (r *replicaSet) buildContainer() (corev1.Container, error) {

// Always expose the metrics port from the container, so it can be
// discoverable for scraping by Prometheus.
ports := []corev1.ContainerPort{
{Name: "prometheus", ContainerPort: defaultMetricsPort},
}
var ports []corev1.ContainerPort
// Expose all of the listener ports.
for _, ls := range r.components {
for _, l := range ls.Listeners {
Expand All @@ -352,6 +353,17 @@ func (r *replicaSet) buildContainer() (corev1.Container, error) {
}
}

if cfg.Observability[metricsConfigKey] != disabled {
// Expose the metrics port from the container, so it can be discoverable for
// scraping by Prometheus.
// TODO(rgrandl): We may want to have a default metrics port that can be scraped
// by any metrics collection system. For now, disable the port if Prometheus
// will not collect the metrics.
ports = append(ports, corev1.ContainerPort{
Name: "prometheus", ContainerPort: defaultMetricsPort,
})
}

return corev1.Container{
Name: appContainerName,
Image: r.image,
Expand Down
Loading