Skip to content

Commit

Permalink
fix(build): redeclaration of get statistic handler
Browse files Browse the repository at this point in the history
  • Loading branch information
powerfooI committed Mar 13, 2024
1 parent 091bb20 commit a47fe9c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 113 deletions.
6 changes: 3 additions & 3 deletions internal/dashboard/generated/swagger/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -640,14 +640,14 @@ const docTemplate = `{
}
}
},
"/api/v1/metrics/telemetry": {
"/api/v1/metrics/statistic": {
"get": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "get telemetry data",
"description": "get statistic data",
"consumes": [
"application/json"
],
Expand All @@ -657,7 +657,7 @@ const docTemplate = `{
"tags": [
"Info"
],
"summary": "get telemetry data",
"summary": "get statistic data",
"operationId": "GetStatistics",
"responses": {
"200": {
Expand Down
6 changes: 3 additions & 3 deletions internal/dashboard/generated/swagger/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -633,14 +633,14 @@
}
}
},
"/api/v1/metrics/telemetry": {
"/api/v1/metrics/statistic": {
"get": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "get telemetry data",
"description": "get statistic data",
"consumes": [
"application/json"
],
Expand All @@ -650,7 +650,7 @@
"tags": [
"Info"
],
"summary": "get telemetry data",
"summary": "get statistic data",
"operationId": "GetStatistics",
"responses": {
"200": {
Expand Down
6 changes: 3 additions & 3 deletions internal/dashboard/generated/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1695,11 +1695,11 @@ paths:
summary: query metrics
tags:
- Metric
/api/v1/metrics/telemetry:
/api/v1/metrics/statistic:
get:
consumes:
- application/json
description: get telemetry data
description: get statistic data
operationId: GetStatistics
produces:
- application/json
Expand Down Expand Up @@ -1727,7 +1727,7 @@ paths:
$ref: '#/definitions/response.APIResponse'
security:
- ApiKeyAuth: []
summary: get telemetry data
summary: get statistic data
tags:
- Info
/api/v1/obclusters:
Expand Down
107 changes: 4 additions & 103 deletions internal/dashboard/handler/info_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/oceanbase/ob-operator/internal/oceanbase"
"github.com/oceanbase/ob-operator/internal/telemetry"
"github.com/oceanbase/ob-operator/internal/telemetry/models"
crypto "github.com/oceanbase/ob-operator/pkg/crypto"
httpErr "github.com/oceanbase/ob-operator/pkg/errors"
"github.com/oceanbase/ob-operator/pkg/k8s/client"
)
Expand Down Expand Up @@ -59,116 +60,16 @@ func GetProcessInfo(_ *gin.Context) (*response.DashboardInfo, error) {
}

// @ID GetStatistics
// @Summary get telemetry data
// @Description get telemetry data
// @Summary get statistic data
// @Description get statistic data
// @Tags Info
// @Accept application/json
// @Produce application/json
// @Success 200 object response.APIResponse{data=response.StatisticDataResponse}
// @Failure 400 object response.APIResponse
// @Failure 401 object response.APIResponse
// @Failure 500 object response.APIResponse
// @Router /api/v1/metrics/telemetry [GET]
// @Security ApiKeyAuth
func GetStatistics(c *gin.Context) (*response.StatisticDataResponse, error) {
reportData := response.StatisticData{}
clusterList := v1alpha1.OBClusterList{}
err := oceanbase.ClusterClient.List(c, corev1.NamespaceAll, &clusterList, metav1.ListOptions{})
if err != nil {
return nil, httpErr.NewInternal(err.Error())
}
reportData.Clusters = make([]models.OBCluster, 0, len(clusterList.Items))
for i := range clusterList.Items {
modelCluster := telemetry.TransformReportOBCluster(&clusterList.Items[i])
reportData.Clusters = append(reportData.Clusters, *modelCluster)
}

zoneList := v1alpha1.OBZoneList{}
err = oceanbase.ZoneClient.List(c, corev1.NamespaceAll, &zoneList, metav1.ListOptions{})
if err != nil {
return nil, httpErr.NewInternal(err.Error())
}
reportData.Zones = make([]models.OBZone, 0, len(zoneList.Items))
for i := range zoneList.Items {
modelZone := telemetry.TransformReportOBZone(&zoneList.Items[i])
reportData.Zones = append(reportData.Zones, *modelZone)
}

serverList := v1alpha1.OBServerList{}
err = oceanbase.ServerClient.List(c, corev1.NamespaceAll, &serverList, metav1.ListOptions{})
if err != nil {
return nil, httpErr.NewInternal(err.Error())
}
reportData.Servers = make([]models.OBServer, 0, len(serverList.Items))
for i := range serverList.Items {
modelServer := telemetry.TransformReportOBServer(&serverList.Items[i])
reportData.Servers = append(reportData.Servers, *modelServer)
}

tenantList := v1alpha1.OBTenantList{}
err = oceanbase.TenantClient.List(c, corev1.NamespaceAll, &tenantList, metav1.ListOptions{})
if err != nil {
return nil, httpErr.NewInternal(err.Error())
}
reportData.Tenants = make([]models.OBTenant, 0, len(tenantList.Items))
for i := range tenantList.Items {
modelTenant := telemetry.TransformReportOBTenant(&tenantList.Items[i])
reportData.Tenants = append(reportData.Tenants, *modelTenant)
}

backupPolicyList := v1alpha1.OBTenantBackupPolicyList{}
err = oceanbase.BackupPolicyClient.List(c, corev1.NamespaceAll, &backupPolicyList, metav1.ListOptions{})
if err != nil {
return nil, httpErr.NewInternal(err.Error())
}
reportData.BackupPolicies = make([]models.OBBackupPolicy, 0, len(backupPolicyList.Items))
for i := range backupPolicyList.Items {
modelBackupPolicy := telemetry.TransformReportOBBackupPolicy(&backupPolicyList.Items[i])
reportData.BackupPolicies = append(reportData.BackupPolicies, *modelBackupPolicy)
}

clt := client.GetClient()
eventList, err := clt.ClientSet.CoreV1().Events(corev1.NamespaceAll).List(c, metav1.ListOptions{FieldSelector: "type=Warning"})
if err != nil {
return nil, httpErr.NewInternal(err.Error())
}
reportData.WarningEvents = make([]models.K8sEvent, 0, len(eventList.Items))
for i := range eventList.Items {
modelEvent := &models.K8sEvent{
Reason: eventList.Items[i].Reason,
Message: eventList.Items[i].Message,
Name: eventList.Items[i].Name,
Namespace: eventList.Items[i].Namespace,
LastTimestamp: eventList.Items[i].LastTimestamp.Format(time.DateTime),
FirstTimestamp: eventList.Items[i].FirstTimestamp.Format(time.DateTime),
Count: eventList.Items[i].Count,
Kind: eventList.Items[i].InvolvedObject.Kind,
ResourceName: eventList.Items[i].InvolvedObject.Name,
}
reportData.WarningEvents = append(reportData.WarningEvents, *modelEvent)
}
reportData.Version = Version

currentTime := time.Now()

return &response.StatisticDataResponse{
Component: telemetry.TelemetryComponentDashboard,
Time: currentTime.Format(time.DateTime),
Content: &reportData,
}, nil
}

// @ID GetStatistics
// @Summary get telemetry data
// @Description get telemetry data
// @Tags Info
// @Accept application/json
// @Produce application/json
// @Success 200 object response.APIResponse{data=response.StatisticDataResponse}
// @Failure 400 object response.APIResponse
// @Failure 401 object response.APIResponse
// @Failure 500 object response.APIResponse
// @Router /api/v1/metrics/telemetry [GET]
// @Router /api/v1/metrics/statistic [GET]
// @Security ApiKeyAuth
func GetStatistics(c *gin.Context) (*response.StatisticDataResponse, error) {
reportData := response.StatisticData{}
Expand Down
2 changes: 1 addition & 1 deletion internal/dashboard/router/v1/metric_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ import (
func InitMetricRoutes(g *gin.RouterGroup) {
g.GET("/metrics", h.Wrap(h.ListMetricMetas))
g.POST("/metrics/query", h.Wrap(h.QueryMetrics))
g.GET("/metrics/telemetry", h.Wrap(h.GetStatistics))
g.GET("/metrics/statistic", h.Wrap(h.GetStatistics))
}

0 comments on commit a47fe9c

Please sign in to comment.