Skip to content

Commit

Permalink
Merge pull request #158 from traas-stack/dev/v0.6.2
Browse files Browse the repository at this point in the history
some feature/bugfix in March
  • Loading branch information
KingsonKai authored Mar 4, 2024
2 parents 87f3854 + 975d872 commit 2b1da1d
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 23 deletions.
6 changes: 3 additions & 3 deletions chaosmeta-deploy/templates/chaosmeta-flow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,10 @@ spec:
resources:
limits:
cpu: 500m
memory: 128Mi
memory: 256Mi
requests:
cpu: 10m
memory: 64Mi
cpu: 500m
memory: 256Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
Expand Down
6 changes: 3 additions & 3 deletions chaosmeta-deploy/templates/chaosmeta-inject.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,10 @@ spec:
resources:
limits:
cpu: 500m
memory: 128Mi
memory: 256Mi
requests:
cpu: 10m
memory: 64Mi
cpu: 500m
memory: 256Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
Expand Down
6 changes: 3 additions & 3 deletions chaosmeta-deploy/templates/chaosmeta-measure.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,10 @@ spec:
resources:
limits:
cpu: 500m
memory: 128Mi
memory: 256Mi
requests:
cpu: 10m
memory: 64Mi
cpu: 500m
memory: 256Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
Expand Down
27 changes: 27 additions & 0 deletions chaosmeta-deploy/templates/chaosmeta-platform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,30 @@ spec:
- name: mysql-storage
hostPath:
path: "/mnt/chaosmeta-platform-mysql"
---
apiVersion: v1
kind: Service
metadata:
finalizers:
- service.k8s.alibaba/resources
labels:
app: chaosmeta-platform
name: chaosmeta-platform
namespace: chaosmeta
spec:
allocateLoadBalancerNodePorts: true
externalTrafficPolicy: Cluster
internalTrafficPolicy: Cluster
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
ports:
- name: http
nodePort: 32504
port: 8000
protocol: TCP
targetPort: 8000
selector:
app: chaosmeta-platform
sessionAffinity: None
type: LoadBalancer
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ShowText from '@/components/ShowText';
import { triggerTypes } from '@/constants';
import { formatTime, getIntlLabel } from '@/utils/format';
import { formatTime, getIntlLabel, timesStampString } from '@/utils/format';
import { renderScheduleType, renderTags } from '@/utils/renderItem';
import { history, useIntl } from '@umijs/max';
import { Button, DatePicker, Drawer, Form, Input, Radio, Space } from 'antd';
Expand Down Expand Up @@ -56,7 +56,7 @@ const InfoDrawer: React.FC<IProps> = (props) => {
const handleSubmit = () => {
form.validateFields().then((values) => {
if (values?.schedule_type === 'once') {
values.schedule_rule = formatTime(values?.once_time);
values.schedule_rule = values?.once_time.valueOf().toString()
}
handleConfirm({ ...values, labels: addTagList });
setOpen(false);
Expand All @@ -75,7 +75,7 @@ const InfoDrawer: React.FC<IProps> = (props) => {
name,
});
if (baseInfo?.schedule_type === 'once') {
form.setFieldValue('once_time', dayjs(schedule_rule));
form.setFieldValue('once_time', dayjs(timesStampString(schedule_rule)));
}
if (baseInfo?.schedule_type === 'cron') {
form.setFieldValue('schedule_rule', schedule_rule);
Expand Down
11 changes: 10 additions & 1 deletion chaosmeta-platform-frontend/src/utils/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function trim(str: string) {
return str.trim();
}

export const formatTime = (time?: dayjs.Dayjs | string) => {
export const formatTime = (time?: dayjs.Dayjs | string | number) => {
if (time) {
return dayjs(time)?.format('YYYY-MM-DD HH:mm:ss');
}
Expand Down Expand Up @@ -336,3 +336,12 @@ export const formatFormName = (
}
return name;
};

/**
* 时间戳字符串转时间戳
* @param time 时间字符串,"1706150902050"转为1706150902050,"2024-01-12 20:02:16"则不变
* @returns
*/
export const timesStampString = (time: string) => {
return !time || isNaN(Number(time)) ? time : Number(time);
};
4 changes: 2 additions & 2 deletions chaosmeta-platform-frontend/src/utils/renderItem.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { tagColors, triggerTypes } from '@/constants';
import { Popover, Tag } from 'antd';
import { cronTranstionCN, formatTime, getIntlLabel } from './format';
import { cronTranstionCN, formatTime, getIntlLabel, timesStampString } from './format';

/**
* 用于各重复组件方法的渲染
Expand All @@ -25,7 +25,7 @@ export const renderScheduleType = (baseInfo: any) => {
return (
<div>
{getIntlLabel(temp)}
<span>{`(${formatTime(schedule_rule)})`}</span>
<span>{`(${formatTime(timesStampString(schedule_rule))})`}</span>
</div>
);
}
Expand Down
4 changes: 2 additions & 2 deletions chaosmeta-platform/pkg/service/experiment/experiment.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ func (es *ExperimentService) UpdateExperiment(uuid string, experimentParam *Expe
}
}

if getExperiment.ScheduleType != experimentParam.ScheduleType {
if getExperiment.ScheduleType != experimentParam.ScheduleType || getExperiment.ScheduleRule != experimentParam.ScheduleRule {
getExperiment.Status = experiment.ToBeExecuted
}
getExperiment.Name = experimentParam.Name
Expand Down Expand Up @@ -376,7 +376,7 @@ func (es *ExperimentService) GetExperimentByUUID(uuid string) (*ExperimentGet, e
}

if !experimentGet.NextExec.IsZero() {
experimentReturn.NextExec = experimentGet.NextExec.Format(TimeLayout)
experimentReturn.NextExec = experimentGet.NextExec.Format(time.RFC3339)
}

experimentCount, _ := experiment_instance.CountExperimentInstances(0, experimentGet.UUID, "", 0)
Expand Down
18 changes: 13 additions & 5 deletions chaosmeta-platform/pkg/service/experiment/routine.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/robfig/cron"
"gopkg.in/yaml.v2"
"k8s.io/client-go/rest"
"strconv"
"time"
)

Expand Down Expand Up @@ -349,10 +350,17 @@ func (e *ExperimentRoutine) DealOnceExperiment() {
}

for _, experimentGet := range experiments {
nextExec, _ := time.Parse(DefaultFormat, experimentGet.ScheduleRule)
timeNow, _ := time.Parse(DefaultFormat, time.Now().Format(DefaultFormat))
timeStamp, err := strconv.ParseInt(experimentGet.ScheduleRule, 10, 64)
var nextExec time.Time
if err != nil {
log.Error(err)
nextExec, _ = time.Parse(DefaultFormat, experimentGet.ScheduleRule)
} else {
nextExec = time.UnixMilli(timeStamp)
}
timeNow := time.Now()
if timeNow.After(nextExec) {
experimentGet.LastInstance = timeNow.Format(TimeLayout)
experimentGet.LastInstance = timeNow.Format(time.RFC3339)
log.Info(experimentGet.UUID, "next exec time", experimentGet.NextExec)
if err := experiment.UpdateExperiment(experimentGet); err != nil {
log.Error(err)
Expand Down Expand Up @@ -383,7 +391,7 @@ func (e *ExperimentRoutine) DealCronExperiment() {
return
}
for _, experimentGet := range experiments {
cronExpr, err := cron.Parse(experimentGet.ScheduleRule)
cronExpr, err := cron.ParseStandard(experimentGet.ScheduleRule)
if err != nil {
continue
}
Expand All @@ -399,7 +407,7 @@ func (e *ExperimentRoutine) DealCronExperiment() {
if time.Now().After(experimentGet.NextExec) {
experimentGet.Status = experiment.Executed
experimentGet.NextExec = cronExpr.Next(now)
experimentGet.LastInstance = time.Now().Format(TimeLayout)
experimentGet.LastInstance = time.Now().Format(time.RFC3339)
log.Info(experimentGet.UUID, "next exec time", experimentGet.NextExec)
if err := experiment.UpdateExperiment(experimentGet); err != nil {
log.Error(err)
Expand Down
2 changes: 1 addition & 1 deletion chaosmetad/pkg/storage/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func newDBStorage() (*dbStorage, error) {
// TODO: db path can be config
dsn := path.Join(utils.GetRunPath(), storageFile)

dsn += "?cache=shared"
dsn += "?cache=shared&loc=Local"

gormDB, err := gorm.Open(sqlite.Open(dsn), &gorm.Config{
Logger: logger.Default.LogMode(logger.Silent),
Expand Down

0 comments on commit 2b1da1d

Please sign in to comment.