Skip to content

Commit

Permalink
#829 给注册日志监控的插件服务增加日志模版等参数
Browse files Browse the repository at this point in the history
  • Loading branch information
zgyzgyhero committed Oct 12, 2024
1 parent 576385d commit aae7274
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
1 change: 1 addition & 0 deletions build/register.xml
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,7 @@
<parameter datatype="string" required="N" sensitiveData="N" mappingType="constant" mappingEntityExpression="">logMonitorName</parameter>
<parameter datatype="string" required="N" sensitiveData="N" mappingType="constant" mappingEntityExpression="">deployPath</parameter>
<parameter datatype="string" required="N" sensitiveData="N" mappingType="system_variable" mappingSystemVariableName="MONITOR_LOG_MONITOR_TYPE">pathType</parameter>
<parameter datatype="object" required="N" sensitiveData="N" mappingType="constant" mappingEntityExpression="" multiple="Y">logServiceCodeList</parameter>
</inputParameters>
<outputParameters>
<parameter datatype="string" sensitiveData="N" mappingType="context">errorCode</parameter>
Expand Down
9 changes: 8 additions & 1 deletion monitor-server/models/service_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,14 @@ type PluginUpdateServicePathRequestObj struct {
LogMonitorPrefixCode string `json:"logMonitorPrefixCode"` // 日志监控指标前缀
LogMonitorName string `json:"logMonitorName"` // 日志监控配置名
DeployPath string `json:"deployPath"`
PathType string `json:"pathType"` // 日志类型-> logMonitor|logKeyword
PathType string `json:"pathType"` // 日志类型-> logMonitor|logKeyword
LogServiceCodeList interface{} `json:"logServiceCodeList"` // 业务服务码列表
}

type PluginUpdateServiceCodeObj struct {
Regulative int `json:"regulative"`
SourceValue string `json:"source_value"`
TargetValue string `json:"target_value"`
}

type PluginUpdateServicePathResp struct {
Expand Down
28 changes: 25 additions & 3 deletions monitor-server/services/db/service_plugin.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package db

import (
"encoding/json"
"fmt"
"github.com/WeBankPartners/go-common-lib/guid"
"github.com/WeBankPartners/open-monitor/monitor-server/middleware/log"
Expand Down Expand Up @@ -31,6 +32,15 @@ func PluginUpdateServicePathAction(input *models.PluginUpdateServicePathRequestO
}
pathList = newPathList
}
var logServiceCodeList []*models.PluginUpdateServiceCodeObj
if input.LogServiceCodeList != nil {
if codeBytes, codeMarshalErr := json.Marshal(input.LogServiceCodeList); codeMarshalErr == nil {
if codeUnmarshalErr := json.Unmarshal(codeBytes, &logServiceCodeList); codeUnmarshalErr != nil {
err = fmt.Errorf("param logServiceCode illegal,fail to parse json struct,%s ", codeUnmarshalErr.Error())
return
}
}
}
endpointTypeMap := getServiceGroupEndpointWithChild(input.SystemName)
sourceTargetMap := make(map[string]string)
var hostEndpoint, targetEndpoint []string
Expand Down Expand Up @@ -62,7 +72,7 @@ func PluginUpdateServicePathAction(input *models.PluginUpdateServicePathRequestO
err = fmt.Errorf("Update logKeyword config fail,%s ", err.Error())
}
} else {
err = updateServiceLogMetricPath(pathList, serviceGroupObj.Guid, input.MonitorType, sourceTargetMap, input.LogMonitorTemplate, input.LogMonitorPrefixCode, input.LogMonitorName, operator, roles, errMsgObj)
err = updateServiceLogMetricPath(pathList, serviceGroupObj.Guid, input.MonitorType, sourceTargetMap, input.LogMonitorTemplate, input.LogMonitorPrefixCode, input.LogMonitorName, operator, roles, errMsgObj, logServiceCodeList)
if err != nil {
err = fmt.Errorf("Update logMetric config fail,%s ", err.Error())
return
Expand All @@ -71,7 +81,7 @@ func PluginUpdateServicePathAction(input *models.PluginUpdateServicePathRequestO
return
}

func updateServiceLogMetricPath(pathList []string, serviceGroup, monitorType string, sourceTargetMap map[string]string, logMonitorTemplateGuid, logMonitorPrefixCode, logMonitorName, operator string, roles []string, errMsgObj *models.ErrorMessageObj) (err error) {
func updateServiceLogMetricPath(pathList []string, serviceGroup, monitorType string, sourceTargetMap map[string]string, logMonitorTemplateGuid, logMonitorPrefixCode, logMonitorName, operator string, roles []string, errMsgObj *models.ErrorMessageObj, logServiceCodeList []*models.PluginUpdateServiceCodeObj) (err error) {
var logMetricTable []*models.LogMetricMonitorTable
err = x.SQL("select * from log_metric_monitor where service_group=?", serviceGroup).Find(&logMetricTable)
if err != nil {
Expand Down Expand Up @@ -101,7 +111,7 @@ func updateServiceLogMetricPath(pathList []string, serviceGroup, monitorType str
actions = append(actions, tmpActions...)
}
}
for _, path := range pathList {
for i, path := range pathList {
if existMonitorType, b := existPathTypeMap[path]; b {
if existMonitorType != monitorType {
// change monitor type
Expand All @@ -125,6 +135,18 @@ func updateServiceLogMetricPath(pathList []string, serviceGroup, monitorType str
Name: logMonitorName,
ServiceGroup: serviceGroup,
MonitorType: monitorType,
CodeStringMap: []*models.LogMetricStringMapTable{},
}
if len(pathList) > 1 {
autoCreateLogMetricGroupParam.MetricPrefixCode += fmt.Sprintf("%d", i+1)
autoCreateLogMetricGroupParam.Name += fmt.Sprintf("_%d", i+1)
}
for _, codeRow := range logServiceCodeList {
autoCreateLogMetricGroupParam.CodeStringMap = append(autoCreateLogMetricGroupParam.CodeStringMap, &models.LogMetricStringMapTable{
Regulative: codeRow.Regulative,
SourceValue: codeRow.SourceValue,
TargetValue: codeRow.TargetValue,
})
}
createLogMetricGroupActions, _, newDashboardId, createLogMetricGroupErr := getCreateLogMetricGroupActions(&autoCreateLogMetricGroupParam, operator, roles, make(map[string]string), errMsgObj)
if createLogMetricGroupErr != nil {
Expand Down

0 comments on commit aae7274

Please sign in to comment.