diff --git a/internal/dashboard/generated/swagger/docs.go b/internal/dashboard/generated/swagger/docs.go index 18989700d..892eca151 100644 --- a/internal/dashboard/generated/swagger/docs.go +++ b/internal/dashboard/generated/swagger/docs.go @@ -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" ], @@ -657,7 +657,7 @@ const docTemplate = `{ "tags": [ "Info" ], - "summary": "get telemetry data", + "summary": "get statistic data", "operationId": "GetStatistics", "responses": { "200": { diff --git a/internal/dashboard/generated/swagger/swagger.json b/internal/dashboard/generated/swagger/swagger.json index 4e6d6ffaf..945b2e66a 100644 --- a/internal/dashboard/generated/swagger/swagger.json +++ b/internal/dashboard/generated/swagger/swagger.json @@ -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" ], @@ -650,7 +650,7 @@ "tags": [ "Info" ], - "summary": "get telemetry data", + "summary": "get statistic data", "operationId": "GetStatistics", "responses": { "200": { diff --git a/internal/dashboard/generated/swagger/swagger.yaml b/internal/dashboard/generated/swagger/swagger.yaml index 9efe8d1c5..94c046d05 100644 --- a/internal/dashboard/generated/swagger/swagger.yaml +++ b/internal/dashboard/generated/swagger/swagger.yaml @@ -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 @@ -1727,7 +1727,7 @@ paths: $ref: '#/definitions/response.APIResponse' security: - ApiKeyAuth: [] - summary: get telemetry data + summary: get statistic data tags: - Info /api/v1/obclusters: diff --git a/internal/dashboard/handler/info_handler.go b/internal/dashboard/handler/info_handler.go index 32a983e31..a15617308 100644 --- a/internal/dashboard/handler/info_handler.go +++ b/internal/dashboard/handler/info_handler.go @@ -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" ) @@ -59,8 +60,8 @@ 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 @@ -68,107 +69,7 @@ func GetProcessInfo(_ *gin.Context) (*response.DashboardInfo, error) { // @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{} diff --git a/internal/dashboard/router/v1/metric_router.go b/internal/dashboard/router/v1/metric_router.go index 9b6b76f74..ec7fd973b 100644 --- a/internal/dashboard/router/v1/metric_router.go +++ b/internal/dashboard/router/v1/metric_router.go @@ -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)) }