From dcf9306248a9fc219466157d5d02c83996de5880 Mon Sep 17 00:00:00 2001 From: liyuqi Date: Tue, 13 Sep 2022 15:01:24 +0800 Subject: [PATCH 1/7] add_telemetry --- docs/guide/install.md | 3 + docs/guide/telemetry.md | 35 +++++++ pkg/k8s/crd/Dockerfile | 1 + .../default/manager_auth_proxy_patch.yaml | 1 + pkg/k8s/crd/config/manager/manager.yaml | 1 + pkg/k8s/crd/install/config_default.yaml | 14 +++ pkg/k8s/crd/install/shifu_install.yml | 14 +++ pkg/k8s/crd/main.go | 10 +- pkg/k8s/crd/telemetry/telemetry.go | 99 +++++++++++++++++++ pkg/k8s/crd/telemetry/types/types.go | 17 ++++ pkg/k8s/crd/telemetry/utils/utils.go | 70 +++++++++++++ 11 files changed, 264 insertions(+), 1 deletion(-) create mode 100644 docs/guide/telemetry.md create mode 100644 pkg/k8s/crd/telemetry/telemetry.go create mode 100644 pkg/k8s/crd/telemetry/types/types.go create mode 100644 pkg/k8s/crd/telemetry/utils/utils.go diff --git a/docs/guide/install.md b/docs/guide/install.md index d0c58df9e..3dc7f0b37 100644 --- a/docs/guide/install.md +++ b/docs/guide/install.md @@ -16,3 +16,6 @@ ``` kubectl delete -f pkg/k8s/crd/install/shifu_install.yml ``` + +### About Telemetry +if you want to close telemetry [click me!](telemetry.md) \ No newline at end of file diff --git a/docs/guide/telemetry.md b/docs/guide/telemetry.md new file mode 100644 index 000000000..bf09f0cd4 --- /dev/null +++ b/docs/guide/telemetry.md @@ -0,0 +1,35 @@ +# Telemetry + +Telemetry is enabled by default when you install Shifu, while you also have the option to disable it either before or after the installation. + +## Data we collect + +- External network IP +- Download date +- Kubernetes version +- Shifu version +- Kubernetes cluster size +- Kubernetes Pod Name +- Kubernetes Deployment Name +- The type of the operating system + +## To turn-off Telemetry + +If you want to turn off temeletry, please delete `--enable-telemetry` on `pkg/k8s/crd/install/shifu_install.yaml` manually. + +```yaml +apiVersion: apps/v1 +kind: Deployment +spec: + replicas: 1 + selector: + matchLabels: + control-plane: controller-manager + template: + spec: + containers: + image: quay.io/brancz/kube-rbac-proxy:v0.12.0 + name: kube-rbac-proxy + - args: + - --enable-telemetry ## delete on demand +``` diff --git a/pkg/k8s/crd/Dockerfile b/pkg/k8s/crd/Dockerfile index c89aee6a3..3eaa49d84 100644 --- a/pkg/k8s/crd/Dockerfile +++ b/pkg/k8s/crd/Dockerfile @@ -14,6 +14,7 @@ RUN go mod download # Copy the go source COPY pkg/k8s/crd/main.go main.go +COPY pkg/k8s/crd/telemetry pkg/k8s/crd/telemetry COPY pkg/k8s/api pkg/k8s/api COPY pkg/k8s/controllers pkg/k8s/controllers diff --git a/pkg/k8s/crd/config/default/manager_auth_proxy_patch.yaml b/pkg/k8s/crd/config/default/manager_auth_proxy_patch.yaml index b51bb1ada..ba2092df5 100644 --- a/pkg/k8s/crd/config/default/manager_auth_proxy_patch.yaml +++ b/pkg/k8s/crd/config/default/manager_auth_proxy_patch.yaml @@ -24,3 +24,4 @@ spec: - "--health-probe-bind-address=:8081" - "--metrics-bind-address=127.0.0.1:8080" - "--leader-elect" + - "--enable-telemetry" \ No newline at end of file diff --git a/pkg/k8s/crd/config/manager/manager.yaml b/pkg/k8s/crd/config/manager/manager.yaml index 79adfe72a..a008590fe 100644 --- a/pkg/k8s/crd/config/manager/manager.yaml +++ b/pkg/k8s/crd/config/manager/manager.yaml @@ -29,6 +29,7 @@ spec: - /manager args: - --leader-elect + - --enable-telemetry image: controller:latest name: manager securityContext: diff --git a/pkg/k8s/crd/install/config_default.yaml b/pkg/k8s/crd/install/config_default.yaml index aaa46a29e..7885c48cf 100644 --- a/pkg/k8s/crd/install/config_default.yaml +++ b/pkg/k8s/crd/install/config_default.yaml @@ -434,6 +434,7 @@ spec: - --health-probe-bind-address=:8081 - --metrics-bind-address=127.0.0.1:8080 - --leader-elect + - --enable-telemetry command: - /manager image: edgehub/shifu-controller:v0.1.0 @@ -463,3 +464,16 @@ spec: runAsNonRoot: true serviceAccountName: shifu-crd-controller-manager terminationGracePeriodSeconds: 10 +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: default-view +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: view +subjects: +- kind: ServiceAccount + name: shifu-crd-controller-manager + namespace: shifu-crd-system \ No newline at end of file diff --git a/pkg/k8s/crd/install/shifu_install.yml b/pkg/k8s/crd/install/shifu_install.yml index 6caf12de2..7af39eafe 100644 --- a/pkg/k8s/crd/install/shifu_install.yml +++ b/pkg/k8s/crd/install/shifu_install.yml @@ -434,6 +434,7 @@ spec: - --health-probe-bind-address=:8081 - --metrics-bind-address=127.0.0.1:8080 - --leader-elect + - --enable-telemetry command: - /manager image: edgehub/shifu-controller:v0.1.0 @@ -527,3 +528,16 @@ subjects: - kind: ServiceAccount name: edgedevice-sa namespace: deviceshifu +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: default-view +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: view +subjects: +- kind: ServiceAccount + name: shifu-crd-controller-manager + namespace: shifu-crd-system \ No newline at end of file diff --git a/pkg/k8s/crd/main.go b/pkg/k8s/crd/main.go index 2bc2dd953..8624adb08 100644 --- a/pkg/k8s/crd/main.go +++ b/pkg/k8s/crd/main.go @@ -18,9 +18,11 @@ package main import ( "flag" + "os" + "github.com/edgenesis/shifu/pkg/k8s/api/v1alpha1" "github.com/edgenesis/shifu/pkg/k8s/controllers" - "os" + "github.com/edgenesis/shifu/pkg/k8s/crd/telemetry" // Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.) // to ensure that exec-entrypoint and run can make use of them. @@ -50,18 +52,24 @@ func init() { func main() { var metricsAddr string var enableLeaderElection bool + var enableTelemetry bool var probeAddr string flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.") flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.") flag.BoolVar(&enableLeaderElection, "leader-elect", false, "Enable leader election for controller manager. "+ "Enabling this will ensure there is only one active controller manager.") + flag.BoolVar(&enableTelemetry, "enable-telemetry", false, "collection user info and send to server") opts := zap.Options{ Development: true, } opts.BindFlags(flag.CommandLine) flag.Parse() + if enableTelemetry { + go telemetry.StartTelemetry() + } + ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts))) mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{ diff --git a/pkg/k8s/crd/telemetry/telemetry.go b/pkg/k8s/crd/telemetry/telemetry.go new file mode 100644 index 000000000..94b6504b7 --- /dev/null +++ b/pkg/k8s/crd/telemetry/telemetry.go @@ -0,0 +1,99 @@ +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Note: the example only works with the code within the same release/branch. +package telemetry + +import ( + "context" + "log" + "time" + + "github.com/edgenesis/shifu/pkg/k8s/crd/telemetry/types" + "github.com/edgenesis/shifu/pkg/k8s/crd/telemetry/utils" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/client-go/kubernetes" + "k8s.io/client-go/rest" +) + +func StartTelemetry() { + for { + publicIP, err := utils.GetPublicIPAddr(utils.URL_EXTERNAL_IP) + if err != nil { + log.Printf("issue getting Public IP") + publicIP = utils.URL_DEFAULT_PUBLIC_IP + } + + log.Printf("Public IP is %v\n", publicIP) + config, err := rest.InClusterConfig() + if err != nil { + panic(err.Error()) + } + + clientset, err := kubernetes.NewForConfig(config) + if err != nil { + panic(err.Error()) + } + + kVersion, err := clientset.ServerVersion() + if err != nil { + panic(err.Error()) + } + log.Printf("%#v", kVersion) + pods, err := clientset.CoreV1().Pods("").List(context.TODO(), metav1.ListOptions{}) + if err != nil { + panic(err.Error()) + } + + deploy, err := clientset.AppsV1().Deployments("").List(context.TODO(), metav1.ListOptions{}) + if err != nil { + panic(err.Error()) + } + + podList := make([]string, len(pods.Items)) + deploymentList := make([]string, len(deploy.Items)) + for index, item := range pods.Items { + podList[index] = item.Name + } + + for index, item := range deploy.Items { + deploymentList[index] = item.Name + } + + clusterInfoTelemetry := types.ClusterInfo{ + NumPods: len(podList), + NumDeployments: len(deploymentList), + Pods: podList, + Deployments: deploymentList, + KubernetesVersion: kVersion.GitVersion, + Platform: kVersion.Platform, + } + + controllerTelemetry := types.TelemetryResponse{ + IP: publicIP, + Source: utils.SOURCE_SHIFU_CONTROLLER, + Task: utils.TASK_RUN_DEMO_KIND, + ClusterInfo: clusterInfoTelemetry, + } + + if result := utils.SendTelemetry(controllerTelemetry); result == nil { + log.Println("telemetry done") + } + + time.Sleep(60 * time.Second) + } +} diff --git a/pkg/k8s/crd/telemetry/types/types.go b/pkg/k8s/crd/telemetry/types/types.go new file mode 100644 index 000000000..f817e3330 --- /dev/null +++ b/pkg/k8s/crd/telemetry/types/types.go @@ -0,0 +1,17 @@ +package types + +type TelemetryResponse struct { + IP string `json:"ip"` + Source string `json:"source"` + Task string `json:"task"` + ClusterInfo ClusterInfo `json:"cluster_info"` +} + +type ClusterInfo struct { + KubernetesVersion string `json:"kubernetesVersion"` + Platform string `json:"platform"` + NumPods int `json:"num_pods"` + NumDeployments int `json:"num_deployments"` + Pods []string `json:"pods"` + Deployments []string `json:"deployments"` +} diff --git a/pkg/k8s/crd/telemetry/utils/utils.go b/pkg/k8s/crd/telemetry/utils/utils.go new file mode 100644 index 000000000..7266edef3 --- /dev/null +++ b/pkg/k8s/crd/telemetry/utils/utils.go @@ -0,0 +1,70 @@ +package utils + +import ( + "bufio" + "bytes" + "encoding/json" + "errors" + "fmt" + "io" + "log" + "net/http" + "strings" +) + +const ( + URL_EXTERNAL_IP = "http://cip.cc" + URL_IP_LINE = "
IP"
+	URL_SHIFU_TELEMETRY              = "https://telemetry.shifu.run/shifu-telemetry/"
+	URL_DEFAULT_PUBLIC_IP            = "0.0.0.0"
+	NAMESPACE_SHIFU_CRD_SYSTEM       = "shifu-crd-system"
+	DEPLOYMENTS_SHIFU_CRD_CONTROLLER = "shifu-crd-controller-manager"
+	TASK_RUN_DEMO_KIND               = "run_shifu_release"
+	STEP_CONTROLLER_READY            = "shifu_controller_ready"
+	SOURCE_SHIFU_CONTROLLER          = "shifu_controller"
+	HTTP_CONTENT_TYPE_JSON           = "application/json"
+)
+
+func GetPublicIPAddr(url string) (string, error) {
+	resp, err := http.Get(url)
+	if err != nil {
+		return "", fmt.Errorf("error getting public IP")
+	}
+
+	defer resp.Body.Close()
+	if resp.StatusCode == http.StatusOK {
+		bodyBytes, err := io.ReadAll(resp.Body)
+		if err != nil {
+			log.Printf("Error getting response of IP query")
+			return "", err
+		}
+
+		responseText := string(bodyBytes)
+		scanner := bufio.NewScanner(strings.NewReader(responseText))
+		for scanner.Scan() {
+			if strings.Contains(scanner.Text(), URL_IP_LINE) {
+				ipString := strings.Split(scanner.Text(), ": ")
+				return ipString[len(ipString)-1], nil
+			}
+		}
+
+	}
+	return "", errors.New("Did not find IP in return query")
+}
+
+func SendTelemetry(telemetry interface{}) error {
+	postBodyJson, err := json.Marshal(telemetry)
+	if err != nil {
+		log.Printf("Error sending telemetry")
+		return err
+	}
+
+	resp, err := http.Post(URL_SHIFU_TELEMETRY, HTTP_CONTENT_TYPE_JSON, bytes.NewBuffer(postBodyJson))
+	if err != nil {
+		log.Println("error posting telemetry, errors: ", err)
+		return err
+	}
+
+	defer resp.Body.Close()
+	return nil
+}

