Skip to content

Commit 2593827

Browse files
feat: add jsonschema for config file and fix readme (#227)
### Description OB-XXX Please explain the changes you made here. ### Checklist - [ ] Created tests which fail without the change (if possible) - [ ] Extended the README / documentation, if necessary
1 parent ad8496f commit 2593827

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+6075
-4
lines changed

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,9 @@ build-ocb:
6464
install-tools:
6565
cd ./internal/tools && go install go.opentelemetry.io/collector/cmd/mdatagen
6666

67+
68+
## generate-jsonschema: Generates JSON schema from config
69+
generate-jsonschema:
70+
go run ./scripts/generate_jsonschema.go
71+
6772
.PHONY: all vendor build go-test release install-ocb build-ocb install-tools

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ This section lists the components that are included in the Observe Distribution
8787
| [prometheus][prometheusreceiver] | | | | |
8888
| [redis][redisreceiver] | | | | |
8989
| [snmp][snmpreceiver] | | | | |
90+
| [sqlquery][sqlqueryreceiver] | | | | |
9091
| [statsd][statsdreceiver] | | | | |
9192
| [tcplog][tcplogreceiver] | | | | |
9293
| [udplog][udplogreceiver] | | | | |
@@ -111,6 +112,7 @@ This section lists the components that are included in the Observe Distribution
111112
[prometheusreceiver]: https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/v0.124.0/receiver/prometheusreceiver
112113
[redisreceiver]: https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/v0.124.0/receiver/redisreceiver
113114
[snmpreceiver]: https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/v0.124.0/receiver/snmpreceiver
115+
[sqlqueryreceiver]: https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/v0.124.0/receiver/sqlqueryreceiver
114116
[statsdreceiver]: https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/v0.124.0/receiver/statsdreceiver
115117
[tcplogreceiver]: https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/v0.124.0/receiver/tcplogreceiver
116118
[udplogreceiver]: https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/v0.124.0/receiver/udplogreceiver
@@ -133,7 +135,7 @@ This section lists the components that are included in the Observe Distribution
133135
[debugexporter]: https://github.com/open-telemetry/opentelemetry-collector/tree/v0.124.0/exporter/debugexporter
134136
[fileexporter]: https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/v0.124.0/exporter/fileexporter
135137
[loadbalancingexporter]: https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/v0.124.0/exporter/loadbalancingexporter
136-
[otlphttpexporter]: https://github.com/open-telemetry/opentelemetry-collector/tree/v0.124.0/exporter/otlpexporter
138+
[otlpexporter]: https://github.com/open-telemetry/opentelemetry-collector/tree/v0.124.0/exporter/otlpexporter
137139
[otlphttpexporter]: https://github.com/open-telemetry/opentelemetry-collector/tree/v0.124.0/exporter/otlphttpexporter
138140
[prometheusremotewriteexporter]: https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/v0.124.0/exporter/prometheusremotewriteexporter
139141
[countconnector]: https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/v0.124.0/connector/countconnector

go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,11 @@ require (
7575
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.30.1 // indirect
7676
github.com/aws/aws-sdk-go-v2/service/sts v1.33.19 // indirect
7777
github.com/aws/smithy-go v1.22.3 // indirect
78+
github.com/bahlo/generic-list-go v0.2.0 // indirect
7879
github.com/bboreham/go-loser v0.0.0-20230920113527-fcc2c21820a3 // indirect
7980
github.com/beorn7/perks v1.0.1 // indirect
8081
github.com/bmatcuk/doublestar/v4 v4.8.1 // indirect
82+
github.com/buger/jsonparser v1.1.1 // indirect
8183
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
8284
github.com/cenkalti/backoff/v5 v5.0.2 // indirect
8385
github.com/cespare/xxhash/v2 v2.3.0 // indirect
@@ -172,6 +174,7 @@ require (
172174
github.com/hetznercloud/hcloud-go/v2 v2.21.0 // indirect
173175
github.com/iancoleman/strcase v0.3.0 // indirect
174176
github.com/inconshreveable/mousetrap v1.1.0 // indirect
177+
github.com/invopop/jsonschema v0.13.0 // indirect
175178
github.com/ionos-cloud/sdk-go/v6 v6.3.3 // indirect
176179
github.com/jaegertracing/jaeger-idl v0.5.0 // indirect
177180
github.com/jcmturner/aescts/v2 v2.0.0 // indirect
@@ -334,6 +337,7 @@ require (
334337
github.com/sourcegraph/conc v0.3.0 // indirect
335338
github.com/spf13/afero v1.11.0 // indirect
336339
github.com/spf13/cast v1.6.0 // indirect
340+
github.com/stoewer/go-strcase v1.3.1 // indirect
337341
github.com/stretchr/objx v0.5.2 // indirect
338342
github.com/subosito/gotenv v1.6.0 // indirect
339343
github.com/thda/tds v0.1.7 // indirect
@@ -353,6 +357,7 @@ require (
353357
github.com/ua-parser/uap-go v0.0.0-20240611065828-3a4781585db6 // indirect
354358
github.com/valyala/fastjson v1.6.4 // indirect
355359
github.com/vultr/govultr/v2 v2.17.2 // indirect
360+
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
356361
github.com/x448/float16 v0.8.4 // indirect
357362
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
358363
github.com/xdg-go/scram v1.1.2 // indirect

internal/config/configschema.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ type HealthCheckConfig struct {
4848
}
4949

5050
type ForwardingMetricsConfig struct {
51-
OutputFormat string `yaml:"output_format,omitempty" mapstructure:"output_format" default:"prometheus"`
51+
OutputFormat string `yaml:"output_format,omitempty" mapstructure:"output_format" default:"prometheus" jsonschema:"pattern=^(prometheus|otel)$"`
5252
}
5353

5454
func (config *ForwardingMetricsConfig) OtlpMetrics() bool {
@@ -79,8 +79,8 @@ type InternalTelemetryConfig struct {
7979
}
8080

8181
type AgentConfig struct {
82-
Token string `yaml:"token" mapstructure:"token"`
83-
ObserveURL string `yaml:"observe_url" mapstructure:"observe_url"`
82+
Token string `yaml:"token" mapstructure:"token" jsonschema:"required"`
83+
ObserveURL string `yaml:"observe_url" mapstructure:"observe_url" jsonschema:"required"`
8484
CloudResourceDetectors []string `yaml:"cloud_resource_detectors,omitempty" mapstructure:"cloud_resource_detectors"`
8585
Debug bool `yaml:"debug,omitempty" mapstructure:"debug"`
8686
Attributes map[string]string `yaml:"attributes,omitempty" mapstructure:"attributes"`

observe-agent.schema.json

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
{
2+
"$defs": {
3+
"AgentConfig": {
4+
"additionalProperties": false,
5+
"properties": {
6+
"attributes": {
7+
"additionalProperties": {
8+
"type": "string"
9+
},
10+
"type": "object"
11+
},
12+
"cloud_resource_detectors": {
13+
"items": {
14+
"type": "string"
15+
},
16+
"type": "array"
17+
},
18+
"debug": {
19+
"type": "boolean"
20+
},
21+
"forwarding": {
22+
"$ref": "#/$defs/ForwardingConfig"
23+
},
24+
"health_check": {
25+
"$ref": "#/$defs/HealthCheckConfig"
26+
},
27+
"host_monitoring": {
28+
"$ref": "#/$defs/HostMonitoringConfig"
29+
},
30+
"internal_telemetry": {
31+
"$ref": "#/$defs/InternalTelemetryConfig"
32+
},
33+
"observe_url": {
34+
"type": "string"
35+
},
36+
"otel_config_overrides": {
37+
"type": "object"
38+
},
39+
"resource_attributes": {
40+
"additionalProperties": {
41+
"type": "string"
42+
},
43+
"type": "object"
44+
},
45+
"self_monitoring": {
46+
"$ref": "#/$defs/SelfMonitoringConfig"
47+
},
48+
"token": {
49+
"type": "string"
50+
}
51+
},
52+
"required": [
53+
"token",
54+
"observe_url"
55+
],
56+
"type": "object"
57+
},
58+
"ForwardingConfig": {
59+
"additionalProperties": false,
60+
"properties": {
61+
"enabled": {
62+
"type": "boolean"
63+
},
64+
"metrics": {
65+
"$ref": "#/$defs/ForwardingMetricsConfig"
66+
}
67+
},
68+
"type": "object"
69+
},
70+
"ForwardingMetricsConfig": {
71+
"additionalProperties": false,
72+
"properties": {
73+
"output_format": {
74+
"pattern": "^(prometheus|otel)$",
75+
"type": "string"
76+
}
77+
},
78+
"type": "object"
79+
},
80+
"HealthCheckConfig": {
81+
"additionalProperties": false,
82+
"properties": {
83+
"enabled": {
84+
"type": "boolean"
85+
},
86+
"endpoint": {
87+
"type": "string"
88+
},
89+
"path": {
90+
"type": "string"
91+
}
92+
},
93+
"type": "object"
94+
},
95+
"HostMonitoringConfig": {
96+
"additionalProperties": false,
97+
"properties": {
98+
"enabled": {
99+
"type": "boolean"
100+
},
101+
"logs": {
102+
"$ref": "#/$defs/HostMonitoringLogsConfig"
103+
},
104+
"metrics": {
105+
"$ref": "#/$defs/HostMonitoringMetricsConfig"
106+
}
107+
},
108+
"type": "object"
109+
},
110+
"HostMonitoringHostMetricsConfig": {
111+
"additionalProperties": false,
112+
"properties": {
113+
"enabled": {
114+
"type": "boolean"
115+
}
116+
},
117+
"type": "object"
118+
},
119+
"HostMonitoringLogsConfig": {
120+
"additionalProperties": false,
121+
"properties": {
122+
"auto_multiline_detection": {
123+
"type": "boolean"
124+
},
125+
"enabled": {
126+
"type": "boolean"
127+
},
128+
"exclude": {
129+
"items": {
130+
"type": "string"
131+
},
132+
"type": "array"
133+
},
134+
"include": {
135+
"items": {
136+
"type": "string"
137+
},
138+
"type": "array"
139+
}
140+
},
141+
"type": "object"
142+
},
143+
"HostMonitoringMetricsConfig": {
144+
"additionalProperties": false,
145+
"properties": {
146+
"host": {
147+
"$ref": "#/$defs/HostMonitoringHostMetricsConfig"
148+
},
149+
"process": {
150+
"$ref": "#/$defs/HostMonitoringProcessMetricsConfig"
151+
}
152+
},
153+
"type": "object"
154+
},
155+
"HostMonitoringProcessMetricsConfig": {
156+
"additionalProperties": false,
157+
"properties": {
158+
"enabled": {
159+
"type": "boolean"
160+
}
161+
},
162+
"type": "object"
163+
},
164+
"InternalTelemetryConfig": {
165+
"additionalProperties": false,
166+
"properties": {
167+
"enabled": {
168+
"type": "boolean"
169+
},
170+
"logs": {
171+
"$ref": "#/$defs/InternalTelemetryLogsConfig"
172+
},
173+
"metrics": {
174+
"$ref": "#/$defs/InternalTelemetryMetricsConfig"
175+
}
176+
},
177+
"type": "object"
178+
},
179+
"InternalTelemetryLogsConfig": {
180+
"additionalProperties": false,
181+
"properties": {
182+
"enabled": {
183+
"type": "boolean"
184+
},
185+
"level": {
186+
"type": "string"
187+
}
188+
},
189+
"type": "object"
190+
},
191+
"InternalTelemetryMetricsConfig": {
192+
"additionalProperties": false,
193+
"properties": {
194+
"enabled": {
195+
"type": "boolean"
196+
},
197+
"host": {
198+
"type": "string"
199+
},
200+
"level": {
201+
"type": "string"
202+
},
203+
"port": {
204+
"type": "integer"
205+
}
206+
},
207+
"type": "object"
208+
},
209+
"SelfMonitoringConfig": {
210+
"additionalProperties": false,
211+
"properties": {
212+
"enabled": {
213+
"type": "boolean"
214+
}
215+
},
216+
"type": "object"
217+
}
218+
},
219+
"$id": "https://github.com/observeinc/observe-agent/internal/config/agent-config",
220+
"$ref": "#/$defs/AgentConfig",
221+
"$schema": "https://json-schema.org/draft/2020-12/schema"
222+
}

scripts/generate_jsonschema.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"os"
7+
8+
"github.com/invopop/jsonschema"
9+
"github.com/observeinc/observe-agent/internal/config"
10+
strcase "github.com/stoewer/go-strcase"
11+
)
12+
13+
func main() {
14+
r := new(jsonschema.Reflector)
15+
r.KeyNamer = strcase.SnakeCase // from package github.com/stoewer/go-strcase
16+
r.RequiredFromJSONSchemaTags = true
17+
18+
s := r.Reflect(&config.AgentConfig{})
19+
20+
schema, err := s.MarshalJSON()
21+
if err != nil {
22+
fmt.Fprintf(os.Stderr, "Error marshaling schema: %v\n", err)
23+
os.Exit(1)
24+
}
25+
26+
// Parse and pretty-print the JSON
27+
var prettyJSON interface{}
28+
if err := json.Unmarshal(schema, &prettyJSON); err != nil {
29+
fmt.Fprintf(os.Stderr, "Error parsing schema JSON: %v\n", err)
30+
os.Exit(1)
31+
}
32+
33+
prettySchema, err := json.MarshalIndent(prettyJSON, "", " ")
34+
if err != nil {
35+
fmt.Fprintf(os.Stderr, "Error pretty-printing schema: %v\n", err)
36+
os.Exit(1)
37+
}
38+
39+
// Write to file
40+
if err := os.WriteFile("observe-agent.schema.json", prettySchema, 0644); err != nil {
41+
fmt.Fprintf(os.Stderr, "Error writing schema to file: %v\n", err)
42+
os.Exit(1)
43+
}
44+
45+
fmt.Println("JSON schema written to observe-agent.schema.json")
46+
}

vendor/github.com/bahlo/generic-list-go/LICENSE

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/bahlo/generic-list-go/README.md

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)