Skip to content
This repository was archived by the owner on Jan 9, 2023. It is now read-only.

Commit f0ade64

Browse files
authored
Merge pull request #352 from charlieegan3/prometheus-mode
Prometheus Install Modes
2 parents 68ce8b9 + 9b7d45e commit f0ade64

File tree

19 files changed

+483
-714
lines changed

19 files changed

+483
-714
lines changed

Gopkg.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/spelling_wordlist.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,4 @@ overprovisioning
7979
autoscaling
8080
preempted
8181
millicores
82+
yaml

docs/user-guide.rst

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ Cluster Autoscaler
156156
Tarmak supports deploying `Cluster Autoscaler
157157
<https://github.com/kubernetes/autoscaler/tree/master/cluster-autoscaler>`_ when
158158
spinning up a Kubernetes cluster. The following `tarmak.yaml` snippet shows how
159-
you would enable Cluster Autoscaler.
159+
you would enable Cluster Autoscaler.
160160

161161
.. code-block:: yaml
162162
@@ -323,9 +323,9 @@ Elasticsearch endpoint and the policy that allow shipping to it:
323323
::
324324

325325
Apply complete! Resources: 2 added, 0 changed, 0 destroyed.
326-
326+
327327
Outputs:
328-
328+
329329
elasticsearch_endpoint = search-tarmak-logs-xyz.eu-west-1.es.amazonaws.com
330330
elasticsearch_shipping_policy_arn = arn:aws:iam::1234:policy/tarmak-logs-shipping
331331

@@ -441,29 +441,42 @@ allows to override the deployed version:
441441
Prometheus
442442
~~~~~~~~~~
443443

444-
By default Tarmak will deploy a `Prometheus <https://prometheus.io/>`_ and some
445-
exporters into the ``monitoring`` namespace. Using this config Prometheus could
446-
be disabled all together:
444+
By default Tarmak will deploy a `Prometheus <https://prometheus.io/>`_
445+
installation and some exporters into the ``monitoring`` namespace.
446+
447+
This can be completely disabled with the following cluster configuration:
447448

448449
.. code-block:: yaml
449450
450451
kubernetes:
451452
prometheus:
452453
enabled: false
453454
454-
Another possibility would be to use The Tarmak provisioned Prometheus only for
455+
Another possibility would be to use the Tarmak provisioned Prometheus only for
455456
scraping exporters on instances that are not part of the Kubernetes cluster.
456-
Using federation those metrics could then be integrated into an already
457-
existing Prometheus deployment. Get that behaviour you needs to set the
458-
configuration like that:
457+
Using federation, those metrics could then be integrated into an existing
458+
Prometheus deployment.
459+
460+
To have Prometheus only monitor nodes external to the cluster, use the
461+
following configuration instead:
459462

460463
.. code-block:: yaml
461464
462465
kubernetes:
463466
prometheus:
464467
enabled: true
465-
externalScrapeTargetsOnly: true
468+
mode: ExternalScrapeTargetsOnly
469+
470+
Finally, you may wish to have Tarmak only install the exporters on the external
471+
nodes. If this is your desired configuration, then set the following mode in
472+
the yaml:
466473

474+
.. code-block:: yaml
475+
476+
kubernetes:
477+
prometheus:
478+
enabled: true
479+
mode: ExternalExportersOnly
467480
468481
API Server
469482
~~~~~~~~~~~

pkg/apis/cluster/v1alpha1/cluster.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ const (
3838
StateDestroy = "destroy"
3939
)
4040

41+
const (
42+
PrometheusModeFull = "Full"
43+
PrometheusModeExternalExportersOnly = "ExternalExportersOnly"
44+
PrometheusModeExternalScrapeTargetsOnly = "ExternalScrapeTargetsOnly"
45+
)
46+
4147
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
4248
// +resource:path=clusters
4349

@@ -165,8 +171,8 @@ type ClusterPodSecurityPolicy struct {
165171
type ClusterKubernetesPrometheus struct {
166172
// Enable a cluster internal prometheus deployment, default: true
167173
Enabled bool `json:"enabled,omitempty"`
168-
// Only deploy/scrape Kubernetes external exporters, default: false
169-
ExternalScrapeTargetsOnly bool `json:"externalScrapeTargetsOnly,omitempty"`
174+
// Mode defines which components are installed
175+
Mode string `json:"mode,omitempty"`
170176
}
171177

172178
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

pkg/puppet/puppet.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,13 @@ func kubernetesClusterConfig(conf *clusterv1alpha1.ClusterKubernetes, hieraData
143143
}
144144
}
145145

