Skip to content
Open
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
55 changes: 55 additions & 0 deletions api/mesh/v1alpha1/k8s_event.go

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: ่ฟ™ไธชๆ–‡ไปถๅบ”่ฏฅ่ฆ็”ฑๆ’ไปถ่‡ชๅŠจ็”Ÿๆˆ็š„๏ผŒ่ง๏ผšResource็š„ๅฎšไน‰ไธŽๆ›ดๆ–ฐ

Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package v1alpha1

// K8sEvent is the spec for a K8s event resource, capturing both K8s native events
// and registry-side lifecycle events in a unified format.
type K8sEvent struct {
Namespace string `json:"namespace,omitempty"`
Reason string `json:"reason,omitempty"`
Message string `json:"message,omitempty"`
Type string `json:"type,omitempty"`
InvolvedObjKind string `json:"involvedObjKind,omitempty"`
InvolvedObjName string `json:"involvedObjName,omitempty"`
SourceComponent string `json:"sourceComponent,omitempty"`
SourceHost string `json:"sourceHost,omitempty"`
FirstTimestamp string `json:"firstTimestamp,omitempty"`
LastTimestamp string `json:"lastTimestamp,omitempty"`
Count int32 `json:"count,omitempty"`
EventSource string `json:"eventSource,omitempty"`
}

func (e *K8sEvent) Clone() *K8sEvent {
if e == nil {
return nil
}
return &K8sEvent{
Namespace: e.Namespace,
Reason: e.Reason,
Message: e.Message,
Type: e.Type,
InvolvedObjKind: e.InvolvedObjKind,
InvolvedObjName: e.InvolvedObjName,
SourceComponent: e.SourceComponent,
SourceHost: e.SourceHost,
FirstTimestamp: e.FirstTimestamp,
LastTimestamp: e.LastTimestamp,
Count: e.Count,
EventSource: e.EventSource,
}
}
38 changes: 38 additions & 0 deletions api/mesh/v1alpha1/k8s_event.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
syntax = "proto3";

package dubbo.mesh.v1alpha1;

option go_package = "github.com/apache/dubbo-admin/api/mesh/v1alpha1";

import "api/mesh/options.proto";

message K8sEvent {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: PlatformEventไธบไป€ไนˆๆฒกๆœ‰protoๅฎšไน‰๏ผŸ

option (dubbo.mesh.resource).name = "K8sEvent";
option (dubbo.mesh.resource).plural_name = "K8sEvents";
option (dubbo.mesh.resource).package = "mesh";
option (dubbo.mesh.resource).is_experimental = true;

string namespace = 1;

string reason = 2;

string message = 3;

string type = 4;

string involvedObjKind = 5;

string involvedObjName = 6;

string sourceComponent = 7;

string sourceHost = 8;

string firstTimestamp = 9;

string lastTimestamp = 10;

int32 count = 11;

string eventSource = 12;
}
77 changes: 77 additions & 0 deletions pkg/console/handler/event.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package handler

import (
"net/http"

"github.com/gin-gonic/gin"

consolectx "github.com/apache/dubbo-admin/pkg/console/context"
"github.com/apache/dubbo-admin/pkg/console/model"
"github.com/apache/dubbo-admin/pkg/console/service"
"github.com/apache/dubbo-admin/pkg/console/util"
)

func GetApplicationEvents(ctx consolectx.Context) gin.HandlerFunc {
return func(c *gin.Context) {
req := &model.EventQueryReq{}
if err := c.ShouldBindQuery(req); err != nil {
util.HandleArgumentError(c, err)
return
}
resp, err := service.ListApplicationEvents(ctx, req)
if err != nil {
util.HandleServiceError(c, err)
return
}
c.JSON(http.StatusOK, model.NewSuccessResp(resp))
}
}

func GetInstanceEvents(ctx consolectx.Context) gin.HandlerFunc {
return func(c *gin.Context) {
req := &model.EventQueryReq{}
if err := c.ShouldBindQuery(req); err != nil {
util.HandleArgumentError(c, err)
return
}
resp, err := service.ListInstanceEvents(ctx, req)
if err != nil {
util.HandleServiceError(c, err)
return
}
c.JSON(http.StatusOK, model.NewSuccessResp(resp))
}
}

func GetServiceEvents(ctx consolectx.Context) gin.HandlerFunc {
return func(c *gin.Context) {
req := &model.EventQueryReq{}
if err := c.ShouldBindQuery(req); err != nil {
util.HandleArgumentError(c, err)
return
}
resp, err := service.ListServiceEvents(ctx, req)
if err != nil {
util.HandleServiceError(c, err)
return
}
c.JSON(http.StatusOK, model.NewSuccessResp(resp))
}
}
43 changes: 43 additions & 0 deletions pkg/console/model/event.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package model

import (
coremodel "github.com/apache/dubbo-admin/pkg/core/resource/model"
)

type EventQueryReq struct {
AppName string `form:"appName"`
InstanceName string `form:"instanceName"`
InstanceIP string `form:"ip"`
ServiceName string `form:"serviceName"`
Mesh string `form:"mesh"`
coremodel.PageReq
}

type EventItem struct {
Time string `json:"time"`
Type string `json:"type"`
Message string `json:"message"`
Source string `json:"source"`
}

type EventListResp struct {
List []*EventItem `json:"list"`
Total int `json:"total"`
}
3 changes: 3 additions & 0 deletions pkg/console/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func InitRouter(r *gin.Engine, ctx consolectx.Context) {
instanceConfig.GET("/operatorLog", handler.InstanceConfigOperatorLogGET(ctx))
instanceConfig.PUT("/operatorLog", handler.InstanceConfigOperatorLogPUT(ctx))
}
instance.GET("/event", handler.GetInstanceEvents(ctx))
instance.GET("/metric-dashboard", handler.GetGrafanaDashboard(ctx, handler.InstanceDimension, handler.MetricDashboard))
instance.GET("/trace-dashboard", handler.GetGrafanaDashboard(ctx, handler.InstanceDimension, handler.TraceDashboard))
instance.GET("/metrics-list", handler.GetMetricsList(ctx))
Expand All @@ -72,6 +73,7 @@ func InitRouter(r *gin.Engine, ctx consolectx.Context) {
applicationConfig.GET("/gray", handler.ApplicationConfigGrayGET(ctx))
applicationConfig.PUT("/gray", handler.ApplicationConfigGrayPUT(ctx))
}
application.GET("/event", handler.GetApplicationEvents(ctx))
application.GET("/metric-dashboard", handler.GetGrafanaDashboard(ctx, handler.AppDimension, handler.MetricDashboard))
application.GET("/trace-dashboard", handler.GetGrafanaDashboard(ctx, handler.AppDimension, handler.TraceDashboard))
}
Expand Down Expand Up @@ -106,6 +108,7 @@ func InitRouter(r *gin.Engine, ctx consolectx.Context) {
service.GET("/search", handler.SearchServices(ctx))
service.GET("/graph", handler.GetServiceGraph(ctx))
service.GET("/detail", handler.GetServiceDetail(ctx))
service.GET("/event", handler.GetServiceEvents(ctx))
service.GET("/interfaces", handler.GetServiceInterfaces(ctx))
}

Expand Down
Loading
Loading