Skip to content

Commit

Permalink
Included paths for prometheus collection targets
Browse files Browse the repository at this point in the history
  • Loading branch information
nikola-jokic committed Jun 12, 2023
1 parent cbe0554 commit 077008e
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 3 deletions.
1 change: 1 addition & 0 deletions pkg/kwokctl/runtime/binary/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ func (c *Cluster) Install(ctx context.Context) error {
KubeControllerManagerPort: conf.KubeControllerManagerPort,
KubeSchedulerPort: conf.KubeSchedulerPort,
KwokControllerPort: conf.KwokControllerPort,
Metrics: runtime.GetMetrics(ctx),
})
if err != nil {
return fmt.Errorf("failed to generate prometheus yaml: %w", err)
Expand Down
3 changes: 3 additions & 0 deletions pkg/kwokctl/runtime/binary/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"fmt"
"text/template"

"sigs.k8s.io/kwok/pkg/apis/internalversion"

_ "embed"
)

Expand Down Expand Up @@ -51,4 +53,5 @@ type BuildPrometheusConfig struct {
KubeControllerManagerPort uint32
KubeSchedulerPort uint32
KwokControllerPort uint32
Metrics []*internalversion.Metric
}
13 changes: 12 additions & 1 deletion pkg/kwokctl/runtime/binary/prometheus.yaml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,18 @@ scrape_configs:
static_configs:
- targets:
- localhost:{{ .KwokControllerPort }}

{{ $kwokControllerPort := .KwokControllerPort }}
{{ range .Metrics }}
- job_name: "kwok-metric-{{ .Name }}"
scheme: http
honor_timestamps: true
metrics_path: {{ .Spec.Path }}
follow_redirects: true
enable_http2: true
static_configs:
- targets:
- localhost:{{ $kwokControllerPort }}
{{ end }}
{{ if .SecurePort }}
- job_name: "kube-apiserver"
scheme: https
Expand Down
3 changes: 2 additions & 1 deletion pkg/kwokctl/runtime/compose/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ func (c *Cluster) Install(ctx context.Context) error {
SecurePort: conf.SecurePort,
AdminCrtPath: inClusterAdminCertPath,
AdminKeyPath: inClusterAdminKeyPath,
Metrics: runtime.GetMetrics(ctx),
})
if err != nil {
return fmt.Errorf("failed to generate prometheus yaml: %w", err)
Expand Down Expand Up @@ -483,7 +484,7 @@ func (c *Cluster) Install(ctx context.Context) error {
return err
}

err = os.WriteFile(inClusterOnHostKubeconfigPath, inClusterKubeconfigData, 0640)
err = os.WriteFile(inClusterOnHostKubeconfigPath, []byte(inClusterKubeconfigData), 0640)
if err != nil {
return err
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/kwokctl/runtime/compose/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"fmt"
"text/template"

"sigs.k8s.io/kwok/pkg/apis/internalversion"

_ "embed"
)

Expand All @@ -45,4 +47,5 @@ type BuildPrometheusConfig struct {
SecurePort bool
AdminCrtPath string
AdminKeyPath string
Metrics []*internalversion.Metric
}
12 changes: 12 additions & 0 deletions pkg/kwokctl/runtime/compose/prometheus.yaml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ scrape_configs:
- targets:
- "{{ .ProjectName }}-kwok-controller:10247"

{{ $projectName := .ProjectName }}
{{ range .Metrics }}
- job_name: "kwok-metric-{{ .Name }}"
scheme: http
honor_timestamps: true
metrics_path: {{ .Spec.Path }}
follow_redirects: true
enable_http2: true
static_configs:
- targets:
- "{{ $projectName }}-kwok-controller:10247"
{{ end }}
{{ if .SecurePort }}
- job_name: "kube-apiserver"
scheme: https
Expand Down
1 change: 1 addition & 0 deletions pkg/kwokctl/runtime/kind/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ func (c *Cluster) Install(ctx context.Context) error {
Name: c.Name(),
ExtraArgs: prometheusPatches.ExtraArgs,
ExtraVolumes: prometheusPatches.ExtraVolumes,
Metrics: runtime.GetMetrics(ctx),
}
if verbosity != log.LevelInfo {
prometheusConf.LogLevel = log.ToLogSeverityLevel(verbosity)
Expand Down
1 change: 1 addition & 0 deletions pkg/kwokctl/runtime/kind/prometheus_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@ type BuildPrometheusDeploymentConfig struct {
LogLevel string
ExtraArgs []internalversion.ExtraArgs
ExtraVolumes []internalversion.Volume
Metrics []*internalversion.Metric
}
11 changes: 11 additions & 0 deletions pkg/kwokctl/runtime/kind/prometheus_deployment.yaml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ data:
static_configs:
- targets:
- "localhost:10247"
{{ range .Metrics }}
- job_name: "kwok-metric-{{ .Name }}"
scheme: http
honor_timestamps: true
metrics_path: {{ .Spec.Path }}
follow_redirects: true
enable_http2: true
static_configs:
- targets:
- "localhost:10247"
{{ end }}
- job_name: "kube-apiserver"
scheme: https
honor_timestamps: true
Expand Down
5 changes: 5 additions & 0 deletions pkg/kwokctl/runtime/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,8 @@ func GetLogVolumes(ctx context.Context) []internalversion.Volume {
}
return volumes
}

// GetMetrics returns metrics for Metrics resource.
func GetMetrics(ctx context.Context) []*internalversion.Metric {
return config.FilterWithTypeFromContext[*internalversion.Metric](ctx)
}
2 changes: 1 addition & 1 deletion test/kwokctl/kwokctl_metric_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function test_apply_node_and_pod() {
echo "Error: fake-deployment apply failed"
return 1
fi
if ! kwokctl --name "${name}" kubectl wait pod -A --all --for=condition=Ready --timeout=12s; then
if ! kwokctl --name "${name}" kubectl wait pod -A --all --for=condition=Ready --timeout=60s; then
echo "Error: fake-pod wait failed"
echo kwokctl --name "${name}" kubectl get pod -A --all
kwokctl --name "${name}" kubectl get pod -A --all
Expand Down

0 comments on commit 077008e

Please sign in to comment.