Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Health check doesn't wait for everything to start #1712

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
37 changes: 37 additions & 0 deletions pkg/api/controllers/provider/health.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2024 Daytona Platforms Inc.
// SPDX-License-Identifier: Apache-2.0

package provider

import (
"fmt"
"net/http"

"github.com/daytonaio/daytona/pkg/api/controllers/provider/dto"
"github.com/daytonaio/daytona/pkg/server"
"github.com/gin-gonic/gin"
)

// HealthCheck godoc
//
// @Tags provider
// @Summary Provider health check
// @Description Provider health check
// @Success 200
// @Router /provider/health [get]
// @id HealthCheck
func HealthCheck(ctx *gin.Context) {
var req dto.Provider
err := ctx.BindJSON(&req)
if err != nil {
ctx.AbortWithError(http.StatusBadRequest, fmt.Errorf("invalid request body: %w", err))
return
}
server := server.GetInstance(nil)
exist := server.ProviderManager.IsInitialized(req.Name)
if !exist {
ctx.AbortWithError(http.StatusInternalServerError, fmt.Errorf("failed to initialize provider: %w", err))
return
}
ctx.Status(200)
}
1 change: 1 addition & 0 deletions pkg/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ func (a *ApiServer) Start() error {
providerController.GET("/", provider.ListProviders)
providerController.POST("/:provider/uninstall", provider.UninstallProvider)
providerController.GET("/:provider/target-manifest", provider.GetTargetManifest)
providerController.GET("/health", provider.HealthCheck)
}

containerRegistryController := protected.Group("/container-registry")
Expand Down
9 changes: 9 additions & 0 deletions pkg/provider/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type IProviderManager interface {
TerminateProviderProcesses(providersBasePath string) error
UninstallProvider(name string) error
Purge() error
IsInitialized(providerName string) bool
}

type ProviderManagerConfig struct {
Expand Down Expand Up @@ -335,3 +336,11 @@ func (m *ProviderManager) dispenseProvider(client *plugin.Client, name string) (

return &provider, nil
}

func (m *ProviderManager) IsInitialized(providerName string) bool {
pluginRef, exists := m.pluginRefs[providerName]
if !exists {
return false
}
return pluginRef != nil
}
Loading