Skip to content

Commit

Permalink
feat: add preheat otel (#741)
Browse files Browse the repository at this point in the history
* feat: add preheat otel

Signed-off-by: Gaius <[email protected]>
  • Loading branch information
gaius-qi authored Oct 21, 2021
1 parent ca4b65b commit 1a8b040
Show file tree
Hide file tree
Showing 29 changed files with 408 additions and 383 deletions.
10 changes: 9 additions & 1 deletion manager/config/constant_otel.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,13 @@ package config
import "go.opentelemetry.io/otel/attribute"

const (
AttributeID = attribute.Key("d7y.manager.id")
AttributeID = attribute.Key("d7y.manager.id")
AttributePreheatType = attribute.Key("d7y.manager.preheat.type")
AttributePreheatURL = attribute.Key("d7y.manager.preheat.url")
)

const (
SpanPreheat = "preheat"
SpanGetLayers = "get-layers"
SpanAuthWithRegistry = "auth-with-registry"
)
12 changes: 6 additions & 6 deletions manager/handlers/cdn.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (h *Handlers) CreateCDN(ctx *gin.Context) {
return
}

cdn, err := h.service.CreateCDN(json)
cdn, err := h.service.CreateCDN(ctx.Request.Context(), json)
if err != nil {
ctx.Error(err)
return
Expand All @@ -68,7 +68,7 @@ func (h *Handlers) DestroyCDN(ctx *gin.Context) {
return
}

if err := h.service.DestroyCDN(params.ID); err != nil {
if err := h.service.DestroyCDN(ctx.Request.Context(), params.ID); err != nil {
ctx.Error(err)
return
}
Expand Down Expand Up @@ -101,7 +101,7 @@ func (h *Handlers) UpdateCDN(ctx *gin.Context) {
return
}

cdn, err := h.service.UpdateCDN(params.ID, json)
cdn, err := h.service.UpdateCDN(ctx.Request.Context(), params.ID, json)
if err != nil {
ctx.Error(err)
return
Expand All @@ -128,7 +128,7 @@ func (h *Handlers) GetCDN(ctx *gin.Context) {
return
}

cdn, err := h.service.GetCDN(params.ID)
cdn, err := h.service.GetCDN(ctx.Request.Context(), params.ID)
if err != nil {
ctx.Error(err)
return
Expand Down Expand Up @@ -157,13 +157,13 @@ func (h *Handlers) GetCDNs(ctx *gin.Context) {
}

h.setPaginationDefault(&query.Page, &query.PerPage)
cdns, err := h.service.GetCDNs(query)
cdns, err := h.service.GetCDNs(ctx.Request.Context(), query)
if err != nil {
ctx.Error(err)
return
}

totalCount, err := h.service.CDNTotalCount(query)
totalCount, err := h.service.CDNTotalCount(ctx.Request.Context(), query)
if err != nil {
ctx.Error(err)
return
Expand Down
20 changes: 10 additions & 10 deletions manager/handlers/cdn_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (h *Handlers) CreateCDNCluster(ctx *gin.Context) {
}

if json.SecurityGroupDomain != "" {
cdn, err := h.service.CreateCDNClusterWithSecurityGroupDomain(json)
cdn, err := h.service.CreateCDNClusterWithSecurityGroupDomain(ctx.Request.Context(), json)
if err != nil {
ctx.Error(err)
return
Expand All @@ -52,7 +52,7 @@ func (h *Handlers) CreateCDNCluster(ctx *gin.Context) {
return
}

cdnCluster, err := h.service.CreateCDNCluster(json)
cdnCluster, err := h.service.CreateCDNCluster(ctx.Request.Context(), json)
if err != nil {
ctx.Error(err)
return
Expand All @@ -79,7 +79,7 @@ func (h *Handlers) DestroyCDNCluster(ctx *gin.Context) {
return
}

if err := h.service.DestroyCDNCluster(params.ID); err != nil {
if err := h.service.DestroyCDNCluster(ctx.Request.Context(), params.ID); err != nil {
ctx.Error(err)
return
}
Expand Down Expand Up @@ -113,7 +113,7 @@ func (h *Handlers) UpdateCDNCluster(ctx *gin.Context) {
}

if json.SecurityGroupDomain != "" {
cdn, err := h.service.UpdateCDNClusterWithSecurityGroupDomain(params.ID, json)
cdn, err := h.service.UpdateCDNClusterWithSecurityGroupDomain(ctx.Request.Context(), params.ID, json)
if err != nil {
ctx.Error(err)
return
Expand All @@ -123,7 +123,7 @@ func (h *Handlers) UpdateCDNCluster(ctx *gin.Context) {
return
}

cdnCluster, err := h.service.UpdateCDNCluster(params.ID, json)
cdnCluster, err := h.service.UpdateCDNCluster(ctx.Request.Context(), params.ID, json)
if err != nil {
ctx.Error(err)
return
Expand All @@ -150,7 +150,7 @@ func (h *Handlers) GetCDNCluster(ctx *gin.Context) {
return
}

cdnCluster, err := h.service.GetCDNCluster(params.ID)
cdnCluster, err := h.service.GetCDNCluster(ctx.Request.Context(), params.ID)
if err != nil {
ctx.Error(err)
return
Expand Down Expand Up @@ -179,13 +179,13 @@ func (h *Handlers) GetCDNClusters(ctx *gin.Context) {
}

h.setPaginationDefault(&query.Page, &query.PerPage)
cdns, err := h.service.GetCDNClusters(query)
cdns, err := h.service.GetCDNClusters(ctx.Request.Context(), query)
if err != nil {
ctx.Error(err)
return
}

totalCount, err := h.service.CDNClusterTotalCount(query)
totalCount, err := h.service.CDNClusterTotalCount(ctx.Request.Context(), query)
if err != nil {
ctx.Error(err)
return
Expand Down Expand Up @@ -214,7 +214,7 @@ func (h *Handlers) AddCDNToCDNCluster(ctx *gin.Context) {
return
}

if err := h.service.AddCDNToCDNCluster(params.ID, params.CDNID); err != nil {
if err := h.service.AddCDNToCDNCluster(ctx.Request.Context(), params.ID, params.CDNID); err != nil {
ctx.Error(err)
return
}
Expand All @@ -241,7 +241,7 @@ func (h *Handlers) AddSchedulerClusterToCDNCluster(ctx *gin.Context) {
return
}

if err := h.service.AddSchedulerClusterToCDNCluster(params.ID, params.SchedulerClusterID); err != nil {
if err := h.service.AddSchedulerClusterToCDNCluster(ctx.Request.Context(), params.ID, params.SchedulerClusterID); err != nil {
ctx.Error(err)
return
}
Expand Down
12 changes: 6 additions & 6 deletions manager/handlers/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (h *Handlers) CreateOauth(ctx *gin.Context) {
return
}

oauth, err := h.service.CreateOauth(json)
oauth, err := h.service.CreateOauth(ctx.Request.Context(), json)
if err != nil {
ctx.Error(err)
return
Expand All @@ -68,7 +68,7 @@ func (h *Handlers) DestroyOauth(ctx *gin.Context) {
return
}

if err := h.service.DestroyOauth(params.ID); err != nil {
if err := h.service.DestroyOauth(ctx.Request.Context(), params.ID); err != nil {
ctx.Error(err)
return
}
Expand Down Expand Up @@ -101,7 +101,7 @@ func (h *Handlers) UpdateOauth(ctx *gin.Context) {
return
}

oauth, err := h.service.UpdateOauth(params.ID, json)
oauth, err := h.service.UpdateOauth(ctx.Request.Context(), params.ID, json)
if err != nil {
ctx.Error(err)
return
Expand All @@ -128,7 +128,7 @@ func (h *Handlers) GetOauth(ctx *gin.Context) {
return
}

oauth, err := h.service.GetOauth(params.ID)
oauth, err := h.service.GetOauth(ctx.Request.Context(), params.ID)
if err != nil {
ctx.Error(err)
return
Expand Down Expand Up @@ -157,13 +157,13 @@ func (h *Handlers) GetOauths(ctx *gin.Context) {
}

h.setPaginationDefault(&query.Page, &query.PerPage)
oauth, err := h.service.GetOauths(query)
oauth, err := h.service.GetOauths(ctx.Request.Context(), query)
if err != nil {
ctx.Error(err)
return
}

totalCount, err := h.service.OauthTotalCount(query)
totalCount, err := h.service.OauthTotalCount(ctx.Request.Context(), query)
if err != nil {
ctx.Error(err)
return
Expand Down
2 changes: 1 addition & 1 deletion manager/handlers/permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ import (
// @Router /permissions [get]
func (h *Handlers) GetPermissions(g *gin.Engine) func(ctx *gin.Context) {
return func(ctx *gin.Context) {
ctx.JSON(http.StatusOK, h.service.GetPermissions(g))
ctx.JSON(http.StatusOK, h.service.GetPermissions(ctx.Request.Context(), g))
}
}
8 changes: 4 additions & 4 deletions manager/handlers/preheat.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (h *Handlers) CreatePreheat(ctx *gin.Context) {
return
}

preheat, err := h.service.CreatePreheat(json)
preheat, err := h.service.CreatePreheat(ctx.Request.Context(), json)
if err != nil {
ctx.Error(err)
return
Expand All @@ -68,7 +68,7 @@ func (h *Handlers) GetPreheat(ctx *gin.Context) {
return
}

preheat, err := h.service.GetPreheat(params.ID)
preheat, err := h.service.GetPreheat(ctx.Request.Context(), params.ID)
if err != nil {
ctx.Error(err)
return
Expand All @@ -95,7 +95,7 @@ func (h *Handlers) CreateV1Preheat(ctx *gin.Context) {
return
}

preheat, err := h.service.CreateV1Preheat(json)
preheat, err := h.service.CreateV1Preheat(ctx.Request.Context(), json)
if err != nil {
ctx.Error(err)
return
Expand All @@ -122,7 +122,7 @@ func (h *Handlers) GetV1Preheat(ctx *gin.Context) {
return
}

preheat, err := h.service.GetV1Preheat(params.ID)
preheat, err := h.service.GetV1Preheat(ctx.Request.Context(), params.ID)
if err != nil {
ctx.Error(err)
return
Expand Down
12 changes: 6 additions & 6 deletions manager/handlers/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (h *Handlers) CreateRole(ctx *gin.Context) {
return
}

if err := h.service.CreateRole(json); err != nil {
if err := h.service.CreateRole(ctx.Request.Context(), json); err != nil {
ctx.Error(err)
return
}
Expand All @@ -65,7 +65,7 @@ func (h *Handlers) DestroyRole(ctx *gin.Context) {
return
}

if ok, err := h.service.DestroyRole(params.Role); err != nil {
if ok, err := h.service.DestroyRole(ctx.Request.Context(), params.Role); err != nil {
ctx.Error(err)
return
} else if !ok {
Expand Down Expand Up @@ -93,7 +93,7 @@ func (h *Handlers) GetRole(ctx *gin.Context) {
return
}

ctx.JSON(http.StatusOK, h.service.GetRole(params.Role))
ctx.JSON(http.StatusOK, h.service.GetRole(ctx.Request.Context(), params.Role))
}

// @Summary Get Roles
Expand All @@ -106,7 +106,7 @@ func (h *Handlers) GetRole(ctx *gin.Context) {
// @Failure 500
// @Router /roles [get]
func (h *Handlers) GetRoles(ctx *gin.Context) {
roles := h.service.GetRoles()
roles := h.service.GetRoles(ctx.Request.Context())
ctx.JSON(http.StatusOK, roles)
}

Expand Down Expand Up @@ -134,7 +134,7 @@ func (h *Handlers) AddPermissionForRole(ctx *gin.Context) {
return
}

if ok, err := h.service.AddPermissionForRole(params.Role, json); err != nil {
if ok, err := h.service.AddPermissionForRole(ctx.Request.Context(), params.Role, json); err != nil {
ctx.Error(err)
return
} else if !ok {
Expand Down Expand Up @@ -169,7 +169,7 @@ func (h *Handlers) DeletePermissionForRole(ctx *gin.Context) {
return
}

if ok, err := h.service.DeletePermissionForRole(params.Role, json); err != nil {
if ok, err := h.service.DeletePermissionForRole(ctx.Request.Context(), params.Role, json); err != nil {
ctx.Error(err)
return
} else if !ok {
Expand Down
12 changes: 6 additions & 6 deletions manager/handlers/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (h *Handlers) CreateScheduler(ctx *gin.Context) {
return
}

scheduler, err := h.service.CreateScheduler(json)
scheduler, err := h.service.CreateScheduler(ctx.Request.Context(), json)
if err != nil {
ctx.Error(err)
return
Expand All @@ -68,7 +68,7 @@ func (h *Handlers) DestroyScheduler(ctx *gin.Context) {
return
}

if err := h.service.DestroyScheduler(params.ID); err != nil {
if err := h.service.DestroyScheduler(ctx.Request.Context(), params.ID); err != nil {
ctx.Error(err)
return
}
Expand Down Expand Up @@ -101,7 +101,7 @@ func (h *Handlers) UpdateScheduler(ctx *gin.Context) {
return
}

scheduler, err := h.service.UpdateScheduler(params.ID, json)
scheduler, err := h.service.UpdateScheduler(ctx.Request.Context(), params.ID, json)
if err != nil {
ctx.Error(err)
return
Expand All @@ -128,7 +128,7 @@ func (h *Handlers) GetScheduler(ctx *gin.Context) {
return
}

scheduler, err := h.service.GetScheduler(params.ID)
scheduler, err := h.service.GetScheduler(ctx.Request.Context(), params.ID)
if err != nil {
ctx.Error(err)
return
Expand Down Expand Up @@ -157,13 +157,13 @@ func (h *Handlers) GetSchedulers(ctx *gin.Context) {
}

h.setPaginationDefault(&query.Page, &query.PerPage)
schedulers, err := h.service.GetSchedulers(query)
schedulers, err := h.service.GetSchedulers(ctx.Request.Context(), query)
if err != nil {
ctx.Error(err)
return
}

totalCount, err := h.service.SchedulerTotalCount(query)
totalCount, err := h.service.SchedulerTotalCount(ctx.Request.Context(), query)
if err != nil {
ctx.Error(err)
return
Expand Down
Loading

0 comments on commit 1a8b040

Please sign in to comment.