Skip to content

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.

feat(web): add support for generating web settings types (#11445)

Vikrant Guptad1f143f6752c
diff --git a/.github/workflows/goci.yaml b/.github/workflows/goci.yaml
index e86728b9bb..16a2ed767f 100644
--- a/.github/workflows/goci.yaml
+++ b/.github/workflows/goci.yaml
@@ -123,3 +123,20 @@ jobs:
run: |
go run cmd/enterprise/*.go generate authz
git diff --compact-summary --exit-code || (echo; echo "Unexpected difference in authz permissions. Run go run cmd/enterprise/*.go generate authz locally and commit."; exit 1)
+ web-settings:
+ if: |
+ github.event_name == 'merge_group' ||
+ (github.event_name == 'pull_request' && ! github.event.pull_request.head.repo.fork && github.event.pull_request.user.login != 'dependabot[bot]' && ! contains(github.event.pull_request.labels.*.name, 'safe-to-test')) ||
+ (github.event_name == 'pull_request_target' && contains(github.event.pull_request.labels.*.name, 'safe-to-test'))
+ runs-on: ubuntu-latest
+ steps:
+ - name: self-checkout
+ uses: actions/checkout@v4
+ - name: go-install
+ uses: actions/setup-go@v5
+ with:
+ go-version: "1.24"
+ - name: generate-web-settings
+ run: |
+ go run cmd/enterprise/*.go generate config web-settings
+ git diff --compact-summary --exit-code || (echo; echo "Unexpected difference in web settings schema. Run go run cmd/enterprise/*.go generate config web-settings locally and commit."; exit 1)
diff --git a/.github/workflows/jsci.yaml b/.github/workflows/jsci.yaml
index 9b7ac5d4d4..6cc52e93e7 100644
--- a/.github/workflows/jsci.yaml
+++ b/.github/workflows/jsci.yaml
@@ -90,3 +90,26 @@ jobs:
run: |
cd frontend && pnpm generate:api
git diff --compact-summary --exit-code || (echo; echo "Unexpected difference in generated api clients. Run pnpm generate:api in frontend/ locally and commit."; exit 1)
+ web-settings:
+ if: |
+ github.event_name == 'merge_group' ||
+ (github.event_name == 'pull_request' && ! github.event.pull_request.head.repo.fork && github.event.pull_request.user.login != 'dependabot[bot]' && ! contains(github.event.pull_request.labels.*.name, 'safe-to-test')) ||
+ (github.event_name == 'pull_request_target' && contains(github.event.pull_request.labels.*.name, 'safe-to-test'))
+ runs-on: ubuntu-latest
+ steps:
+ - name: self-checkout
+ uses: actions/checkout@v4
+ - name: node-install
+ uses: actions/setup-node@v5
+ with:
+ node-version: "22"
+ - name: install-pnpm
+ uses: pnpm/action-setup@v6
+ with:
+ version: 10
+ - name: install-frontend
+ run: cd frontend && pnpm install
+ - name: generate-web-settings
+ run: |
+ cd frontend && pnpm generate:config:web-settings
+ git diff --compact-summary --exit-code || (echo; echo "Unexpected difference in generated web settings types. Run pnpm generate:config:web-settings in frontend/ locally and commit."; exit 1)
diff --git a/cmd/genconfig.go b/cmd/genconfig.go
new file mode 100644
index 0000000000..335cc69238
--- /dev/null
+++ b/cmd/genconfig.go
@@ -0,0 +1,61 @@
+package cmd
+
+import (
+ "encoding/json"
+ "os"
+ "reflect"
+ "strings"
+
+ "github.com/SigNoz/signoz/pkg/web"
+ "github.com/spf13/cobra"
+ "github.com/swaggest/jsonschema-go"
+)
+
+const webSettingsSchemaPath = "docs/config/web-settings.json"
+
+func registerGenerateConfig(parentCmd *cobra.Command) {
+ configCmd := &cobra.Command{
+ Use: "config",
+ Short: "Generate JSON Schema for config",
+ }
+
+ configCmd.AddCommand(&cobra.Command{
+ Use: "web-settings",
+ Short: "Generate JSON Schema for web settings",
+ RunE: func(currCmd *cobra.Command, args []string) error {
+ return generateWebSettings()
+ },
+ })
+
+ parentCmd.AddCommand(configCmd)
+}
+
+func generateWebSettings() error {
+ falseVal := false
+ noAdditional := jsonschema.SchemaOrBool{TypeBoolean: &falseVal}
+
+ reflector := jsonschema.Reflector{}
+ reflector.DefaultOptions = append(reflector.DefaultOptions,
+ jsonschema.InterceptSchema(func(params jsonschema.InterceptSchemaParams) (bool, error) {
+ if params.Value.Kind() == reflect.Struct {
+ params.Schema.AdditionalProperties = &noAdditional
+ }
+ return false, nil
+ }),
+ jsonschema.InterceptDefName(func(t reflect.Type, defaultDefName string) string {
+ return strings.TrimPrefix(defaultDefName, "Web")
+ }),
+ )
+
+ schema, err := reflector.Reflect(web.Settings{})
+ if err != nil {
+ return err
+ }
+
+ data, err := json.MarshalIndent(schema, "", " ")
+ if err != nil {
+ return err
+ }
+
+ return os.WriteFile(webSettingsSchemaPath, append(data, '\n'), 0o600)
+}
diff --git a/cmd/generate.go b/cmd/generate.go
index 8a986a1207..37c4938803 100644
--- a/cmd/generate.go
+++ b/cmd/generate.go
@@ -17,6 +17,7 @@ func RegisterGenerate(parentCmd *cobra.Command, logger *slog.Logger) {
registerGenerateOpenAPI(generateCmd)
registerGenerateAuthz(generateCmd)
+ registerGenerateConfig(generateCmd)
parentCmd.AddCommand(generateCmd)
}
diff --git a/docs/config/web-settings.json b/docs/config/web-settings.json
new file mode 100644
index 0000000000..4ae155c359
--- /dev/null
+++ b/docs/config/web-settings.json
@@ -0,0 +1,42 @@
+{
+ "required": [
+ "posthog",
+ "appcues"
+ ],
+ "additionalProperties": false,
+ "definitions": {
+ "Appcues": {
+ "required": [
+ "enabled"
+ ],
+ "additionalProperties": false,
+ "properties": {
+ "enabled": {
+ "type": "boolean"
+ }
+ },
+ "type": "object"
+ },
+ "Posthog": {
+ "required": [
+ "enabled"
+ ],
+ "additionalProperties": false,
+ "properties": {
+ "enabled": {
+ "type": "boolean"
+ }
+ },
+ "type": "object"
+ }
+ },
+ "properties": {
+ "appcues": {
+ "$ref": "#/definitions/Appcues"
+ },
+ "posthog": {
+ "$ref": "#/definitions/Posthog"
+ }
+ },
+ "type": "object"
+}
diff --git a/frontend/package.json b/frontend/package.json
index 6bcf21d05d..6fa0c103b9 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -24,7 +24,8 @@
"commitlint": "commitlint --edit $1",
"test": "jest",
"test:changedsince": "jest --changedSince=main --coverage --silent",
- "generate:api": "orval --config ./orval.config.ts && sh scripts/post-types-generation.sh"
+ "generate:api": "orval --config ./orval.config.ts && sh scripts/post-types-generation.sh",
+ "generate:config:web-settings": "json2ts ../docs/config/web-settings.json -o src/types/generated/webSettings.ts --style.useTabs --style.tabWidth=1 --style.singleQuote --bannerComment '/* AUTO GENERATED FILE - DO NOT EDIT - GENERATED FROM docs/config/web-settings.json */'"
},
"engines": {
"node": ">=22.0.0",
@@ -160,8 +161,8 @@
"@testing-library/user-event": "14.4.3",
"@types/color": "^3.0.3",
"@types/crypto-js": "4.2.2",
- "@types/event-source-polyfill": "^1.0.0",
"@types/d3-hierarchy": "1.1.11",
+ "@types/event-source-polyfill": "^1.0.0",
"@types/history": "4.7.11",
"@types/jest": "30.0.0",
"@types/lodash-es": "^4.17.4",
@@ -187,6 +188,7 @@
"is-ci": "^3.0.1",
"jest-environment-jsdom": "29.7.0",
"jest-styled-components": "^7.2.0",
+ "json-schema-to-typescript": "^15.0.4",
"lint-staged": "^17.0.4",
"msw": "1.3.2",
"orval": "8.9.1",
diff --git a/frontend/pnpm-lock.yaml b/frontend/pnpm-lock.yaml
index 4261b7b94a..e0ed2139fd 100644
--- a/frontend/pnpm-lock.yaml
+++ b/frontend/pnpm-lock.yaml
@@ -449,6 +449,9 @@ importers:
jest-styled-components:
specifier: ^7.2.0
+ json-schema-to-typescript:
+ specifier: ^15.0.4
+ version: 15.0.4
lint-staged:
specifier: ^17.0.4
version: 17.0.4
@@ -457,7 +460,7 @@ importers:
version: 1.3.2([email protected])
orval:
specifier: 8.9.1
- version: 8.9.1([email protected])
oxfmt:
specifier: 0.47.0
version: 0.47.0
@@ -545,6 +548,10 @@ packages:
peerDependencies:
react: '>=16.9.0'
+ '@apidevtools/[email protected]':
+ resolution: {integrity: sha512-60vepv88RwcJtSHrD6MjIL6Ta3SOYbgfnkHb+ppAVK+o9mXprRtulx7VlRl3lN3bbvysAfCS7WMVfhUYemB0IQ==}
+ engines: {node: '>= 16'}
+
resolution: {integrity: sha512-9NhCeYjq9+3uxgdtp20LSiJXJvN0FeCtNGpJxuMFZ1Kv3cWUNb6DOhJwUvcVCzKGR66cw4njwM6hrJLqgOwbcw==}
engines: {node: '>=6.9.0'}
@@ -1991,6 +1998,9 @@ packages:
'@jridgewell/[email protected]':
resolution: {integrity: sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==}
+ '@jsdevtools/[email protected]':
+ resolution: {integrity: sha512-4JQNk+3mVzK3xh2rqd6RB4J46qUR19azEHBneZyTZM+c456qOrbbM/5xcR8huNCCcbVt7+UmizG6GuUvPvKUYg==}
+
resolution: {integrity: sha512-WbzE9sdmQtKy8vrNPa9BRnwZh5UF4s1KTmSK0KUVLo3eff5BlQNNWDnFOouNpKfPKDnms9xynJjsMYjMaT/aFQ==}
engines: {node: '>= 18'}
@@ -6066,6 +6076,11 @@ packages:
resolution: {integrity: sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==}
+ resolution: {integrity: sha512-Su9oK8DR4xCmDsLlyvadkXzX6+GGXJpbhwoLtOGArAG61dvbW4YQmSEno2y66ahpIdmLMg6YUf/QHLgiwvkrHQ==}
+ engines: {node: '>=16.0.0'}
+ hasBin: true
+
resolution: {integrity: sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==}
@@ -7104,6 +7119,11 @@ packages:
resolution: {integrity: sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==}
engines: {node: '>= 0.8.0'}
+ resolution: {integrity: sha512-7igPTM53cGHMW8xWuVTydi2KO233VFiTNyF5hLJqpilHfmn8C8gPf+PS7dUT64YcXFbiMGZxS9pCSxL/Dxm/Jw==}
+ engines: {node: '>=14'}
+ hasBin: true
+
resolution: {integrity: sha512-Qb1gy5OrP5+zDf2Bvnzdl3jsTf1qXVMazbvCoKhtKqVs4/YK4ozX4gKQJJVyNe+cajNPn0KoC0MC3FUmaHWEmQ==}
engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0}
@@ -9044,6 +9064,12 @@ snapshots:
resize-observer-polyfill: 1.5.1
throttle-debounce: 5.0.0
+ '@apidevtools/[email protected]':
+ dependencies:
+ '@jsdevtools/ono': 7.1.3
+ '@types/json-schema': 7.0.15
+ js-yaml: 4.1.1
+
dependencies:
'@babel/helper-validator-identifier': 7.28.5
@@ -10798,6 +10824,8 @@ snapshots:
'@jridgewell/sourcemap-codec': 1.5.5
optional: true
+ '@jsdevtools/[email protected]': {}
+
dependencies:
hashery: 1.5.1
@@ -15374,6 +15402,18 @@ snapshots:
+ dependencies:
+ '@apidevtools/json-schema-ref-parser': 11.9.3
+ '@types/json-schema': 7.0.15
+ '@types/lodash': 4.17.24
+ is-glob: 4.0.3
+ js-yaml: 4.1.1
+ lodash: 4.18.1
+ minimist: 1.2.8
+ prettier: 3.8.3
+ tinyglobby: 0.2.15
+
@@ -16290,7 +16330,7 @@ snapshots:
strip-ansi: 6.0.1
wcwidth: 1.0.1
dependencies:
'@commander-js/extra-typings': 14.0.0([email protected])
'@orval/angular': 8.9.1([email protected])
@@ -16321,6 +16361,8 @@ snapshots:
typedoc: 0.28.19([email protected])
typedoc-plugin-coverage: 4.0.2([email protected]([email protected]))
typedoc-plugin-markdown: 4.11.0([email protected]([email protected]))
+ optionalDependencies:
+ prettier: 3.8.3
transitivePeerDependencies:
- '@faker-js/faker'
- supports-color
@@ -16581,6 +16623,8 @@ snapshots:
+
dependencies:
ansi-regex: 5.0.1
diff --git a/frontend/src/types/generated/webSettings.ts b/frontend/src/types/generated/webSettings.ts
new file mode 100644
index 0000000000..52125098cd
--- /dev/null
+++ b/frontend/src/types/generated/webSettings.ts
@@ -0,0 +1,12 @@
+/* AUTO GENERATED FILE - DO NOT EDIT - GENERATED FROM docs/config/web-settings.json */
+
+export interface WebSettings {
+ appcues: Appcues;
+ posthog: Posthog;
+}
+export interface Appcues {
+ enabled: boolean;
+}
+export interface Posthog {
+ enabled: boolean;
+}
diff --git a/pkg/web/config.go b/pkg/web/config.go
index 54cdd9531f..d0fa45600b 100644
--- a/pkg/web/config.go
+++ b/pkg/web/config.go
@@ -15,22 +15,21 @@ type Config struct {
// The directory from which to serve the web files.
Directory string `mapstructure:"directory"`
- // Settings that are exposed to the web.
- Settings Settings `mapstructure:"settings"`
+ // Web settings configuration.
+ Settings SettingsConfig `mapstructure:"settings"`
}
-// Settings that are exposed to the web.
-type Settings struct {
- Posthog Posthog `mapstructure:"posthog"`
-
- Appcues Appcues `mapstructure:"appcues"`
+// SettingsConfig holds the configuration for web settings.
+type SettingsConfig struct {
+ Posthog PosthogConfig `mapstructure:"posthog"`
+ Appcues AppcuesConfig `mapstructure:"appcues"`
}
-type Posthog struct {
+type PosthogConfig struct {
Enabled bool `mapstructure:"enabled"`
}
-type Appcues struct {
+type AppcuesConfig struct {
Enabled bool `mapstructure:"enabled"`
}
@@ -43,11 +42,11 @@ func newConfig() factory.Config {
Enabled: true,
Index: "index.html",
Directory: "/etc/signoz/web",
- Settings: Settings{
- Posthog: Posthog{
+ Settings: SettingsConfig{
+ Posthog: PosthogConfig{
Enabled: true,
},
- Appcues: Appcues{
+ Appcues: AppcuesConfig{
Enabled: true,
},
},
diff --git a/pkg/web/routerweb/provider.go b/pkg/web/routerweb/provider.go
index 85cafd7baf..8627754f83 100644
--- a/pkg/web/routerweb/provider.go
+++ b/pkg/web/routerweb/provider.go
@@ -44,7 +44,8 @@ func New(ctx context.Context, settings factory.ProviderSettings, config web.Conf
return nil, errors.WrapInvalidInputf(err, errors.CodeInvalidInput, "cannot read %q in web directory", config.Index)
}
- settingsJSON, err := json.Marshal(config.Settings)
+ webSettings := web.NewSettings(config)
+ settingsJSON, err := json.Marshal(webSettings)
if err != nil {
return nil, errors.WrapInternalf(err, errors.CodeInternal, "cannot marshal web settings to JSON")
}
diff --git a/pkg/web/routerweb/provider_test.go b/pkg/web/routerweb/provider_test.go
index 461adf6348..6436b6c9ae 100644
--- a/pkg/web/routerweb/provider_test.go
+++ b/pkg/web/routerweb/provider_test.go
@@ -118,9 +118,9 @@ func TestServeTemplatedIndex(t *testing.T) {
webConfig: web.Config{
Index: "valid_template.html",
Directory: "testdata",
- Settings: web.Settings{
- Posthog: web.Posthog{Enabled: true},
- Appcues: web.Appcues{Enabled: true},
+ Settings: web.SettingsConfig{
+ Posthog: web.PosthogConfig{Enabled: true},
+ Appcues: web.AppcuesConfig{Enabled: true},
},
},
expected: expectedHTML("/", web.Settings{
diff --git a/pkg/web/settings.go b/pkg/web/settings.go
new file mode 100644
index 0000000000..5c60eae8d5
--- /dev/null
+++ b/pkg/web/settings.go
@@ -0,0 +1,25 @@
+package web
+
+type Settings struct {
+ Posthog Posthog `json:"posthog" required:"true"`
+ Appcues Appcues `json:"appcues" required:"true"`
+}
+
+type Posthog struct {
+ Enabled bool `json:"enabled" required:"true"`
+}
+
+type Appcues struct {
+ Enabled bool `json:"enabled" required:"true"`
+}
+
+func NewSettings(config Config) Settings {
+ return Settings{
+ Posthog: Posthog{
+ Enabled: config.Settings.Posthog.Enabled,
+ },
+ Appcues: Appcues{
+ Enabled: config.Settings.Appcues.Enabled,
+ },
+ }
+}