-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from utilitywarehouse/as-upgrade
update go and added test
- Loading branch information
Showing
13 changed files
with
357 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/prometheus/client_golang/prometheus" | ||
_ "k8s.io/client-go/plugin/pkg/client/auth" | ||
stats "k8s.io/kubelet/pkg/apis/stats/v1alpha1" | ||
) | ||
|
||
func Test_collectSummaryMetrics(t *testing.T) { | ||
expectedOut := `# HELP kube_summary_container_logs_available_bytes Number of bytes that aren't consumed by the container logs | ||
# TYPE kube_summary_container_logs_available_bytes gauge | ||
kube_summary_container_logs_available_bytes{name="dev-server",namespace="mon",pod="dev-server-0"} 9.0016837632e+10 | ||
# HELP kube_summary_container_logs_capacity_bytes Number of bytes that can be consumed by the container logs | ||
# TYPE kube_summary_container_logs_capacity_bytes gauge | ||
kube_summary_container_logs_capacity_bytes{name="dev-server",namespace="mon",pod="dev-server-0"} 1.01535985664e+11 | ||
# HELP kube_summary_container_logs_inodes Number of Inodes for logs | ||
# TYPE kube_summary_container_logs_inodes gauge | ||
kube_summary_container_logs_inodes{name="dev-server",namespace="mon",pod="dev-server-0"} 2.5474432e+07 | ||
# HELP kube_summary_container_logs_inodes_free Number of available Inodes for logs | ||
# TYPE kube_summary_container_logs_inodes_free gauge | ||
kube_summary_container_logs_inodes_free{name="dev-server",namespace="mon",pod="dev-server-0"} 2.5355212e+07 | ||
# HELP kube_summary_container_logs_inodes_used Number of used Inodes for logs | ||
# TYPE kube_summary_container_logs_inodes_used gauge | ||
kube_summary_container_logs_inodes_used{name="dev-server",namespace="mon",pod="dev-server-0"} 1 | ||
# HELP kube_summary_container_logs_used_bytes Number of bytes that are consumed by the container logs | ||
# TYPE kube_summary_container_logs_used_bytes gauge | ||
kube_summary_container_logs_used_bytes{name="dev-server",namespace="mon",pod="dev-server-0"} 8192 | ||
# HELP kube_summary_container_rootfs_available_bytes Number of bytes that aren't consumed by the container | ||
# TYPE kube_summary_container_rootfs_available_bytes gauge | ||
kube_summary_container_rootfs_available_bytes{name="dev-server",namespace="mon",pod="dev-server-0"} 9.0016837632e+10 | ||
# HELP kube_summary_container_rootfs_capacity_bytes Number of bytes that can be consumed by the container | ||
# TYPE kube_summary_container_rootfs_capacity_bytes gauge | ||
kube_summary_container_rootfs_capacity_bytes{name="dev-server",namespace="mon",pod="dev-server-0"} 1.01535985664e+11 | ||
# HELP kube_summary_container_rootfs_inodes Number of Inodes | ||
# TYPE kube_summary_container_rootfs_inodes gauge | ||
kube_summary_container_rootfs_inodes{name="dev-server",namespace="mon",pod="dev-server-0"} 2.5474432e+07 | ||
# HELP kube_summary_container_rootfs_inodes_free Number of available Inodes | ||
# TYPE kube_summary_container_rootfs_inodes_free gauge | ||
kube_summary_container_rootfs_inodes_free{name="dev-server",namespace="mon",pod="dev-server-0"} 2.5355212e+07 | ||
# HELP kube_summary_container_rootfs_inodes_used Number of used Inodes | ||
# TYPE kube_summary_container_rootfs_inodes_used gauge | ||
kube_summary_container_rootfs_inodes_used{name="dev-server",namespace="mon",pod="dev-server-0"} 14 | ||
# HELP kube_summary_container_rootfs_used_bytes Number of bytes that are consumed by the container | ||
# TYPE kube_summary_container_rootfs_used_bytes gauge | ||
kube_summary_container_rootfs_used_bytes{name="dev-server",namespace="mon",pod="dev-server-0"} 114688 | ||
# HELP kube_summary_pod_ephemeral_storage_available_bytes Number of bytes of Ephemeral storage that aren't consumed by the pod | ||
# TYPE kube_summary_pod_ephemeral_storage_available_bytes gauge | ||
kube_summary_pod_ephemeral_storage_available_bytes{namespace="mon",pod="dev-server-0"} 9.0016837632e+10 | ||
# HELP kube_summary_pod_ephemeral_storage_capacity_bytes Number of bytes of Ephemeral storage that can be consumed by the pod | ||
# TYPE kube_summary_pod_ephemeral_storage_capacity_bytes gauge | ||
kube_summary_pod_ephemeral_storage_capacity_bytes{namespace="mon",pod="dev-server-0"} 1.01535985664e+11 | ||
# HELP kube_summary_pod_ephemeral_storage_inodes Number of Inodes for pod Ephemeral storage | ||
# TYPE kube_summary_pod_ephemeral_storage_inodes gauge | ||
kube_summary_pod_ephemeral_storage_inodes{namespace="mon",pod="dev-server-0"} 2.5474432e+07 | ||
# HELP kube_summary_pod_ephemeral_storage_inodes_free Number of available Inodes for pod Ephemeral storage | ||
# TYPE kube_summary_pod_ephemeral_storage_inodes_free gauge | ||
kube_summary_pod_ephemeral_storage_inodes_free{namespace="mon",pod="dev-server-0"} 2.5355212e+07 | ||
# HELP kube_summary_pod_ephemeral_storage_inodes_used Number of used Inodes for pod Ephemeral storage | ||
# TYPE kube_summary_pod_ephemeral_storage_inodes_used gauge | ||
kube_summary_pod_ephemeral_storage_inodes_used{namespace="mon",pod="dev-server-0"} 63 | ||
# HELP kube_summary_pod_ephemeral_storage_used_bytes Number of bytes of Ephemeral storage that are consumed by the pod | ||
# TYPE kube_summary_pod_ephemeral_storage_used_bytes gauge | ||
kube_summary_pod_ephemeral_storage_used_bytes{namespace="mon",pod="dev-server-0"} 1.33947392e+08 | ||
` | ||
|
||
d, err := os.ReadFile("test-summary.json") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
var summary stats.Summary | ||
registry := prometheus.NewRegistry() | ||
|
||
err = json.Unmarshal(d, &summary) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
collectSummaryMetrics(&summary, registry) | ||
|
||
tmpfile, err := os.CreateTemp("", "test-summary.prom") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer os.Remove(tmpfile.Name()) | ||
|
||
if err := prometheus.WriteToTextfile(tmpfile.Name(), registry); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
fileBytes, err := os.ReadFile(tmpfile.Name()) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if diff := cmp.Diff(string(fileBytes), expectedOut); diff != "" { | ||
t.Errorf("collectSummaryMetrics() metrics mismatch (-want +got):\n%s", diff) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: kube-summary-exporter | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
labels: | ||
name: kube-summary-exporter | ||
name: kube-summary-exporter | ||
spec: | ||
ports: | ||
- name: kube-summary-exporter | ||
protocol: TCP | ||
port: 9779 | ||
targetPort: 9779 | ||
selector: | ||
app: kube-summary-exporter | ||
--- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: kube-summary-exporter | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: kube-summary-exporter | ||
template: | ||
metadata: | ||
name: kube-summary-exporter | ||
labels: | ||
app: kube-summary-exporter | ||
spec: | ||
serviceAccountName: kube-summary-exporter | ||
containers: | ||
- name: kube-summary-exporter | ||
image: quay.io/utilitywarehouse/kube-summary-exporter:latest | ||
ports: | ||
- name: tcp | ||
containerPort: 9779 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
apiVersion: kustomize.config.k8s.io/v1beta1 | ||
kind: Kustomization | ||
resources: | ||
- deployment.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
name: kube-summary-exporter | ||
rules: | ||
- apiGroups: [""] | ||
resources: ["nodes/proxy"] | ||
verbs: ["get"] | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: kube-summary-exporter | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: ClusterRole | ||
name: kube-summary-exporter | ||
subjects: | ||
- kind: ServiceAccount | ||
name: kube-summary-exporter | ||
namespace: sys-prom |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
apiVersion: kustomize.config.k8s.io/v1beta1 | ||
kind: Kustomization | ||
resources: | ||
- clusterrole.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Scrape config for the Summary API exporter. | ||
# This assumes that the exporter is available at kube-summary-exporter:9779 | ||
- job_name: "kubernetes-summary" | ||
kubernetes_sd_configs: | ||
- role: node | ||
relabel_configs: | ||
- action: labelmap | ||
regex: __meta_kubernetes_node_label_(.+) | ||
- source_labels: [__meta_kubernetes_node_name] | ||
regex: (.+) | ||
target_label: __metrics_path__ | ||
replacement: /node/${1} | ||
- target_label: __address__ | ||
replacement: kube-summary-exporter:9779 |
Oops, something went wrong.