update the PR
This commit is contained in:
@@ -114,7 +114,6 @@ func initPlugins(ctx context.Context, mgr *plugin.Manager, telemetryCfg *otelset
|
|||||||
// newServer creates and initializes the HTTP server.
|
// newServer creates and initializes the HTTP server.
|
||||||
func newServer(ctx context.Context, mgr handler.PluginManager, cfg *Config, otelProvider *telemetry.Provider) (http.Handler, error) {
|
func newServer(ctx context.Context, mgr handler.PluginManager, cfg *Config, otelProvider *telemetry.Provider) (http.Handler, error) {
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
mux.HandleFunc("/health", handler.HealthHandler)
|
|
||||||
|
|
||||||
if otelProvider != nil && otelProvider.MetricsHandler != nil {
|
if otelProvider != nil && otelProvider.MetricsHandler != nil {
|
||||||
mux.Handle("/metrics", otelProvider.MetricsHandler)
|
mux.Handle("/metrics", otelProvider.MetricsHandler)
|
||||||
|
|||||||
@@ -29,6 +29,9 @@ var handlerProviders = map[handler.Type]Provider{
|
|||||||
// It iterates over the module configurations, retrieves appropriate handler providers,
|
// It iterates over the module configurations, retrieves appropriate handler providers,
|
||||||
// and registers the handlers with the HTTP multiplexer.
|
// and registers the handlers with the HTTP multiplexer.
|
||||||
func Register(ctx context.Context, mCfgs []Config, mux *http.ServeMux, mgr handler.PluginManager) error {
|
func Register(ctx context.Context, mCfgs []Config, mux *http.ServeMux, mgr handler.PluginManager) error {
|
||||||
|
|
||||||
|
mux.Handle("/health", http.HandlerFunc(handler.HealthHandler))
|
||||||
|
|
||||||
log.Debugf(ctx, "Registering modules with config: %#v", mCfgs)
|
log.Debugf(ctx, "Registering modules with config: %#v", mCfgs)
|
||||||
// Iterate over the handlers in the configuration.
|
// Iterate over the handlers in the configuration.
|
||||||
for _, c := range mCfgs {
|
for _, c := range mCfgs {
|
||||||
|
|||||||
@@ -123,6 +123,16 @@ func TestRegisterSuccess(t *testing.T) {
|
|||||||
if capturedModuleName != "test-module" {
|
if capturedModuleName != "test-module" {
|
||||||
t.Errorf("expected module_id in context to be 'test-module', got %v", capturedModuleName)
|
t.Errorf("expected module_id in context to be 'test-module', got %v", capturedModuleName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Verifying /health endpoint registration
|
||||||
|
reqHealth := httptest.NewRequest(http.MethodGet, "/health", nil)
|
||||||
|
recHealth := httptest.NewRecorder()
|
||||||
|
mux.ServeHTTP(recHealth, reqHealth)
|
||||||
|
|
||||||
|
if status := recHealth.Code; status != http.StatusOK {
|
||||||
|
t.Errorf("handler for /health returned wrong status code: got %v want %v",
|
||||||
|
status, http.StatusOK)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestRegisterFailure tests scenarios where the handler registration should fail.
|
// TestRegisterFailure tests scenarios where the handler registration should fail.
|
||||||
|
|||||||
Reference in New Issue
Block a user