From d03259cc18852ae9df2876bde94ab9571477e0ce Mon Sep 17 00:00:00 2001
From: liyuqi 
Date: Tue, 13 Sep 2022 15:41:35 +0800
Subject: [PATCH 2/7] tiny fix

---
 pkg/k8s/crd/main.go                  |  2 +-
 pkg/k8s/crd/telemetry/telemetry.go   | 34 +++++++++-------------------
 pkg/k8s/crd/telemetry/utils/utils.go | 18 +++++++--------
 3 files changed, 20 insertions(+), 34 deletions(-)

diff --git a/pkg/k8s/crd/main.go b/pkg/k8s/crd/main.go
index 8624adb08..d4048afe9 100644
--- a/pkg/k8s/crd/main.go
+++ b/pkg/k8s/crd/main.go
@@ -59,7 +59,7 @@ func main() {
 	flag.BoolVar(&enableLeaderElection, "leader-elect", false,
 		"Enable leader election for controller manager. "+
 			"Enabling this will ensure there is only one active controller manager.")
-	flag.BoolVar(&enableTelemetry, "enable-telemetry", false, "collection user info and send to server")
+	flag.BoolVar(&enableTelemetry, "enable-telemetry", false, "collection telemetry")
 	opts := zap.Options{
 		Development: true,
 	}
diff --git a/pkg/k8s/crd/telemetry/telemetry.go b/pkg/k8s/crd/telemetry/telemetry.go
index 94b6504b7..533a7a161 100644
--- a/pkg/k8s/crd/telemetry/telemetry.go
+++ b/pkg/k8s/crd/telemetry/telemetry.go
@@ -1,20 +1,3 @@
-/*
-Copyright 2016 The Kubernetes Authors.
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-
-// Note: the example only works with the code within the same release/branch.
 package telemetry
 
 import (
@@ -41,27 +24,32 @@ func StartTelemetry() {
 		log.Printf("Public IP is %v\n", publicIP)
 		config, err := rest.InClusterConfig()
 		if err != nil {
-			panic(err.Error())
+			log.Println("error when get cluster Config,error: ", err)
+			continue
 		}
 
 		clientset, err := kubernetes.NewForConfig(config)
 		if err != nil {
-			panic(err.Error())
+			log.Println("cannot get ClusterInfo,errors: ", err)
+			continue
 		}
 
 		kVersion, err := clientset.ServerVersion()
 		if err != nil {
-			panic(err.Error())
+			log.Println("cannot get Kubernetes Server Info,errors: ", err)
+			continue
 		}
 		log.Printf("%#v", kVersion)
 		pods, err := clientset.CoreV1().Pods("").List(context.TODO(), metav1.ListOptions{})
 		if err != nil {
-			panic(err.Error())
+			log.Println("cannot get Pod Info,errors: ", err)
+			continue
 		}
 
 		deploy, err := clientset.AppsV1().Deployments("").List(context.TODO(), metav1.ListOptions{})
 		if err != nil {
-			panic(err.Error())
+			log.Println("cannot get Deployment Info,errors: ", err)
+			continue
 		}
 
 		podList := make([]string, len(pods.Items))
@@ -94,6 +82,6 @@ func StartTelemetry() {
 			log.Println("telemetry done")
 		}
 
-		time.Sleep(60 * time.Second)
+		time.Sleep(utils.TELEMETRY_INTERVAL_IN_SECOND * time.Second)
 	}
 }
diff --git a/pkg/k8s/crd/telemetry/utils/utils.go b/pkg/k8s/crd/telemetry/utils/utils.go
index 7266edef3..abea53305 100644
--- a/pkg/k8s/crd/telemetry/utils/utils.go
+++ b/pkg/k8s/crd/telemetry/utils/utils.go
@@ -13,16 +13,14 @@ import (
 )
 
 const (
-	URL_EXTERNAL_IP                  = "http://cip.cc"
-	URL_IP_LINE                      = "
IP"
-	URL_SHIFU_TELEMETRY              = "https://telemetry.shifu.run/shifu-telemetry/"
-	URL_DEFAULT_PUBLIC_IP            = "0.0.0.0"
-	NAMESPACE_SHIFU_CRD_SYSTEM       = "shifu-crd-system"
-	DEPLOYMENTS_SHIFU_CRD_CONTROLLER = "shifu-crd-controller-manager"
-	TASK_RUN_DEMO_KIND               = "run_shifu_release"
-	STEP_CONTROLLER_READY            = "shifu_controller_ready"
-	SOURCE_SHIFU_CONTROLLER          = "shifu_controller"
-	HTTP_CONTENT_TYPE_JSON           = "application/json"
+	URL_EXTERNAL_IP              = "http://cip.cc"
+	URL_IP_LINE                  = "
IP"
+	URL_SHIFU_TELEMETRY          = "https://telemetry.shifu.run/shifu-telemetry/"
+	URL_DEFAULT_PUBLIC_IP        = "0.0.0.0"
+	TASK_RUN_DEMO_KIND           = "run_shifu_release"
+	SOURCE_SHIFU_CONTROLLER      = "shifu_controller"
+	HTTP_CONTENT_TYPE_JSON       = "application/json"
+	TELEMETRY_INTERVAL_IN_SECOND = 60
 )
 
 func GetPublicIPAddr(url string) (string, error) {

From 657b8a2e057d786fd411d698a29f7515154aed30 Mon Sep 17 00:00:00 2001
From: liyuqi 
Date: Tue, 13 Sep 2022 16:11:04 +0800
Subject: [PATCH 3/7] fix doc

---
 docs/guide/install-zh.md             |  5 +++-
 docs/guide/install.md                |  2 +-
 docs/guide/telemetry-zh.md           | 36 ++++++++++++++++++++++++++++
 docs/guide/telemetry.md              |  1 +
 pkg/k8s/crd/main.go                  |  2 +-
 pkg/k8s/crd/telemetry/utils/utils.go |  6 +++--
 6 files changed, 47 insertions(+), 5 deletions(-)
 create mode 100644 docs/guide/telemetry-zh.md

diff --git a/docs/guide/install-zh.md b/docs/guide/install-zh.md
index 4b3843eee..e66c80cd3 100644
--- a/docs/guide/install-zh.md
+++ b/docs/guide/install-zh.md
@@ -15,4 +15,7 @@
 1. 执行卸载命令:
    ``` 
    kubectl delete -f pkg/k8s/crd/install/shifu_install.yml
-   ```
\ No newline at end of file
+   ```
+
+### 关于遥测
+要了解更多信息,包括如何禁用内置遥测,请在[此处](telemetry.md)查看我们的指南
\ No newline at end of file
diff --git a/docs/guide/install.md b/docs/guide/install.md
index 3dc7f0b37..0346acdad 100644
--- a/docs/guide/install.md
+++ b/docs/guide/install.md
@@ -18,4 +18,4 @@
    ```
 
 ### About Telemetry
-if you want to close telemetry [click me!](telemetry.md)
\ No newline at end of file
+To learn more including how to disable the built-in telemetry, checkout out our guide [here!](telemetry.md)
\ No newline at end of file
diff --git a/docs/guide/telemetry-zh.md b/docs/guide/telemetry-zh.md
new file mode 100644
index 000000000..ce91430b3
--- /dev/null
+++ b/docs/guide/telemetry-zh.md
@@ -0,0 +1,36 @@
+# 遥测
+
+安装 Shifu 时默认启用遥测,您可以在安装之前或之后禁用它。
+
+## 我们收集的数据
+
+- 外网IP
+- 下载日期
+- Kubernetes 版本
+- Shifu 版本
+- Kubernetes 集群规模
+- Kubernetes Pod 名称
+- Kubernetes Deployment 名称
+- 操作系统的类型
+
+## 关闭遥测
+
+如果要关闭 telemetry,请手动删除 `pkg/k8s/crd/install/shifu_install.yaml` 上的 `--enable-telemetry`。
+或者您也可以在安装后通过 `kubectl edit deployment -n shifu-crd-system shifu-crd-controller-manager` 进行编辑
+
+```yaml
+apiVersion: apps/v1
+kind: Deployment
+spec:
+  replicas: 1
+  selector:
+    matchLabels:
+      control-plane: controller-manager
+  template:
+    spec:
+      containers:
+      image: quay.io/brancz/kube-rbac-proxy:v0.12.0
+      name: kube-rbac-proxy
+      - args:
+        - --enable-telemetry ## delete on demand
+```
\ No newline at end of file
diff --git a/docs/guide/telemetry.md b/docs/guide/telemetry.md
index bf09f0cd4..ae2c94c55 100644
--- a/docs/guide/telemetry.md
+++ b/docs/guide/telemetry.md
@@ -16,6 +16,7 @@ Telemetry is enabled by default when you install Shifu, while you also have the
 ## To turn-off Telemetry
 
 If you want to turn off temeletry, please delete `--enable-telemetry` on `pkg/k8s/crd/install/shifu_install.yaml` manually.
+Or you can also edit via `kubectl edit deployment -n shifu-crd-system shifu-crd-controller-manager` after installation
 
 ```yaml
 apiVersion: apps/v1
diff --git a/pkg/k8s/crd/main.go b/pkg/k8s/crd/main.go
index d4048afe9..1a76d88ce 100644
--- a/pkg/k8s/crd/main.go
+++ b/pkg/k8s/crd/main.go
@@ -59,7 +59,7 @@ func main() {
 	flag.BoolVar(&enableLeaderElection, "leader-elect", false,
 		"Enable leader election for controller manager. "+
 			"Enabling this will ensure there is only one active controller manager.")
-	flag.BoolVar(&enableTelemetry, "enable-telemetry", false, "collection telemetry")
+	flag.BoolVar(&enableTelemetry, "enable-telemetry", false, "Collect telemetry")
 	opts := zap.Options{
 		Development: true,
 	}
diff --git a/pkg/k8s/crd/telemetry/utils/utils.go b/pkg/k8s/crd/telemetry/utils/utils.go
index abea53305..8414ef8fd 100644
--- a/pkg/k8s/crd/telemetry/utils/utils.go
+++ b/pkg/k8s/crd/telemetry/utils/utils.go
@@ -10,6 +10,8 @@ import (
 	"log"
 	"net/http"
 	"strings"
+
+	"github.com/edgenesis/shifu/pkg/k8s/crd/telemetry/types"
 )
 
 const (
@@ -50,10 +52,10 @@ func GetPublicIPAddr(url string) (string, error) {
 	return "", errors.New("Did not find IP in return query")
 }
 
-func SendTelemetry(telemetry interface{}) error {
+func SendTelemetry(telemetry types.TelemetryResponse) error {
 	postBodyJson, err := json.Marshal(telemetry)
 	if err != nil {
-		log.Printf("Error sending telemetry")
+		log.Printf("Error marshaling telemetry")
 		return err
 	}
 

From c6ac342d192110a94dfbbf58a3bf931b81fee096 Mon Sep 17 00:00:00 2001
From: liyuqi 
Date: Tue, 13 Sep 2022 17:02:09 +0800
Subject: [PATCH 4/7] tiny fix

---
 docs/guide/install-zh.md   | 2 +-
 docs/guide/telemetry-zh.md | 4 ++--
 docs/guide/telemetry.md    | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/docs/guide/install-zh.md b/docs/guide/install-zh.md
index e66c80cd3..d511e62b6 100644
--- a/docs/guide/install-zh.md
+++ b/docs/guide/install-zh.md
@@ -18,4 +18,4 @@
    ```
 
 ### 关于遥测
-要了解更多信息,包括如何禁用内置遥测,请在[此处](telemetry.md)查看我们的指南
\ No newline at end of file
+要了解更多信息,包括如何禁用内置遥测,请在[此处](telemetry-zh.md)查看我们的指南
\ No newline at end of file
diff --git a/docs/guide/telemetry-zh.md b/docs/guide/telemetry-zh.md
index ce91430b3..f2b1b1b61 100644
--- a/docs/guide/telemetry-zh.md
+++ b/docs/guide/telemetry-zh.md
@@ -15,7 +15,7 @@
 
 ## 关闭遥测
 
-如果要关闭 telemetry,请手动删除 `pkg/k8s/crd/install/shifu_install.yaml` 上的 `--enable-telemetry`。
+如果要关闭 telemetry,请手动删除 `pkg/k8s/crd/install/shifu_install.yaml` 上的 `--enable-telemetry`。  
 或者您也可以在安装后通过 `kubectl edit deployment -n shifu-crd-system shifu-crd-controller-manager` 进行编辑
 
 ```yaml
@@ -32,5 +32,5 @@ spec:
       image: quay.io/brancz/kube-rbac-proxy:v0.12.0
       name: kube-rbac-proxy
       - args:
-        - --enable-telemetry ## delete on demand
+        - --enable-telemetry ## 删除此行
 ```
\ No newline at end of file
diff --git a/docs/guide/telemetry.md b/docs/guide/telemetry.md
index ae2c94c55..f485eda96 100644
--- a/docs/guide/telemetry.md
+++ b/docs/guide/telemetry.md
@@ -15,7 +15,7 @@ Telemetry is enabled by default when you install Shifu, while you also have the
 
 ## To turn-off Telemetry
 
-If you want to turn off temeletry, please delete `--enable-telemetry` on `pkg/k8s/crd/install/shifu_install.yaml` manually.
+If you want to turn off temeletry, please delete `--enable-telemetry` on `pkg/k8s/crd/install/shifu_install.yaml` manually.  
 Or you can also edit via `kubectl edit deployment -n shifu-crd-system shifu-crd-controller-manager` after installation
 
 ```yaml

From 4586e5de2ff3143d7faccca561e82d03b14a027d Mon Sep 17 00:00:00 2001
From: liyuqi 
Date: Tue, 13 Sep 2022 17:05:55 +0800
Subject: [PATCH 5/7] replace space to enter

---
 docs/guide/telemetry-zh.md | 3 ++-
 docs/guide/telemetry.md    | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/docs/guide/telemetry-zh.md b/docs/guide/telemetry-zh.md
index f2b1b1b61..93a8849a6 100644
--- a/docs/guide/telemetry-zh.md
+++ b/docs/guide/telemetry-zh.md
@@ -15,7 +15,8 @@
 
 ## 关闭遥测
 
-如果要关闭 telemetry,请手动删除 `pkg/k8s/crd/install/shifu_install.yaml` 上的 `--enable-telemetry`。  
+如果要关闭 telemetry,请手动删除 `pkg/k8s/crd/install/shifu_install.yaml` 上的 `--enable-telemetry`。
+
 或者您也可以在安装后通过 `kubectl edit deployment -n shifu-crd-system shifu-crd-controller-manager` 进行编辑
 
 ```yaml
diff --git a/docs/guide/telemetry.md b/docs/guide/telemetry.md
index f485eda96..18115738b 100644
--- a/docs/guide/telemetry.md
+++ b/docs/guide/telemetry.md
@@ -15,7 +15,8 @@ Telemetry is enabled by default when you install Shifu, while you also have the
 
 ## To turn-off Telemetry
 
-If you want to turn off temeletry, please delete `--enable-telemetry` on `pkg/k8s/crd/install/shifu_install.yaml` manually.  
+If you want to turn off temeletry, please delete `--enable-telemetry` on `pkg/k8s/crd/install/shifu_install.yaml` manually.
+
 Or you can also edit via `kubectl edit deployment -n shifu-crd-system shifu-crd-controller-manager` after installation
 
 ```yaml

From da3abf51f1e4a69addc7f5788c651c8d96a0aeed Mon Sep 17 00:00:00 2001
From: liyuqi 
Date: Wed, 14 Sep 2022 07:34:55 +0800
Subject: [PATCH 6/7] make reviewer happy :)

---
 docs/guide/telemetry-zh.md                    | 21 +++++++++++++++++++
 docs/guide/telemetry.md                       | 21 +++++++++++++++++++
 .../default/manager_auth_proxy_patch.yaml     |  3 ++-
 pkg/k8s/crd/config/manager/manager.yaml       |  1 +
 pkg/k8s/crd/install/config_default.yaml       | 14 +------------
 pkg/k8s/crd/install/shifu_install.yml         | 14 +------------
 pkg/k8s/crd/main.go                           |  2 ++
 pkg/k8s/crd/telemetry/telemetry.go            |  2 +-
 pkg/k8s/crd/telemetry/utils/utils.go          | 17 ++++++++-------
 9 files changed, 59 insertions(+), 36 deletions(-)

diff --git a/docs/guide/telemetry-zh.md b/docs/guide/telemetry-zh.md
index 93a8849a6..ad95abd48 100644
--- a/docs/guide/telemetry-zh.md
+++ b/docs/guide/telemetry-zh.md
@@ -13,6 +13,27 @@
 - Kubernetes Deployment 名称
 - 操作系统的类型
 
+## 设置
+
+您可以通过设置  `pkg/k8s/crd/install/shifu_install.yaml` 上的 `--telemetry-interval=60` 对遥测的间隔时间进行设置。
+
+或者您也可以在安装后通过 `kubectl edit deployment -n shifu-crd-system shifu-crd-controller-manager` 进行编辑
+```yaml
+apiVersion: apps/v1
+kind: Deployment
+spec:
+  replicas: 1
+  selector:
+    matchLabels:
+      control-plane: controller-manager
+  template:
+    spec:
+      containers:
+      image: quay.io/brancz/kube-rbac-proxy:v0.12.0
+      name: kube-rbac-proxy
+      - args:
+        - --telemetry-interval=60 ## 编辑此行
+```
 ## 关闭遥测
 
 如果要关闭 telemetry,请手动删除 `pkg/k8s/crd/install/shifu_install.yaml` 上的 `--enable-telemetry`。
diff --git a/docs/guide/telemetry.md b/docs/guide/telemetry.md
index 18115738b..276317ce9 100644
--- a/docs/guide/telemetry.md
+++ b/docs/guide/telemetry.md
@@ -13,6 +13,27 @@ Telemetry is enabled by default when you install Shifu, while you also have the
 - Kubernetes Deployment Name
 - The type of the operating system
 
+## Setting
+
+You can modify telemetry interval by edit `--enable-telemetry` on `pkg/k8s/crd/install/shifu_install.yaml` manually.
+
+Or you can also edit via `kubectl edit deployment -n shifu-crd-system shifu-crd-controller-manager` after installation
+```yaml
+apiVersion: apps/v1
+kind: Deployment
+spec:
+  replicas: 1
+  selector:
+    matchLabels:
+      control-plane: controller-manager
+  template:
+    spec:
+      containers:
+      image: quay.io/brancz/kube-rbac-proxy:v0.12.0
+      name: kube-rbac-proxy
+      - args:
+        - --telemetry-interval=60 ## Edit this line
+```
 ## To turn-off Telemetry
 
 If you want to turn off temeletry, please delete `--enable-telemetry` on `pkg/k8s/crd/install/shifu_install.yaml` manually.
diff --git a/pkg/k8s/crd/config/default/manager_auth_proxy_patch.yaml b/pkg/k8s/crd/config/default/manager_auth_proxy_patch.yaml
index ba2092df5..08e484e28 100644
--- a/pkg/k8s/crd/config/default/manager_auth_proxy_patch.yaml
+++ b/pkg/k8s/crd/config/default/manager_auth_proxy_patch.yaml
@@ -24,4 +24,5 @@ spec:
         - "--health-probe-bind-address=:8081"
         - "--metrics-bind-address=127.0.0.1:8080"
         - "--leader-elect"
-        - "--enable-telemetry"
\ No newline at end of file
+        - "--enable-telemetry"
+        - "--telemetry-interval=60"
\ No newline at end of file
diff --git a/pkg/k8s/crd/config/manager/manager.yaml b/pkg/k8s/crd/config/manager/manager.yaml
index a008590fe..4e5c86d0b 100644
--- a/pkg/k8s/crd/config/manager/manager.yaml
+++ b/pkg/k8s/crd/config/manager/manager.yaml
@@ -30,6 +30,7 @@ spec:
         args:
         - --leader-elect
         - --enable-telemetry
+        - --telemetry-interval=60
         image: controller:latest
         name: manager
         securityContext:
diff --git a/pkg/k8s/crd/install/config_default.yaml b/pkg/k8s/crd/install/config_default.yaml
index 7885c48cf..11569a62b 100644
--- a/pkg/k8s/crd/install/config_default.yaml
+++ b/pkg/k8s/crd/install/config_default.yaml
@@ -435,6 +435,7 @@ spec:
         - --metrics-bind-address=127.0.0.1:8080
         - --leader-elect
         - --enable-telemetry
+        - --telemetry-interval=60
         command:
         - /manager
         image: edgehub/shifu-controller:v0.1.0
@@ -464,16 +465,3 @@ spec:
         runAsNonRoot: true
       serviceAccountName: shifu-crd-controller-manager
       terminationGracePeriodSeconds: 10
----
-apiVersion: rbac.authorization.k8s.io/v1
-kind: ClusterRoleBinding
-metadata:
-  name: default-view
-roleRef:
-  apiGroup: rbac.authorization.k8s.io
-  kind: ClusterRole
-  name: view
-subjects:
-- kind: ServiceAccount
-  name: shifu-crd-controller-manager
-  namespace: shifu-crd-system
\ No newline at end of file
diff --git a/pkg/k8s/crd/install/shifu_install.yml b/pkg/k8s/crd/install/shifu_install.yml
index 7af39eafe..fd84d25ab 100644
--- a/pkg/k8s/crd/install/shifu_install.yml
+++ b/pkg/k8s/crd/install/shifu_install.yml
@@ -435,6 +435,7 @@ spec:
         - --metrics-bind-address=127.0.0.1:8080
         - --leader-elect
         - --enable-telemetry
+        - --telemetry-interval=60
         command:
         - /manager
         image: edgehub/shifu-controller:v0.1.0
@@ -528,16 +529,3 @@ subjects:
 - kind: ServiceAccount
   name: edgedevice-sa
   namespace: deviceshifu
----
-apiVersion: rbac.authorization.k8s.io/v1
-kind: ClusterRoleBinding
-metadata:
-  name: default-view
-roleRef:
-  apiGroup: rbac.authorization.k8s.io
-  kind: ClusterRole
-  name: view
-subjects:
-- kind: ServiceAccount
-  name: shifu-crd-controller-manager
-  namespace: shifu-crd-system
\ No newline at end of file
diff --git a/pkg/k8s/crd/main.go b/pkg/k8s/crd/main.go
index 1a76d88ce..c557075d4 100644
--- a/pkg/k8s/crd/main.go
+++ b/pkg/k8s/crd/main.go
@@ -23,6 +23,7 @@ import (
 	"github.com/edgenesis/shifu/pkg/k8s/api/v1alpha1"
 	"github.com/edgenesis/shifu/pkg/k8s/controllers"
 	"github.com/edgenesis/shifu/pkg/k8s/crd/telemetry"
+	"github.com/edgenesis/shifu/pkg/k8s/crd/telemetry/utils"
 
 	// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
 	// to ensure that exec-entrypoint and run can make use of them.
@@ -60,6 +61,7 @@ func main() {
 		"Enable leader election for controller manager. "+
 			"Enabling this will ensure there is only one active controller manager.")
 	flag.BoolVar(&enableTelemetry, "enable-telemetry", false, "Collect telemetry")
+	flag.IntVar(&utils.TelemetryIntervalInSecond, "telemetry-interval", 60, "Telemetry Interval")
 	opts := zap.Options{
 		Development: true,
 	}
diff --git a/pkg/k8s/crd/telemetry/telemetry.go b/pkg/k8s/crd/telemetry/telemetry.go
index 533a7a161..d2851875a 100644
--- a/pkg/k8s/crd/telemetry/telemetry.go
+++ b/pkg/k8s/crd/telemetry/telemetry.go
@@ -82,6 +82,6 @@ func StartTelemetry() {
 			log.Println("telemetry done")
 		}
 
-		time.Sleep(utils.TELEMETRY_INTERVAL_IN_SECOND * time.Second)
+		time.Sleep(time.Duration(utils.TelemetryIntervalInSecond) * time.Second)
 	}
 }
diff --git a/pkg/k8s/crd/telemetry/utils/utils.go b/pkg/k8s/crd/telemetry/utils/utils.go
index 8414ef8fd..fd1e00996 100644
--- a/pkg/k8s/crd/telemetry/utils/utils.go
+++ b/pkg/k8s/crd/telemetry/utils/utils.go
@@ -15,16 +15,17 @@ import (
 )
 
 const (
-	URL_EXTERNAL_IP              = "http://cip.cc"
-	URL_IP_LINE                  = "
IP"
-	URL_SHIFU_TELEMETRY          = "https://telemetry.shifu.run/shifu-telemetry/"
-	URL_DEFAULT_PUBLIC_IP        = "0.0.0.0"
-	TASK_RUN_DEMO_KIND           = "run_shifu_release"
-	SOURCE_SHIFU_CONTROLLER      = "shifu_controller"
-	HTTP_CONTENT_TYPE_JSON       = "application/json"
-	TELEMETRY_INTERVAL_IN_SECOND = 60
+	URL_EXTERNAL_IP         = "http://cip.cc"
+	URL_IP_LINE             = "
IP"
+	URL_SHIFU_TELEMETRY     = "https://telemetry.shifu.run/shifu-telemetry/"
+	URL_DEFAULT_PUBLIC_IP   = "0.0.0.0"
+	TASK_RUN_DEMO_KIND      = "run_shifu_release"
+	SOURCE_SHIFU_CONTROLLER = "shifu_controller"
+	HTTP_CONTENT_TYPE_JSON  = "application/json"
 )
 
+var TelemetryIntervalInSecond int
+
 func GetPublicIPAddr(url string) (string, error) {
 	resp, err := http.Get(url)
 	if err != nil {

From 82758ff1dad5e8f27c2ec8a5c14b3f96f075891e Mon Sep 17 00:00:00 2001
From: liyuqi 
Date: Wed, 14 Sep 2022 14:46:40 +0800
Subject: [PATCH 7/7] log => klog

---
 pkg/k8s/crd/telemetry/telemetry.go   | 20 ++++++++++----------
 pkg/k8s/crd/telemetry/utils/utils.go |  8 ++++----
 2 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/pkg/k8s/crd/telemetry/telemetry.go b/pkg/k8s/crd/telemetry/telemetry.go
index d2851875a..c2af7c4bc 100644
--- a/pkg/k8s/crd/telemetry/telemetry.go
+++ b/pkg/k8s/crd/telemetry/telemetry.go
@@ -2,7 +2,6 @@ package telemetry
 
 import (
 	"context"
-	"log"
 	"time"
 
 	"github.com/edgenesis/shifu/pkg/k8s/crd/telemetry/types"
@@ -11,44 +10,45 @@ import (
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 	"k8s.io/client-go/kubernetes"
 	"k8s.io/client-go/rest"
+	"k8s.io/klog/v2"
 )
 
 func StartTelemetry() {
 	for {
 		publicIP, err := utils.GetPublicIPAddr(utils.URL_EXTERNAL_IP)
 		if err != nil {
-			log.Printf("issue getting Public IP")
+			klog.Errorf("issue getting Public IP")
 			publicIP = utils.URL_DEFAULT_PUBLIC_IP
 		}
 
-		log.Printf("Public IP is %v\n", publicIP)
+		klog.Infof("Public IP is %v\n", publicIP)
 		config, err := rest.InClusterConfig()
 		if err != nil {
-			log.Println("error when get cluster Config,error: ", err)
+			klog.Errorln("error when get cluster Config,error: ", err)
 			continue
 		}
 
 		clientset, err := kubernetes.NewForConfig(config)
 		if err != nil {
-			log.Println("cannot get ClusterInfo,errors: ", err)
+			klog.Errorln("cannot get ClusterInfo,errors: ", err)
 			continue
 		}
 
 		kVersion, err := clientset.ServerVersion()
 		if err != nil {
-			log.Println("cannot get Kubernetes Server Info,errors: ", err)
+			klog.Errorln("cannot get Kubernetes Server Info,errors: ", err)
 			continue
 		}
-		log.Printf("%#v", kVersion)
+		klog.Infof("%#v", kVersion)
 		pods, err := clientset.CoreV1().Pods("").List(context.TODO(), metav1.ListOptions{})
 		if err != nil {
-			log.Println("cannot get Pod Info,errors: ", err)
+			klog.Errorln("cannot get Pod Info,errors: ", err)
 			continue
 		}
 
 		deploy, err := clientset.AppsV1().Deployments("").List(context.TODO(), metav1.ListOptions{})
 		if err != nil {
-			log.Println("cannot get Deployment Info,errors: ", err)
+			klog.Errorln("cannot get Deployment Info,errors: ", err)
 			continue
 		}
 
@@ -79,7 +79,7 @@ func StartTelemetry() {
 		}
 
 		if result := utils.SendTelemetry(controllerTelemetry); result == nil {
-			log.Println("telemetry done")
+			klog.Infoln("telemetry done")
 		}
 
 		time.Sleep(time.Duration(utils.TelemetryIntervalInSecond) * time.Second)
diff --git a/pkg/k8s/crd/telemetry/utils/utils.go b/pkg/k8s/crd/telemetry/utils/utils.go
index fd1e00996..eacfee046 100644
--- a/pkg/k8s/crd/telemetry/utils/utils.go
+++ b/pkg/k8s/crd/telemetry/utils/utils.go
@@ -7,11 +7,11 @@ import (
 	"errors"
 	"fmt"
 	"io"
-	"log"
 	"net/http"
 	"strings"
 
 	"github.com/edgenesis/shifu/pkg/k8s/crd/telemetry/types"
+	"k8s.io/klog/v2"
 )
 
 const (
@@ -36,7 +36,7 @@ func GetPublicIPAddr(url string) (string, error) {
 	if resp.StatusCode == http.StatusOK {
 		bodyBytes, err := io.ReadAll(resp.Body)
 		if err != nil {
-			log.Printf("Error getting response of IP query")
+			klog.Errorf("Error getting response of IP query")
 			return "", err
 		}
 
@@ -56,13 +56,13 @@ func GetPublicIPAddr(url string) (string, error) {
 func SendTelemetry(telemetry types.TelemetryResponse) error {
 	postBodyJson, err := json.Marshal(telemetry)
 	if err != nil {
-		log.Printf("Error marshaling telemetry")
+		klog.Errorf("Error marshaling telemetry")
 		return err
 	}
 
 	resp, err := http.Post(URL_SHIFU_TELEMETRY, HTTP_CONTENT_TYPE_JSON, bytes.NewBuffer(postBodyJson))
 	if err != nil {
-		log.Println("error posting telemetry, errors: ", err)
+		klog.Errorln("error posting telemetry, errors: ", err)
 		return err
 	}