mirror of
https://github.com/APIParkLab/APIPark.git
synced 2026-06-04 10:13:53 +08:00
fix log bug
This commit is contained in:
+18
-12
@@ -212,23 +212,29 @@ func (i *imlStrategyController) DeleteStrategy(ctx *gin.Context, id string) erro
|
||||
return i.strategyModule.Delete(ctx, id)
|
||||
}
|
||||
|
||||
func genTime(t string, defaultValue time.Time) (time.Time, error) {
|
||||
if t == "" {
|
||||
return defaultValue, nil
|
||||
}
|
||||
|
||||
s, err := strconv.ParseInt(t, 10, 64)
|
||||
if err != nil {
|
||||
return time.Time{}, err
|
||||
}
|
||||
return time.Unix(s, 0), nil
|
||||
}
|
||||
|
||||
func (i *imlStrategyController) GetStrategyLogs(ctx *gin.Context, keyword string, strategyId string, start string, end string, limit string, offset string) ([]*strategy_dto.LogItem, int64, error) {
|
||||
now := time.Now()
|
||||
s, err := time.ParseInLocation("2006-01-02 15:04:05", start, time.Local)
|
||||
|
||||
s, err := genTime(start, now.Add(-time.Hour*24*30))
|
||||
if err != nil {
|
||||
if start == "" {
|
||||
s = now.Add(-time.Hour * 24 * 30)
|
||||
} else {
|
||||
return nil, 0, fmt.Errorf("start time error: %s", err)
|
||||
}
|
||||
return nil, 0, fmt.Errorf("start time error: %s", err)
|
||||
}
|
||||
e, err := time.ParseInLocation("2006-01-02 15:04:05", end, time.Local)
|
||||
e, err := genTime(start, now)
|
||||
if err != nil {
|
||||
if end == "" {
|
||||
e = now
|
||||
} else {
|
||||
return nil, 0, fmt.Errorf("end time error: %s", err)
|
||||
}
|
||||
|
||||
return nil, 0, fmt.Errorf("end time error: %s", err)
|
||||
}
|
||||
if s.After(e) {
|
||||
return nil, 0, fmt.Errorf("start time must be less than end time")
|
||||
|
||||
@@ -69,8 +69,10 @@ func (a *ApplicationClient) toApinto(app *gateway.ApplicationRelease) interface{
|
||||
Expire: info.Expire,
|
||||
Pattern: driver.ToPattern(info.Config),
|
||||
HideCredential: info.HideCredential,
|
||||
Labels: info.Label,
|
||||
},
|
||||
},
|
||||
Labels: info.Label,
|
||||
})
|
||||
}
|
||||
labels := make(map[string]string)
|
||||
|
||||
@@ -7,15 +7,17 @@ type Application struct {
|
||||
}
|
||||
|
||||
type Authorization struct {
|
||||
Type string `json:"type"`
|
||||
Position string `json:"position"`
|
||||
TokenName string `json:"token_name"`
|
||||
Config interface{} `json:"config"`
|
||||
Users []*AuthUser `json:"users"`
|
||||
Type string `json:"type"`
|
||||
Position string `json:"position"`
|
||||
TokenName string `json:"token_name"`
|
||||
Config interface{} `json:"config"`
|
||||
Users []*AuthUser `json:"users"`
|
||||
Labels map[string]string `json:"labels"`
|
||||
}
|
||||
|
||||
type AuthUser struct {
|
||||
Expire int64 `json:"expire"`
|
||||
Pattern interface{} `json:"pattern"`
|
||||
HideCredential bool `json:"hide_credential"`
|
||||
Expire int64 `json:"expire"`
|
||||
Pattern interface{} `json:"pattern"`
|
||||
HideCredential bool `json:"hide_credential"`
|
||||
Labels map[string]string `json:"labels"`
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ func (d *Driver) LogCount(clusterId string, conditions map[string]string, spendH
|
||||
tmpCondition = "|" + strings.Join(cs, "|")
|
||||
}
|
||||
queries := url.Values{}
|
||||
queries.Set("query", fmt.Sprintf("sum(count_over_time({cluster=\"%s\"} %s [%dh])) by (%s)", clusterId, tmpCondition, spendHour, group))
|
||||
queries.Set("query", fmt.Sprintf("sum(count_over_time({cluster=\"%s\"} | json %s [%dh])) by (%s)", clusterId, tmpCondition, spendHour, group))
|
||||
list, err := send[LogCount](http.MethodGet, fmt.Sprintf("%s/loki/api/v1/query", d.url), d.headers, queries, "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -220,7 +220,7 @@ func (d *Driver) logCount(clusterId string, conditions map[string]string, start
|
||||
if len(conditions) > 0 {
|
||||
tmpCondition = "|" + strings.Join(cs, "|")
|
||||
}
|
||||
queries.Set("query", fmt.Sprintf("sum(count_over_time({cluster=\"%s\"} %s [720h]))", clusterId, tmpCondition))
|
||||
queries.Set("query", fmt.Sprintf("sum(count_over_time({cluster=\"%s\"} | json %s [720h]))", clusterId, tmpCondition))
|
||||
list, err := send[LogCount](http.MethodGet, fmt.Sprintf("%s/loki/api/v1/query", d.url), d.headers, queries, "")
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
||||
@@ -122,7 +122,7 @@ type LogItem struct {
|
||||
Url string `json:"url"`
|
||||
RemoteIP string `json:"remote_ip"`
|
||||
Consumer auto.Label `json:"consumer" aolabel:"service"`
|
||||
Authorization auto.Label `json:"authorization" aolabel:"authorization"`
|
||||
Authorization auto.Label `json:"authorization" aolabel:"service_authorization"`
|
||||
RecordTime auto.TimeLabel `json:"record_time"`
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,6 @@ func (p *plugin) strategyApis() []pm3.Api {
|
||||
|
||||
pm3.CreateApiWidthDoc(http.MethodGet, "/api/v1/strategy/global/:driver/to-publishs", []string{"context", "rest:driver"}, []string{"strategies", "source", "version_name", "is_publish"}, p.strategyController.ToPublish),
|
||||
pm3.CreateApiWidthDoc(http.MethodGet, "/api/v1/strategy/global/:driver/logs", []string{"context", "query:keyword", "query:strategy", "query:begin", "query:end", "query:page", "query:page_size"}, []string{"logs", "total"}, p.strategyController.GetStrategyLogs),
|
||||
pm3.CreateApiWidthDoc(http.MethodGet, "/api/v1/strategy/global/:driver/log", []string{"context", "query:id"}, []string{"log"}, p.strategyController.LogInfo),
|
||||
pm3.CreateApiWidthDoc(http.MethodGet, "/api/v1/strategy/global/:driver/log", []string{"context", "query:log"}, []string{"log"}, p.strategyController.LogInfo),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ func (i *imlAuthorizationService) OnComplete() {
|
||||
i.IServiceCreate = universally.NewCreator[Create, service.Authorization](i.store, "project_authorization", createEntityHandler, uniquestHandler, labelHandler)
|
||||
|
||||
i.IServiceEdit = universally.NewEdit[Edit, service.Authorization](i.store, updateHandler, labelHandler)
|
||||
auto.RegisterService("project_authorization", i)
|
||||
auto.RegisterService("service_authorization", i)
|
||||
}
|
||||
|
||||
func labelHandler(e *service.Authorization) []string {
|
||||
|
||||
+1
-1
@@ -77,7 +77,7 @@ func (i *imlLogService) UpdateLogSource(ctx context.Context, driver string, inpu
|
||||
}
|
||||
|
||||
} else {
|
||||
if input.Config == nil || *input.Config == "" {
|
||||
if input.Config != nil && *input.Config != "" {
|
||||
s.Config = *input.Config
|
||||
}
|
||||
s.Updater = utils.UserId(ctx)
|
||||
|
||||
Reference in New Issue
Block a user