SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.
TypeScript apmapplication-monitoringdistributed-tracinggogood-first-issuejaegerloglogsmetricsmonitoringnextjsobservabilityopen-sourceopentelemetryprometheusreactreactjsself-hostedtracingtypescript
feat(global): add global config support (#9826)
Vikrant Gupta0c059df3275a
diff --git a/conf/example.yaml b/conf/example.yamlindex 0aba8b8773..3fc1120b40 100644--- a/conf/example.yaml+++ b/conf/example.yaml@@ -3,6 +3,13 @@# Do not modify this file#+##################### Global #####################+global:+ # the url under which the signoz apiserver is externally reachable.+ external_url: <unset>+ # the url where the SigNoz backend receives telemetry data (traces, metrics, logs) from instrumented applications.+ ingestion_url: <unset>+##################### Version #####################version:banner:diff --git a/docs/api/openapi.yml b/docs/api/openapi.ymlindex 7ed96f1d4d..0b1414be94 100644--- a/docs/api/openapi.yml+++ b/docs/api/openapi.yml@@ -473,6 +473,49 @@ paths:summary: Get reset password tokentags:- users+ /api/v1/global/config:+ get:+ deprecated: false+ description: This endpoints returns global config+ operationId: GetGlobalConfig+ responses:+ "200":+ content:+ application/json:+ schema:+ properties:+ data:+ $ref: '#/components/schemas/TypesGettableGlobalConfig'+ status:+ type: string+ type: object+ description: OK+ "401":+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/RenderErrorResponse'+ description: Unauthorized+ "403":+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/RenderErrorResponse'+ description: Forbidden+ "500":+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/RenderErrorResponse'+ description: Internal Server Error+ security:+ - api_key:+ - EDITOR+ - tokenizer:+ - EDITOR+ summary: Get global config+ tags:+ - global/api/v1/invite:get:deprecated: false@@ -2145,6 +2188,13 @@ components:userId:type: stringtype: object+ TypesGettableGlobalConfig:+ properties:+ external_url:+ type: string+ ingestion_url:+ type: string+ type: objectTypesInvite:properties:createdAt:diff --git a/pkg/apiserver/signozapiserver/global.go b/pkg/apiserver/signozapiserver/global.gonew file mode 100644index 0000000000..0de19a853d--- /dev/null+++ b/pkg/apiserver/signozapiserver/global.go@@ -0,0 +1,30 @@+package signozapiserver++import (+ "net/http"++ "github.com/SigNoz/signoz/pkg/http/handler"+ "github.com/SigNoz/signoz/pkg/types"+ "github.com/gorilla/mux"+)++func (provider *provider) addGlobalRoutes(router *mux.Router) error {+ if err := router.Handle("/api/v1/global/config", handler.New(provider.authZ.EditAccess(provider.globalHandler.GetConfig), handler.OpenAPIDef{+ ID: "GetGlobalConfig",+ Tags: []string{"global"},+ Summary: "Get global config",+ Description: "This endpoints returns global config",+ Request: nil,+ RequestContentType: "",+ Response: new(types.GettableGlobalConfig),+ ResponseContentType: "application/json",+ SuccessStatusCode: http.StatusOK,+ ErrorStatusCodes: []int{},+ Deprecated: false,+ SecuritySchemes: newSecuritySchemes(types.RoleEditor),+ })).Methods(http.MethodGet).GetError(); err != nil {+ return err+ }++ return nil+}diff --git a/pkg/apiserver/signozapiserver/provider.go b/pkg/apiserver/signozapiserver/provider.goindex f166425629..b2cfbb6a1f 100644--- a/pkg/apiserver/signozapiserver/provider.go+++ b/pkg/apiserver/signozapiserver/provider.go@@ -6,6 +6,7 @@ import ("github.com/SigNoz/signoz/pkg/apiserver""github.com/SigNoz/signoz/pkg/authz""github.com/SigNoz/signoz/pkg/factory"+ "github.com/SigNoz/signoz/pkg/global""github.com/SigNoz/signoz/pkg/http/handler""github.com/SigNoz/signoz/pkg/http/middleware""github.com/SigNoz/signoz/pkg/modules/authdomain"@@ -28,6 +29,7 @@ type provider struct {sessionHandler session.HandlerauthDomainHandler authdomain.HandlerpreferenceHandler preference.Handler+ globalHandler global.Handler}func NewFactory(@@ -38,9 +40,10 @@ func NewFactory(sessionHandler session.Handler,authDomainHandler authdomain.Handler,preferenceHandler preference.Handler,+ globalHandler global.Handler,) factory.ProviderFactory[apiserver.APIServer, apiserver.Config] {return factory.NewProviderFactory(factory.MustNewName("signoz"), func(ctx context.Context, providerSettings factory.ProviderSettings, config apiserver.Config) (apiserver.APIServer, error) {- return newProvider(ctx, providerSettings, config, orgGetter, authz, orgHandler, userHandler, sessionHandler, authDomainHandler, preferenceHandler)+ return newProvider(ctx, providerSettings, config, orgGetter, authz, orgHandler, userHandler, sessionHandler, authDomainHandler, preferenceHandler, globalHandler)})}@@ -55,6 +58,7 @@ func newProvider(sessionHandler session.Handler,authDomainHandler authdomain.Handler,preferenceHandler preference.Handler,+ globalHandler global.Handler,) (apiserver.APIServer, error) {settings := factory.NewScopedProviderSettings(providerSettings, "github.com/SigNoz/signoz/pkg/apiserver/signozapiserver")router := mux.NewRouter().UseEncodedPath()@@ -68,6 +72,7 @@ func newProvider(sessionHandler: sessionHandler,authDomainHandler: authDomainHandler,preferenceHandler: preferenceHandler,+ globalHandler: globalHandler,}provider.authZ = middleware.NewAuthZ(settings.Logger(), orgGetter, authz)@@ -104,6 +109,10 @@ func (provider *provider) AddToRouter(router *mux.Router) error {return err}+ if err := provider.addGlobalRoutes(router); err != nil {+ return err+ }+return nil}diff --git a/pkg/global/config.go b/pkg/global/config.gonew file mode 100644index 0000000000..39900807ed--- /dev/null+++ b/pkg/global/config.go@@ -0,0 +1,41 @@+package global++import (+ "net/url"++ "github.com/SigNoz/signoz/pkg/errors"++ "github.com/SigNoz/signoz/pkg/factory"+)++var (+ ErrCodeInvalidGlobalConfig = errors.MustNewCode("invalid_global_config")+)++type Config struct {+ ExternalURL *url.URL `mapstructure:"external_url"`+ IngestionURL *url.URL `mapstructure:"ingestion_url"`+}++func NewConfigFactory() factory.ConfigFactory {+ return factory.NewConfigFactory(factory.MustNewName("global"), newConfig)+}++func newConfig() factory.Config {+ return &Config{+ ExternalURL: &url.URL{+ Scheme: "",+ Host: "<unset>",+ Path: "",+ },+ IngestionURL: &url.URL{+ Scheme: "",+ Host: "<unset>",+ Path: "",+ },+ }+}++func (c Config) Validate() error {+ return nil+}diff --git a/pkg/global/global.go b/pkg/global/global.gonew file mode 100644index 0000000000..e78f2ecd03--- /dev/null+++ b/pkg/global/global.go@@ -0,0 +1,11 @@+package global++import "net/http"++type Global interface {+ GetConfig() Config+}++type Handler interface {+ GetConfig(http.ResponseWriter, *http.Request)+}diff --git a/pkg/global/signozglobal/handler.go b/pkg/global/signozglobal/handler.gonew file mode 100644index 0000000000..7572e9aead--- /dev/null+++ b/pkg/global/signozglobal/handler.go@@ -0,0 +1,23 @@+package signozglobal++import (+ "net/http"++ "github.com/SigNoz/signoz/pkg/global"+ "github.com/SigNoz/signoz/pkg/http/render"+ "github.com/SigNoz/signoz/pkg/types"+)++type handler struct {+ global global.Global+}++func NewHandler(global global.Global) global.Handler {+ return &handler{global: global}+}++func (handker *handler) GetConfig(rw http.ResponseWriter, r *http.Request) {+ cfg := handker.global.GetConfig()++ render.Success(rw, http.StatusOK, types.NewGettableGlobalConfig(cfg.ExternalURL, cfg.IngestionURL))+}diff --git a/pkg/global/signozglobal/provider.go b/pkg/global/signozglobal/provider.gonew file mode 100644index 0000000000..cb9878da88--- /dev/null+++ b/pkg/global/signozglobal/provider.go@@ -0,0 +1,31 @@+package signozglobal++import (+ "context"++ "github.com/SigNoz/signoz/pkg/factory"+ "github.com/SigNoz/signoz/pkg/global"+)++type provider struct {+ config global.Config+ settings factory.ScopedProviderSettings+}++func NewFactory() factory.ProviderFactory[global.Global, global.Config] {+ return factory.NewProviderFactory(factory.MustNewName("signoz"), func(ctx context.Context, providerSettings factory.ProviderSettings, config global.Config) (global.Global, error) {+ return newProvider(ctx, providerSettings, config)+ })+}++func newProvider(_ context.Context, providerSettings factory.ProviderSettings, config global.Config) (global.Global, error) {+ settings := factory.NewScopedProviderSettings(providerSettings, "github.com/SigNoz/signoz/pkg/global/signozglobal")+ return &provider{+ config: config,+ settings: settings,+ }, nil+}++func (provider *provider) GetConfig() global.Config {+ return provider.config+}diff --git a/pkg/signoz/config.go b/pkg/signoz/config.goindex 7bc4c9a895..f5f3083048 100644--- a/pkg/signoz/config.go+++ b/pkg/signoz/config.go@@ -18,6 +18,7 @@ import ("github.com/SigNoz/signoz/pkg/errors""github.com/SigNoz/signoz/pkg/factory""github.com/SigNoz/signoz/pkg/gateway"+ "github.com/SigNoz/signoz/pkg/global""github.com/SigNoz/signoz/pkg/instrumentation""github.com/SigNoz/signoz/pkg/modules/metricsexplorer""github.com/SigNoz/signoz/pkg/prometheus"@@ -39,6 +40,9 @@ import (// Config defines the entire input configuration of signoz.type Config struct {+ // Global config+ Global global.Config `mapstructure:"global"`+// Version configVersion version.Config `mapstructure:"version"`@@ -141,6 +145,7 @@ func (df *DeprecatedFlags) RegisterFlags(cmd *cobra.Command) {func NewConfig(ctx context.Context, logger *slog.Logger, resolverConfig config.ResolverConfig, deprecatedFlags DeprecatedFlags) (Config, error) {configFactories := []factory.ConfigFactory{+ global.NewConfigFactory(),version.NewConfigFactory(),instrumentation.NewConfigFactory(),analytics.NewConfigFactory(),diff --git a/pkg/signoz/handler.go b/pkg/signoz/handler.goindex 1baaa622fc..c959fee2a9 100644--- a/pkg/signoz/handler.go+++ b/pkg/signoz/handler.go@@ -2,6 +2,8 @@ package signozimport ("github.com/SigNoz/signoz/pkg/factory"+ "github.com/SigNoz/signoz/pkg/global"+ "github.com/SigNoz/signoz/pkg/global/signozglobal""github.com/SigNoz/signoz/pkg/licensing""github.com/SigNoz/signoz/pkg/modules/apdex""github.com/SigNoz/signoz/pkg/modules/apdex/implapdex"@@ -34,9 +36,10 @@ type Handlers struct {SpanPercentile spanpercentile.HandlerServices services.HandlerMetricsExplorer metricsexplorer.Handler+ Global global.Handler}-func NewHandlers(modules Modules, providerSettings factory.ProviderSettings, querier querier.Querier, licensing licensing.Licensing) Handlers {+func NewHandlers(modules Modules, providerSettings factory.ProviderSettings, querier querier.Querier, licensing licensing.Licensing, global global.Global) Handlers {return Handlers{SavedView: implsavedview.NewHandler(modules.SavedView),Apdex: implapdex.NewHandler(modules.Apdex),@@ -47,5 +50,6 @@ func NewHandlers(modules Modules, providerSettings factory.ProviderSettings, queServices: implservices.NewHandler(modules.Services),MetricsExplorer: implmetricsexplorer.NewHandler(modules.MetricsExplorer),SpanPercentile: implspanpercentile.NewHandler(modules.SpanPercentile),+ Global: signozglobal.NewHandler(global),}}diff --git a/pkg/signoz/handler_test.go b/pkg/signoz/handler_test.goindex db131500d0..72907155ec 100644--- a/pkg/signoz/handler_test.go+++ b/pkg/signoz/handler_test.go@@ -40,7 +40,7 @@ func TestNewHandlers(t *testing.T) {require.NoError(t, err)modules := NewModules(sqlstore, tokenizer, emailing, providerSettings, orgGetter, alertmanager, nil, nil, nil, nil, nil, nil, nil, queryParser, Config{})- handlers := NewHandlers(modules, providerSettings, nil, nil)+ handlers := NewHandlers(modules, providerSettings, nil, nil, nil)reflectVal := reflect.ValueOf(handlers)for i := 0; i < reflectVal.NumField(); i++ {diff --git a/pkg/signoz/openapi.go b/pkg/signoz/openapi.goindex b797a2da53..0bdd23d172 100644--- a/pkg/signoz/openapi.go+++ b/pkg/signoz/openapi.go@@ -8,6 +8,7 @@ import ("github.com/SigNoz/signoz/pkg/apiserver""github.com/SigNoz/signoz/pkg/apiserver/signozapiserver""github.com/SigNoz/signoz/pkg/authz"+ "github.com/SigNoz/signoz/pkg/global""github.com/SigNoz/signoz/pkg/http/handler""github.com/SigNoz/signoz/pkg/instrumentation""github.com/SigNoz/signoz/pkg/modules/authdomain"@@ -36,6 +37,7 @@ func NewOpenAPI(ctx context.Context, instrumentation instrumentation.Instrumentastruct{ session.Handler }{},struct{ authdomain.Handler }{},struct{ preference.Handler }{},+ struct{ global.Handler }{},).New(ctx, instrumentation.ToProviderSettings(), apiserver.Config{})if err != nil {return nil, errdiff --git a/pkg/signoz/provider.go b/pkg/signoz/provider.goindex d8fa7cd3ab..9e30ce3850 100644--- a/pkg/signoz/provider.go+++ b/pkg/signoz/provider.go@@ -18,6 +18,8 @@ import ("github.com/SigNoz/signoz/pkg/emailing/noopemailing""github.com/SigNoz/signoz/pkg/emailing/smtpemailing""github.com/SigNoz/signoz/pkg/factory"+ "github.com/SigNoz/signoz/pkg/global"+ "github.com/SigNoz/signoz/pkg/global/signozglobal""github.com/SigNoz/signoz/pkg/modules/authdomain/implauthdomain""github.com/SigNoz/signoz/pkg/modules/organization""github.com/SigNoz/signoz/pkg/modules/organization/implorganization"@@ -221,7 +223,7 @@ func NewQuerierProviderFactories(telemetryStore telemetrystore.TelemetryStore, p)}-func NewAPIServerProviderFactories(orgGetter organization.Getter, authz authz.AuthZ, modules Modules, handlers Handlers) factory.NamedMap[factory.ProviderFactory[apiserver.APIServer, apiserver.Config]] {+func NewAPIServerProviderFactories(orgGetter organization.Getter, authz authz.AuthZ, global global.Global, modules Modules, handlers Handlers) factory.NamedMap[factory.ProviderFactory[apiserver.APIServer, apiserver.Config]] {return factory.MustNewNamedMap(signozapiserver.NewFactory(orgGetter,@@ -231,6 +233,7 @@ func NewAPIServerProviderFactories(orgGetter organization.Getter, authz authz.Auimplsession.NewHandler(modules.Session),implauthdomain.NewHandler(modules.AuthDomain),implpreference.NewHandler(modules.Preference),+ signozglobal.NewHandler(global),),)}@@ -242,3 +245,9 @@ func NewTokenizerProviderFactories(cache cache.Cache, sqlstore sqlstore.SQLStorejwttokenizer.NewFactory(cache, tokenStore),)}++func NewGlobalProviderFactories() factory.NamedMap[factory.ProviderFactory[global.Global, global.Config]] {+ return factory.MustNewNamedMap(+ signozglobal.NewFactory(),+ )+}diff --git a/pkg/signoz/provider_test.go b/pkg/signoz/provider_test.goindex 2601aa76e2..92847f3793 100644--- a/pkg/signoz/provider_test.go+++ b/pkg/signoz/provider_test.go@@ -83,6 +83,7 @@ func TestNewProviderFactories(t *testing.T) {NewAPIServerProviderFactories(implorganization.NewGetter(implorganization.NewStore(sqlstoretest.New(sqlstore.Config{Provider: "sqlite"}, sqlmock.QueryMatcherEqual)), nil),nil,+ nil,Modules{},Handlers{},)diff --git a/pkg/signoz/signoz.go b/pkg/signoz/signoz.goindex 60602a48e5..8ea742fd8b 100644--- a/pkg/signoz/signoz.go+++ b/pkg/signoz/signoz.go@@ -345,18 +345,29 @@ func New(telemetrymetadata.AttributesMetadataLocalTableName,)+ global, err := factory.NewProviderFromNamedMap(+ ctx,+ providerSettings,+ config.Global,+ NewGlobalProviderFactories(),+ "signoz",+ )+ if err != nil {+ return nil, err+ }+// Initialize all modulesmodules := NewModules(sqlstore, tokenizer, emailing, providerSettings, orgGetter, alertmanager, analytics, querier, telemetrystore, telemetryMetadataStore, authNs, authz, cache, queryParser, config)// Initialize all handlers for the modules- handlers := NewHandlers(modules, providerSettings, querier, licensing)+ handlers := NewHandlers(modules, providerSettings, querier, licensing, global)// Initialize the API serverapiserver, err := factory.NewProviderFromNamedMap(ctx,providerSettings,config.APIServer,- NewAPIServerProviderFactories(orgGetter, authz, modules, handlers),+ NewAPIServerProviderFactories(orgGetter, authz, global, modules, handlers),"signoz",)if err != nil {diff --git a/pkg/types/global.go b/pkg/types/global.gonew file mode 100644index 0000000000..3278725549--- /dev/null+++ b/pkg/types/global.go@@ -0,0 +1,15 @@+package types++import "net/url"++type GettableGlobalConfig struct {+ ExternalURL string `json:"external_url"`+ IngestionURL string `json:"ingestion_url"`+}++func NewGettableGlobalConfig(externalURL, ingestionURL *url.URL) *GettableGlobalConfig {+ return &GettableGlobalConfig{+ ExternalURL: externalURL.String(),+ IngestionURL: ingestionURL.String(),+ }+}