Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rebase origin #38

Merged
merged 5 commits into from
Sep 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pkg/api/rest/alert/eventhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package alert

import (
"fmt"
"net/http"

"github.com/cloud-barista/cb-dragonfly/pkg/api/rest"
"github.com/cloud-barista/cb-dragonfly/pkg/core/alert/eventhandler"
"github.com/cloud-barista/cb-dragonfly/pkg/core/alert/types"
"github.com/labstack/echo/v4"
"net/http"
)

// ListEventHandler 알람 이벤트 핸들러 목록 조회
Expand Down Expand Up @@ -92,6 +93,8 @@ func UpdateEventHandler(c echo.Context) error {
eventType := c.Param("type")
eventHandlerName := c.Param("name")
params := &types.AlertEventHandlerReq{}
params.Type = eventType
params.Name = eventHandlerName
if err := c.Bind(params); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, rest.SetMessage(err.Error()))
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/core/agent/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (a AgentListManager) GetAgentList() (map[string]AgentInfo, error) {

func (a AgentListManager) GetAgentInfo(uuid string) (AgentInfo, error) {
agentInfo := AgentInfo{}
agentInfoStr := cbstore.GetInstance().StoreGet(uuid)
agentInfoStr := cbstore.GetInstance().StoreGet(fmt.Sprintf(uuid))

if agentInfoStr == "" {
return AgentInfo{}, errors.New(fmt.Sprintf("failed to get agent with UUID %s", uuid))
Expand Down Expand Up @@ -192,6 +192,6 @@ func SetMetadataByAgentUninstall(nsId string, mcisId string, vmId string, cspTyp
}

func MakeAgentUUID(nsId string, mcisId string, vmId string, cspType string) string {
UUID := nsId + "/" + mcisId + "/" + vmId + "/" + cspType
UUID := types.Agent + "/" + nsId + "/" + mcisId + "/" + vmId + "/" + cspType
return UUID
}
10 changes: 1 addition & 9 deletions pkg/core/alert/eventhandler/eventhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const (
)

var (
EventTypes = make(map[string]EventHandler)
EventTypes = map[string]EventHandler{SlackType: slack.SlackHandler{}, SMTPType: smtp.SmtpHandler{}}
)

type EventHandler interface {
Expand All @@ -26,15 +26,7 @@ type EventHandler interface {
DeleteEventHandler(name string) error
}

func InitializeEventTypes() {
EventTypes[SlackType] = slack.SlackHandler{}
EventTypes[SMTPType] = smtp.SmtpHandler{}
}

func ListEventHandlers(eventType string) ([]types.AlertEventHandler, error) {
if len(EventTypes) == 0 {
InitializeEventTypes()
}
// get specific event type handlers
if eventType != "" {
if _, ok := EventTypes[eventType]; !ok {
Expand Down
11 changes: 6 additions & 5 deletions pkg/core/alert/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package task

import (
"fmt"
v1 "github.com/cloud-barista/cb-dragonfly/pkg/metricstore/influxdb/v1"
"regexp"
"strings"

Expand All @@ -19,9 +20,9 @@ const (
KapacitorTaskPattern = "dragonfly-*"
KapacitorTaskFormat = "dragonfly-%s"
KapacitorTemplateID = "default"
InfluxDefaultDB = "cbmon"
InfluxDefaultRP = "autogen"
AlertMessageFormat = "[{{.Level}}] {{.ID}} {{.TaskName}} Alert \n%s"
//InfluxDefaultDB = "cbmon"
//InfluxDefaultRP = "autogen"
AlertMessageFormat = "[{{.Level}}] {{.ID}} {{.TaskName}} Alert \n%s"
)

func ListTasks() ([]types.AlertTask, error) {
Expand Down Expand Up @@ -64,8 +65,8 @@ func CreateTask(alertTaskReq types.AlertTaskReq) (*types.AlertTask, error) {
TemplateID: fmt.Sprintf(KapacitorTaskFormat, KapacitorTemplateID),
DBRPs: []kapacitorclient.DBRP{
{
Database: InfluxDefaultDB,
RetentionPolicy: InfluxDefaultRP,
Database: v1.DefaultDatabase,
RetentionPolicy: v1.CBRetentionPolicyName,
},
},
Status: kapacitorclient.Enabled,
Expand Down
44 changes: 24 additions & 20 deletions pkg/core/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,26 @@ func SetMonConfig(newMonConfig config.Monitoring) (*config.Monitoring, int, erro
if err != nil {
return nil, http.StatusInternalServerError, err
}
var defaultMonConfigMap map[string]interface{}
err = mapstructure.Decode(config.GetDefaultConfig().Monitoring, &defaultMonConfigMap)
if err != nil {
return nil, http.StatusInternalServerError, err
}

for key, val := range monConfigMap {
if val == nil || val == 0 || val == "" {
val = defaultMonConfigMap[key]
}
err := cbstore.GetInstance().StorePut(types.MonConfig+"/"+key, fmt.Sprintf("%v", val))
if err != nil {
return nil, http.StatusInternalServerError, err
if val != nil && val != 0 && val != "" {
err := cbstore.GetInstance().StorePut(types.MonConfig+"/"+key, fmt.Sprintf("%v", val))
if err != nil {
return nil, http.StatusInternalServerError, err
}
}
}

monConfig := config.Monitoring{
AgentInterval: cbstore.GetInstance().StoreGetToInt(fmt.Sprintf("%s/%s", types.MonConfig, "agent_interval")),
CollectorInterval: cbstore.GetInstance().StoreGetToInt(fmt.Sprintf("%s/%s", types.MonConfig, "collector_interval")),
MaxHostCount: cbstore.GetInstance().StoreGetToInt(fmt.Sprintf("%s/%s", types.MonConfig, "max_host_count")),
MonitoringPolicy: cbstore.GetInstance().StoreGetToString(fmt.Sprintf("%s/%s", types.MonConfig, "monitoring_policy")),
AgentInterval: cbstore.GetInstance().StoreGetToInt(fmt.Sprintf("%s/%s", types.MonConfig, "agent_interval")),
CollectorInterval: cbstore.GetInstance().StoreGetToInt(fmt.Sprintf("%s/%s", types.MonConfig, "collector_interval")),
MaxHostCount: cbstore.GetInstance().StoreGetToInt(fmt.Sprintf("%s/%s", types.MonConfig, "max_host_count")),
MonitoringPolicy: cbstore.GetInstance().StoreGetToString(fmt.Sprintf("%s/%s", types.MonConfig, "monitoring_policy")),
DefaultPolicy: cbstore.GetInstance().StoreGetToString(fmt.Sprintf("%s/%s", types.MonConfig, "default_policy")),
PullerInterval: cbstore.GetInstance().StoreGetToInt(fmt.Sprintf("%s/%s", types.MonConfig, "puller_interval")),
PullerAggregateInterval: cbstore.GetInstance().StoreGetToInt(fmt.Sprintf("%s/%s", types.MonConfig, "puller_aggregate_interval")),
AggregateType: cbstore.GetInstance().StoreGetToString(fmt.Sprintf("%s/%s", types.MonConfig, "aggregate_type")),
DeployType: cbstore.GetInstance().StoreGetToString(fmt.Sprintf("%s/%s", types.MonConfig, "deploy_type")),
}

return &monConfig, http.StatusOK, nil
Expand All @@ -49,13 +48,18 @@ func SetMonConfig(newMonConfig config.Monitoring) (*config.Monitoring, int, erro
// 모니터링 정책 조회
func GetMonConfig() (*config.Monitoring, int, error) {
monConfig := config.Monitoring{
AgentInterval: cbstore.GetInstance().StoreGetToInt(fmt.Sprintf("%s/%s", types.MonConfig, "agent_interval")),
CollectorInterval: cbstore.GetInstance().StoreGetToInt(fmt.Sprintf("%s/%s", types.MonConfig, "collector_interval")),
MaxHostCount: cbstore.GetInstance().StoreGetToInt(fmt.Sprintf("%s/%s", types.MonConfig, "max_host_count")),
MonitoringPolicy: cbstore.GetInstance().StoreGetToString(fmt.Sprintf("%s/%s", types.MonConfig, "monitoring_policy")),
AgentInterval: cbstore.GetInstance().StoreGetToInt(fmt.Sprintf("%s/%s", types.MonConfig, "agent_interval")),
CollectorInterval: cbstore.GetInstance().StoreGetToInt(fmt.Sprintf("%s/%s", types.MonConfig, "collector_interval")),
MaxHostCount: cbstore.GetInstance().StoreGetToInt(fmt.Sprintf("%s/%s", types.MonConfig, "max_host_count")),
MonitoringPolicy: cbstore.GetInstance().StoreGetToString(fmt.Sprintf("%s/%s", types.MonConfig, "monitoring_policy")),
DefaultPolicy: cbstore.GetInstance().StoreGetToString(fmt.Sprintf("%s/%s", types.MonConfig, "default_policy")),
PullerInterval: cbstore.GetInstance().StoreGetToInt(fmt.Sprintf("%s/%s", types.MonConfig, "puller_interval")),
PullerAggregateInterval: cbstore.GetInstance().StoreGetToInt(fmt.Sprintf("%s/%s", types.MonConfig, "puller_aggregate_interval")),
AggregateType: cbstore.GetInstance().StoreGetToString(fmt.Sprintf("%s/%s", types.MonConfig, "aggregate_type")),
DeployType: cbstore.GetInstance().StoreGetToString(fmt.Sprintf("%s/%s", types.MonConfig, "deploy_type")),
}

if monConfig.AgentInterval == -1 || monConfig.CollectorInterval == -1 || monConfig.MaxHostCount == -1 || monConfig.MonitoringPolicy == "" {
if monConfig.AgentInterval == -1 || monConfig.CollectorInterval == -1 || monConfig.MaxHostCount == -1 || monConfig.MonitoringPolicy == "" || monConfig.DefaultPolicy == "" || monConfig.PullerInterval == -1 || monConfig.PullerAggregateInterval == -1 || monConfig.AggregateType == "" || monConfig.DeployType == "" {
return nil, http.StatusInternalServerError, nil
}

Expand Down
6 changes: 2 additions & 4 deletions pkg/manager/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package manager

import (
"fmt"
echoSwagger "github.com/swaggo/echo-swagger"
"net/http"
"sync"

echoSwagger "github.com/swaggo/echo-swagger"

"github.com/cloud-barista/cb-dragonfly/pkg/util"

"github.com/cloud-barista/cb-dragonfly/pkg/api/rest/agent"
Expand All @@ -14,7 +15,6 @@ import (
"github.com/cloud-barista/cb-dragonfly/pkg/api/rest/healthcheck"
"github.com/cloud-barista/cb-dragonfly/pkg/api/rest/metric"
"github.com/cloud-barista/cb-dragonfly/pkg/config"
"github.com/cloud-barista/cb-dragonfly/pkg/core/alert/eventhandler"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"

Expand Down Expand Up @@ -42,8 +42,6 @@ func (apiServer *APIServer) StartAPIServer(wg *sync.WaitGroup) error {
// 모니터링 API 라우팅 룰 설정
apiServer.SetRoutingRule(apiServer.echo)

eventhandler.InitializeEventTypes()

// 모니터링 API 서버 실행
return apiServer.echo.Start(fmt.Sprintf(":%d", config.GetInstance().APIServer.Port))
}
Expand Down