Skip to content

Commit

Permalink
chore: add k8s daemonset resources
Browse files Browse the repository at this point in the history
  • Loading branch information
srikanthccv committed Nov 8, 2024
1 parent 9aa761f commit 533bbbf
Show file tree
Hide file tree
Showing 5 changed files with 539 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/query-service/app/http_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ type APIHandler struct {
clustersRepo *inframetrics.ClustersRepo
// workloads
deploymentsRepo *inframetrics.DeploymentsRepo
daemonsetsRepo *inframetrics.DaemonSetsRepo
}

type APIHandlerOpts struct {
Expand Down Expand Up @@ -196,6 +197,7 @@ func NewAPIHandler(opts APIHandlerOpts) (*APIHandler, error) {
namespacesRepo := inframetrics.NewNamespacesRepo(opts.Reader, querierv2)
clustersRepo := inframetrics.NewClustersRepo(opts.Reader, querierv2)
deploymentsRepo := inframetrics.NewDeploymentsRepo(opts.Reader, querierv2)
daemonsetsRepo := inframetrics.NewDaemonSetsRepo(opts.Reader, querierv2)

aH := &APIHandler{
reader: opts.Reader,
Expand All @@ -221,6 +223,7 @@ func NewAPIHandler(opts APIHandlerOpts) (*APIHandler, error) {
namespacesRepo: namespacesRepo,
clustersRepo: clustersRepo,
deploymentsRepo: deploymentsRepo,
daemonsetsRepo: daemonsetsRepo,
}

logsQueryBuilder := logsv3.PrepareLogsQuery
Expand Down Expand Up @@ -404,6 +407,11 @@ func (aH *APIHandler) RegisterInfraMetricsRoutes(router *mux.Router, am *AuthMid
deploymentsSubRouter.HandleFunc("/attribute_keys", am.ViewAccess(aH.getDeploymentAttributeKeys)).Methods(http.MethodGet)
deploymentsSubRouter.HandleFunc("/attribute_values", am.ViewAccess(aH.getDeploymentAttributeValues)).Methods(http.MethodGet)
deploymentsSubRouter.HandleFunc("/list", am.ViewAccess(aH.getDeploymentList)).Methods(http.MethodPost)

daemonsetsSubRouter := router.PathPrefix("/api/v1/daemonsets").Subrouter()
daemonsetsSubRouter.HandleFunc("/attribute_keys", am.ViewAccess(aH.getDaemonSetAttributeKeys)).Methods(http.MethodGet)
daemonsetsSubRouter.HandleFunc("/attribute_values", am.ViewAccess(aH.getDaemonSetAttributeValues)).Methods(http.MethodGet)
daemonsetsSubRouter.HandleFunc("/list", am.ViewAccess(aH.getDaemonSetList)).Methods(http.MethodPost)
}

func (aH *APIHandler) RegisterWebSocketPaths(router *mux.Router, am *AuthMiddleware) {
Expand Down
53 changes: 53 additions & 0 deletions pkg/query-service/app/infra.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,3 +387,56 @@ func (aH *APIHandler) getDeploymentList(w http.ResponseWriter, r *http.Request)

aH.Respond(w, deploymentList)
}

func (aH *APIHandler) getDaemonSetAttributeKeys(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
req, err := parseFilterAttributeKeyRequest(r)
if err != nil {
RespondError(w, &model.ApiError{Typ: model.ErrorInternal, Err: err}, nil)
return
}

keys, err := aH.daemonsetsRepo.GetDaemonSetAttributeKeys(ctx, *req)
if err != nil {
RespondError(w, &model.ApiError{Typ: model.ErrorInternal, Err: err}, nil)
return
}

aH.Respond(w, keys)
}

func (aH *APIHandler) getDaemonSetAttributeValues(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
req, err := parseFilterAttributeValueRequest(r)
if err != nil {
RespondError(w, &model.ApiError{Typ: model.ErrorInternal, Err: err}, nil)
return
}

values, err := aH.daemonsetsRepo.GetDaemonSetAttributeValues(ctx, *req)
if err != nil {
RespondError(w, &model.ApiError{Typ: model.ErrorInternal, Err: err}, nil)
return
}

aH.Respond(w, values)
}

func (aH *APIHandler) getDaemonSetList(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
req := model.DaemonSetListRequest{}

err := json.NewDecoder(r.Body).Decode(&req)
if err != nil {
RespondError(w, &model.ApiError{Typ: model.ErrorInternal, Err: err}, nil)
return
}

daemonSetList, err := aH.daemonsetsRepo.GetDaemonSetList(ctx, req)
if err != nil {
RespondError(w, &model.ApiError{Typ: model.ErrorInternal, Err: err}, nil)
return
}

aH.Respond(w, daemonSetList)
}
4 changes: 4 additions & 0 deletions pkg/query-service/app/inframetrics/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ func getParamsForTopDeployments(req model.DeploymentListRequest) (int64, string,
return getParamsForTopItems(req.Start, req.End)
}

func getParamsForTopDaemonSets(req model.DaemonSetListRequest) (int64, string, string) {
return getParamsForTopItems(req.Start, req.End)
}

// TODO(srikanthccv): remove this
// What is happening here?
// The `PrepareTimeseriesFilterQuery` uses the local time series table for sub-query because each fingerprint
Expand Down
Loading

0 comments on commit 533bbbf

Please sign in to comment.