-
Notifications
You must be signed in to change notification settings - Fork 4
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
feat: read config from file #383
Changes from 5 commits
9cdeee2
4761bb3
0dc2da2
94c6894
9f889d0
2b99e31
dd9a8a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,20 +2,30 @@ package main | |
|
||
type ( | ||
ServiceConfig struct { | ||
Environment string `env:"SENTRY_ENVIRONMENT" env-default:"development"` | ||
Port int `env:"PORT" env-default:"8085"` | ||
Environment string `env:"SENTRY_ENVIRONMENT" yaml:"environment" env-default:"development"` | ||
Host string `env:"HOST" yaml:"host"` | ||
Port string `env:"PORT" yaml:"port" env-default:"8085"` | ||
|
||
SentryDSN string `env:"SENTRY_DSN"` | ||
SentryDSN string `env:"SENTRY_DSN" yaml:"sentry_dsn"` | ||
|
||
OccurrencesKafkaBrokers []string `env:"SENTRY_KAFKA_BROKERS_OCCURRENCES" env-default:"localhost:9092"` | ||
OccurrencesKafkaTopic string `env:"SENTRY_KAFKA_TOPIC_OCCURRENCES" env-default:"ingest-occurrences"` | ||
Occurrences struct { | ||
OccurrencesKafkaBrokers []string `env:"SENTRY_KAFKA_BROKERS_OCCURRENCES" yaml:"kafka_brokers" env-default:"localhost:9092"` | ||
OccurrencesKafkaTopic string `env:"SENTRY_KAFKA_TOPIC_OCCURRENCES" yaml:"kafka_topic" env-default:"ingest-occurrences"` | ||
} `yaml:"occurrences"` | ||
|
||
ProfilingKafkaBrokers []string `env:"SENTRY_KAFKA_BROKERS_PROFILING" env-default:"localhost:9092"` | ||
CallTreesKafkaTopic string `env:"SENTRY_KAFKA_TOPIC_CALL_TREES" env-default:"profiles-call-tree"` | ||
ProfilesKafkaTopic string `env:"SENTRY_KAKFA_TOPIC_PROFILES" env-default:"processed-profiles"` | ||
Profiling struct { | ||
ProfilingKafkaBrokers []string `env:"SENTRY_KAFKA_BROKERS_PROFILING" yaml:"kafka_brokers" env-default:"localhost:9092"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's remove the |
||
CallTreesKafkaTopic string `env:"SENTRY_KAFKA_TOPIC_CALL_TREES" yaml:"call_trees_kafka_topic" env-default:"profiles-call-tree"` | ||
ProfilesKafkaTopic string `env:"SENTRY_KAKFA_TOPIC_PROFILES" yaml:"profiles_kafka_topic" env-default:"processed-profiles"` | ||
} `yaml:"profiling"` | ||
|
||
SnubaHost string `env:"SENTRY_SNUBA_HOST" env-default:"http://localhost:1218"` | ||
SnubaHost string `env:"SENTRY_SNUBA_HOST" yaml:"snuba_host" env-default:"http://localhost:1218"` | ||
|
||
BucketURL string `env:"SENTRY_BUCKET_PROFILES" env-default:"file://./test/gcs/sentry-profiles"` | ||
BucketURL string `env:"SENTRY_BUCKET_PROFILES" yaml:"bucket_url" env-default:"file://./test/gcs/sentry-profiles"` | ||
|
||
Logging struct { | ||
Level string `env:"SENTRY_LOGGING_LEVEL" yaml:"level" env-default:"info"` | ||
Format string `env:"SENTRY_LOGGING_FORMAT" yaml:"format" env-default:"simplified"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's remove this since we only have 1 format so far. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It can be |
||
} `yaml:"logging"` | ||
} | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,9 @@ package main | |
import ( | ||
"context" | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"net" | ||
"net/http" | ||
"os" | ||
"os/signal" | ||
|
@@ -14,6 +16,7 @@ import ( | |
"github.com/CAFxX/httpcompression" | ||
"github.com/getsentry/sentry-go" | ||
sentryhttp "github.com/getsentry/sentry-go/http" | ||
"github.com/getsentry/vroom/internal/logutil" | ||
"github.com/ilyakaznacheev/cleanenv" | ||
"github.com/julienschmidt/httprouter" | ||
"github.com/rs/zerolog/log" | ||
|
@@ -26,7 +29,6 @@ import ( | |
"gocloud.dev/gcerrors" | ||
|
||
"github.com/getsentry/vroom/internal/httputil" | ||
"github.com/getsentry/vroom/internal/logutil" | ||
"github.com/getsentry/vroom/internal/snubautil" | ||
) | ||
|
||
|
@@ -50,9 +52,16 @@ const ( | |
|
||
func newEnvironment() (*environment, error) { | ||
var e environment | ||
err := cleanenv.ReadEnv(&e.config) | ||
err := cleanenv.ReadConfig("config.yml", &e.config) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer not to hardcode the filename and make it an argument like other services. |
||
if err != nil { | ||
return nil, err | ||
if errors.Is(err, os.ErrNotExist) { | ||
err := cleanenv.ReadEnv(&e.config) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} else { | ||
return nil, err | ||
} | ||
} | ||
|
||
e.snuba, err = snubautil.NewClient(e.config.SnubaHost, "profiles") | ||
|
@@ -67,16 +76,16 @@ func newEnvironment() (*environment, error) { | |
} | ||
|
||
e.occurrencesWriter = &kafka.Writer{ | ||
Addr: kafka.TCP(e.config.OccurrencesKafkaBrokers...), | ||
Addr: kafka.TCP(e.config.Occurrences.OccurrencesKafkaBrokers...), | ||
Async: true, | ||
Balancer: kafka.CRC32Balancer{}, | ||
BatchSize: 100, | ||
ReadTimeout: 3 * time.Second, | ||
Topic: e.config.OccurrencesKafkaTopic, | ||
Topic: e.config.Occurrences.OccurrencesKafkaTopic, | ||
WriteTimeout: 3 * time.Second, | ||
} | ||
e.profilingWriter = &kafka.Writer{ | ||
Addr: kafka.TCP(e.config.ProfilingKafkaBrokers...), | ||
Addr: kafka.TCP(e.config.Profiling.ProfilingKafkaBrokers...), | ||
Async: true, | ||
Balancer: kafka.CRC32Balancer{}, | ||
BatchBytes: 20 * MiB, | ||
|
@@ -165,13 +174,13 @@ func (e *environment) newRouter() (*httprouter.Router, error) { | |
} | ||
|
||
func main() { | ||
logutil.ConfigureLogger() | ||
|
||
env, err := newEnvironment() | ||
if err != nil { | ||
log.Fatal().Err(err).Msg("error setting up environment") | ||
} | ||
|
||
logutil.ConfigureLogger(env.config.Logging.Level, env.config.Logging.Format) | ||
|
||
err = sentry.Init(sentry.ClientOptions{ | ||
Dsn: env.config.SentryDSN, | ||
EnableTracing: true, | ||
|
@@ -204,7 +213,7 @@ func main() { | |
} | ||
|
||
server := http.Server{ | ||
Addr: fmt.Sprintf(":%d", env.config.Port), | ||
Addr: net.JoinHostPort(env.config.Host, env.config.Port), | ||
ReadHeaderTimeout: time.Second, | ||
Handler: sentryhttp.New(sentryhttp.Options{}).Handle(router), | ||
} | ||
|
@@ -227,7 +236,7 @@ func main() { | |
}() | ||
|
||
err = server.ListenAndServe() | ||
if err != nil && err != http.ErrServerClosed { | ||
if err != nil && !errors.Is(err, http.ErrServerClosed) { | ||
sentry.CaptureException(err) | ||
log.Err(err).Msg("server failed") | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# vroom binds to all host by default, if you want to bind to specific host, | ||
# uncomment the line below | ||
# host: | ||
port: 8085 | ||
|
||
environment: "development" | ||
|
||
sentry_dsn: "" | ||
|
||
occurrences: | ||
kafka_brokers: | ||
- "localhost:9092" | ||
kafka_topic: "ingest-occurrences" | ||
|
||
profiling: | ||
kafka_brokers: | ||
- "localhost:9092" | ||
call_trees_kafka_topic: "profiles-call-tree" | ||
profiles_kafka_topic: "processed-profiles" | ||
|
||
snuba_host: "http://localhost:1218" | ||
|
||
# The default bucket URL points to local filesystem. This bucket stores the profiles data compressed with LZ4. | ||
# For connecting to custom blob storage such as S3, GCS, or Azure Blob, change the value below. | ||
# | ||
# For S3: s3://my-bucket-name?region=us-west-1&awssdk=2&s3ForcePathStyle=false&disableSSL=true | ||
# For S3 hosted on MinIO: s3://my-bucket-name?awssdk=2&endpoint=minio.selfhosted.com&s3ForcePathStyle=true&disableSSL=true | ||
# Do provide these as environment variables (if needed): | ||
# AWS_ACCESS_KEY=foobar | ||
# AWS_SECRET_KEY=foobar | ||
# AWS_SESSION_TOKEN=foobar (not required) | ||
# | ||
# For GCS: gs://my-bucket-name | ||
# Do provide these as environment variables (if needed): | ||
# GOOGLE_APPLICATION_CREDENTIALS=foobar | ||
# | ||
# For Azure Blob: azblob://my-container?protocol=http&domain=localhost:10001&protocol=string&localemu=false&cdn=false | ||
# Do provide these as environment variables (if needed): | ||
# AZURE_STORAGE_ACCOUNT=foobar | ||
# AZURE_STORAGE_KEY=foobar | ||
# AZURE_STORAGE_SAS_TOKEN=foobar | ||
bucket_url: "file://./test/gcs/sentry-profiles" | ||
|
||
logging: | ||
# Available values are: "trace", "debug", "info", "warn", "error", "fatal", "panic", "disabled" | ||
level: "info" | ||
# "simplified" provides human-readable log on the console. | ||
# "json" provides JSON log on the console | ||
format: "simplified" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package logutil | ||
|
||
import ( | ||
"github.com/rs/zerolog" | ||
) | ||
|
||
type LevelSampler struct { | ||
Level zerolog.Level | ||
} | ||
|
||
func (l LevelSampler) Sample(lvl zerolog.Level) bool { | ||
return lvl >= l.Level | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the
Occurrences
prefix from the name.