146-
// enabling prometheus if requested, default is to enable prometheus
146+
// enable prometheus if set, default: enabled
147147
if conf.Prometheus == nil || conf.Prometheus.Enabled {
148-
// check if mode external scrape targets only is enabled
149-
if conf.Prometheus != nil && conf.Prometheus.ExternalScrapeTargetsOnly {
150-
hieraData.variables = append(hieraData.variables, "prometheus::external_scrape_targets_only: true")
151-
} else {
152-
hieraData.variables = append(hieraData.variables, "prometheus::external_scrape_targets_only: false")
148+
mode := clusterv1alpha1.PrometheusModeFull
149+
if conf.Prometheus != nil && conf.Prometheus.Mode != "" {
150+
mode = conf.Prometheus.Mode
153151
}
152+
hieraData.variables = append(hieraData.variables, fmt.Sprintf("prometheus::mode: %s", mode))
154153
hieraData.classes = append(hieraData.classes, `prometheus`)
155154
}
156155

pkg/tarmak/cluster/cluster.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/hashicorp/go-multierror"
1010
"github.com/sirupsen/logrus"
11+
"k8s.io/apimachinery/pkg/util/sets"
1112

1213
clusterv1alpha1 "github.com/jetstack/tarmak/pkg/apis/cluster/v1alpha1"
1314
"github.com/jetstack/tarmak/pkg/tarmak/instance_pool"
@@ -206,6 +207,13 @@ func (c *Cluster) Validate() (result error) {
206207
result = multierror.Append(result, err)
207208
}
208209
}
210+
211+
//validate prometheus mode
212+
if c.Config().Kubernetes.Prometheus != nil {
213+
if err := c.validatePrometheusMode(); err != nil {
214+
result = multierror.Append(result, err)
215+
}
216+
}
209217
}
210218

211219
return result
@@ -297,6 +305,25 @@ func (c *Cluster) validateAPIServer() (result error) {
297305
return result
298306
}
299307

