Skip to content

Commit

Permalink
ISSUE-155 Enable prometheus monitoring for zookeeper pods
Browse files Browse the repository at this point in the history
Since 3.6.0 ZooKeeper supports native Prometheus monitoring
https://github.com/apache/zookeeper/blob/master/zookeeper-docs/src/main/resources/markdown/zookeeperMonitor.md#prometheus

This patch
- enables `PrometheusMetricsProvider` in zoo.cfg
- expose a new `metrics` port to ZK pods, ZK services
- disambiguate the headless and client service labels by adding a new label,
 so it can be used in Prometheus `ServiceMonitors`
  • Loading branch information
amuraru committed May 3, 2020
1 parent 206b36e commit e13e27a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
13 changes: 10 additions & 3 deletions pkg/apis/zookeeper/v1beta1/zookeepercluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ func (s *ZookeeperClusterSpec) withDefaults(z *ZookeeperCluster) (changed bool)
Name: "leader-election",
ContainerPort: 3888,
},
{
Name: "metrics",
ContainerPort: 7000,
},
}
changed = true
}
Expand Down Expand Up @@ -182,6 +186,8 @@ func (z *ZookeeperCluster) ZookeeperPorts() Ports {
ports.Quorum = p.ContainerPort
} else if p.Name == "leader-election" {
ports.Leader = p.ContainerPort
} else if p.Name == "metrics" {
ports.Metrics = p.ContainerPort
}
}
return ports
Expand All @@ -194,9 +200,10 @@ func (z *ZookeeperCluster) GetClientServiceName() string {

// Ports groups the ports for a zookeeper cluster node for easy access
type Ports struct {
Client int32
Quorum int32
Leader int32
Client int32
Quorum int32
Leader int32
Metrics int32
}

// ContainerImage defines the fields needed for a Docker repository image. The
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/zookeeper/v1beta1/zookeepercluster_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ var _ = Describe("ZookeeperCluster Types", func() {
It("should have a leader port", func() {
Ω(p.Leader).To(BeEquivalentTo(3888))
})

It("should have a metrics port", func() {
Ω(p.Metrics).To(BeEquivalentTo(7000))
})
})

})
6 changes: 5 additions & 1 deletion pkg/zk/generators.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ func MakeHeadlessService(z *v1beta1.ZookeeperCluster) *v1.Service {
svcPorts := []v1.ServicePort{
{Name: "quorum", Port: ports.Quorum},
{Name: "leader-election", Port: ports.Leader},
{Name: "metrics", Port: ports.Metrics},
}
return makeService(headlessSvcName(z), svcPorts, false, z)
}
Expand All @@ -194,6 +195,9 @@ func makeZkConfigString(s v1beta1.ZookeeperClusterSpec) string {
"standaloneEnabled=false\n" +
"reconfigEnabled=true\n" +
"skipACL=yes\n" +
"metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider\n" +
"metricsProvider.httpPort=7000\n" +
"metricsProvider.exportJvmInfo=true\n" +
"initLimit=" + strconv.Itoa(s.Conf.InitLimit) + "\n" +
"syncLimit=" + strconv.Itoa(s.Conf.SyncLimit) + "\n" +
"tickTime=" + strconv.Itoa(s.Conf.TickTime) + "\n" +
Expand Down Expand Up @@ -259,7 +263,7 @@ func makeService(name string, ports []v1.ServicePort, clusterIP bool, z *v1beta1
Kind: "ZookeeperCluster",
}),
},
Labels: map[string]string{"app": z.GetName()},
Labels: map[string]string{"app": z.GetName(), "headless": strconv.FormatBool(!clusterIP)},
Annotations: annotationMap,
},
Spec: v1.ServiceSpec{
Expand Down

0 comments on commit e13e27a

Please sign in to comment.