Skip to content

Commit

Permalink
report-server 监控间隔调整
Browse files Browse the repository at this point in the history
通过正则表达式匹配schedule的cron表达式中的调用周期,从而指定cronjob中的interval
  • Loading branch information
zhaoxiangchun committed May 7, 2020
1 parent fb88568 commit fba6be1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
1 change: 0 additions & 1 deletion pkg/apis/onecloud/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,6 @@ type CronJobSpec struct {
ContainerSpec
Disable bool `json:"disable"`
Schedule string `json:"schedule"`
Interval string `json:"interval"`
Affinity *corev1.Affinity `json:"affinity,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
Expand Down
18 changes: 10 additions & 8 deletions pkg/manager/component/cloudmon_report_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package component
import (
"fmt"
"math"
"regexp"
"strconv"
"strings"

batchv1 "k8s.io/api/batch/v1beta1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -41,15 +43,15 @@ func (m *cloudmonReportServerManager) newCronJob(
cfg *v1alpha1.OnecloudClusterConfig,
) (*batchv1.CronJob, error) {
spec := &oc.Spec.CloudmonReportServer
//spec.Schedule = "*/15 * * * *"
if spec.Schedule == ""{
spec.Schedule = "*/15 * * * *"
reg, _ := regexp.Compile(`/\d+`)
fin := reg.Find([]byte(spec.Schedule))
if spec.Schedule == "" {
spec.Schedule = "*/4 * * * *"
fin = []byte("/4")
}
if spec.Interval == ""{
spec.Interval = "15"
}
period,_:=strconv.ParseFloat(spec.Interval,64)
monitorInterval:=strconv.FormatFloat(math.Ceil(period * v1alpha1.CronjobMonitorExpand),'f',-1,64)
interval := strings.Split(string(fin), "/")[1]
period, _ := strconv.ParseFloat(interval, 64)
monitorInterval := strconv.FormatFloat(math.Ceil(period*v1alpha1.CronjobMonitorExpand), 'f', -1, 64)
configMapType := v1alpha1.APIGatewayComponentType
containersF := func(volMounts []corev1.VolumeMount) []corev1.Container {
return []corev1.Container{
Expand Down

0 comments on commit fba6be1

Please sign in to comment.