308+
func (c *Cluster) validatePrometheusMode() error {
309+
var result error
310+
311+
allowedModes := sets.NewString(
312+
clusterv1alpha1.PrometheusModeFull,
313+
clusterv1alpha1.PrometheusModeExternalScrapeTargetsOnly,
314+
clusterv1alpha1.PrometheusModeExternalExportersOnly,
315+
)
316+
317+
modeString := c.Config().Kubernetes.Prometheus.Mode
318+
if c.Config().Kubernetes.Prometheus != nil && modeString != "" {
319+
if !allowedModes.Has(modeString) {
320+
return fmt.Errorf("%s is not a valid Prometheus mode, allowed modes: %s", modeString, allowedModes.List())
321+
}
322+
}
323+
324+
return result
325+
}
326+
300327
// Determine if this Cluster is a cluster or hub, single or multi environment
301328
func (c *Cluster) Type() string {
302329
if c.conf.Type != "" {

puppet/modules/prometheus/manifests/blackbox_exporter.pp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@
1010
$namespace = $::prometheus::namespace
1111

1212
# Setup deployment for blackbox exporter in cluster
13-
if $::prometheus::role == 'master' {
14-
kubernetes::apply{'blackbox-exporter':
15-
manifests => [
16-
template('prometheus/prometheus-ns.yaml.erb'),
17-
template('prometheus/blackbox-exporter-deployment.yaml.erb'),
18-
template('prometheus/blackbox-exporter-svc.yaml.erb'),
19-
],
20-
}
13+
kubernetes::apply{'blackbox-exporter':
14+
manifests => [
15+
template('prometheus/prometheus-ns.yaml.erb'),
16+
template('prometheus/blackbox-exporter-deployment.yaml.erb'),
17+
template('prometheus/blackbox-exporter-svc.yaml.erb'),
18+
],
2119
}
2220
}

puppet/modules/prometheus/manifests/blackbox_exporter_etcd.pp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,13 @@
1919
if $::prometheus::role == 'master' {
2020
include ::prometheus::server
2121

22-
$blackbox_exporters = $::prometheus::etcd_cluster.map |$node| { "${node}:${port}" }
23-
2422
prometheus::scrape_config { 'etcd-k8s-main':
2523
order => 140,
2624
config => {
2725
'metrics_path' => '/probe',
2826
'params' => { 'module' => ['etcd_k8s_main_proxy'] },
29-
'static_configs' => [{
30-
'targets' => $blackbox_exporters,
31-
'labels' => {'role' => 'etcd'},
27+
'dns_sd_configs' => [{
28+
'names' => $tarmak::etcd_cluster_exporters,
3229
}],
3330
'relabel_configs' => [{
3431
'source_labels' => [],
@@ -44,9 +41,8 @@
4441
config => {
4542
'metrics_path' => '/probe',
4643
'params' => { 'module' => ['etcd_k8s_events_proxy'] },
47-
'static_configs' => [{
48-
'targets' => $blackbox_exporters,
49-
'labels' => {'role' => 'etcd'},
44+
'dns_sd_configs' => [{
45+
'names' => $tarmak::etcd_cluster_exporters,
5046
}],
5147
'relabel_configs' => [{
5248
'source_labels' => [],
@@ -62,9 +58,8 @@
6258
config => {
6359
'metrics_path' => '/probe',
6460
'params' => { 'module' => ['etcd_overlay_proxy'] },
65-
'static_configs' => [{
66-
'targets' => $blackbox_exporters,
67-
'labels' => {'role' => 'etcd'},
61+
'dns_sd_configs' => [{
62+
'names' => $tarmak::etcd_cluster_exporters,
6863
}],
6964
'relabel_configs' => [{
7065
'source_labels' => [],

puppet/modules/prometheus/manifests/init.pp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,29 @@
22
String $systemd_path = '/etc/systemd/system',
33
String $namespace = 'monitoring',
44
Optional[Enum['etcd','master','worker']] $role = $::prometheus::params::role,
5-
$etcd_cluster = $::prometheus::params::etcd_cluster,
5+
$etcd_cluster_exporters = $::prometheus::params::etcd_cluster_exporters,
66
Integer[1025,65535] $etcd_k8s_main_port = $::prometheus::params::etcd_k8s_main_port,
77
Integer[1025,65535] $etcd_k8s_events_port = $::prometheus::params::etcd_k8s_events_port,
88
Integer[1024,65535] $etcd_overlay_port = $::prometheus::params::etcd_overlay_port,
9-
Boolean $external_scrape_targets_only = false,
9+
String $mode = 'Full',
1010
) inherits ::prometheus::params
1111
{
1212

1313
if $role == 'master' {
14-
include ::prometheus::server
15-
include ::prometheus::blackbox_exporter_etcd
16-
include ::prometheus::node_exporter
17-
if ! $external_scrape_targets_only {
14+
if $mode == 'Full' {
15+
include ::prometheus::server
16+
include ::prometheus::blackbox_exporter_etcd
17+
include ::prometheus::node_exporter
18+
1819
include ::prometheus::kube_state_metrics
1920
include ::prometheus::blackbox_exporter
2021
}
22+
23+
if $mode == 'ExternalScrapeTargetsOnly' {
24+
include ::prometheus::server
25+
include ::prometheus::blackbox_exporter_etcd
26+
include ::prometheus::node_exporter
27+
}
2128
}
2229

2330
if $role == 'etcd' {

puppet/modules/prometheus/manifests/node_exporter.pp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,16 @@
5757

5858

5959
# scrape node exporter running on etcd nodes
60-
$etcd_node_exporters = $::prometheus::etcd_cluster.map |$node| { "${node}:${port}" }
6160
prometheus::scrape_config { 'etcd-nodes-exporter':
6261
order => 135,
6362
config => {
64-
'static_configs' => [{
65-
'targets' => $etcd_node_exporters,
66-
'labels' => {'role' => 'etcd'},
63+
'dns_sd_configs' => [{
64+
'names' => $tarmak::etcd_cluster_exporters,
6765
}],
6866
}
6967
}
7068

71-
$external_scrape_targets_only = $::prometheus::external_scrape_targets_only
72-
if ! $external_scrape_targets_only {
69+
if $::prometheus::mode == 'Full' {
7370
kubernetes::apply{'node-exporter':
7471
manifests => [
7572
template('prometheus/prometheus-ns.yaml.erb'),

0 commit comments

Comments
 (0)