Skip to content

Commit

Permalink
Merge pull request #89 from nyaruka/remove_librato
Browse files Browse the repository at this point in the history
Remove librato, use latest gocommon
  • Loading branch information
rowanseymour authored Dec 13, 2024
2 parents 2a623d8 + 78d7a98 commit 1f7e63e
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 31 deletions.
20 changes: 9 additions & 11 deletions cmd/rp-indexer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ func main() {
logHandler := slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: level})
slog.SetDefault(slog.New(logHandler))

logger := slog.With("comp", "main")
logger.Info("starting indexer", "version", version, "released", date)

// if we have a DSN entry, try to initialize it
if rt.Config.SentryDSN != "" {
err := sentry.Init(sentry.ClientOptions{
Expand All @@ -60,7 +57,7 @@ func main() {

defer sentry.Flush(2 * time.Second)

logger = slog.New(
logger := slog.New(
slogmulti.Fanout(
logHandler,
slogsentry.Option{Level: slog.LevelError}.NewSentryHandler(),
Expand All @@ -70,16 +67,17 @@ func main() {
slog.SetDefault(logger)
}

log := slog.With("comp", "main")
log.Info("starting indexer", "version", version, "released", date)

rt.DB, err = sql.Open("postgres", cfg.DB)
if err != nil {
logger.Error("unable to connect to database")
log.Error("unable to connect to database", "error", err)
}

if rt.Config.DeploymentID != "dev" {
rt.CW, err = cwatch.NewService(rt.Config.AWSAccessKeyID, rt.Config.AWSSecretAccessKey, rt.Config.AWSRegion, rt.Config.CloudwatchNamespace, rt.Config.DeploymentID)
if err != nil {
logger.Error("unable to create cloudwatch service")
}
rt.CW, err = cwatch.NewService(rt.Config.AWSAccessKeyID, rt.Config.AWSSecretAccessKey, rt.Config.AWSRegion, rt.Config.CloudwatchNamespace, rt.Config.DeploymentID)
if err != nil {
log.Error("unable to create cloudwatch service", "error", err)
}

idxrs := []indexers.Indexer{
Expand All @@ -91,7 +89,7 @@ func main() {
// the rebuild argument can be become the name of the index to rebuild, e.g. --rebuild=contacts
idxr := idxrs[0]
if _, err := idxr.Index(rt, true, rt.Config.Cleanup); err != nil {
logger.Error("error during rebuilding", "error", err, "indexer", idxr.Name())
log.Error("error during rebuilding", "error", err, "indexer", idxr.Name())
}
} else {
d := indexer.NewDaemon(rt, idxrs)
Expand Down
7 changes: 0 additions & 7 deletions daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@ func NewDaemon(rt *runtime.Runtime, ixs []indexers.Indexer) *Daemon {

// Start starts this daemon
func (d *Daemon) Start() {
// if we have a librato token, configure it
if d.rt.Config.LibratoToken != "" {
analytics.RegisterBackend(analytics.NewLibrato(d.rt.Config.LibratoUsername, d.rt.Config.LibratoToken, d.rt.Config.InstanceName, time.Second, d.wg))
}

analytics.Start()

for _, i := range d.indexers {
d.startIndexer(i)
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/getsentry/sentry-go v0.30.0
github.com/lib/pq v1.10.9
github.com/nyaruka/ezconf v0.3.0
github.com/nyaruka/gocommon v1.60.1
github.com/nyaruka/gocommon v1.60.2
github.com/samber/slog-multi v1.2.4
github.com/samber/slog-sentry v1.2.2
github.com/stretchr/testify v1.10.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ github.com/naoina/toml v0.1.1 h1:PT/lllxVVN0gzzSqSlHEmP8MJB4MY2U7STGxiouV4X8=
github.com/naoina/toml v0.1.1/go.mod h1:NBIhNtsFMo3G2szEBne+bO4gS192HuIYRqfvOWb4i1E=
github.com/nyaruka/ezconf v0.3.0 h1:kGvJqVN8AHowb4HdaHAviJ0Z3yI5Pyekp1WqibFEaGk=
github.com/nyaruka/ezconf v0.3.0/go.mod h1:89GUW6EPRNLIxT7lC4LWnjWTgZeQwRoX7lBmc8ralAU=
github.com/nyaruka/gocommon v1.60.1 h1:m/BXoBQ1KVzbpmTJ5vuQrv084mWyQ6gtuX6cOeva+lM=
github.com/nyaruka/gocommon v1.60.1/go.mod h1:kFJuOq8COneV7ssfK6xgCMJ8gP8fQifLQnNXBnE4YL0=
github.com/nyaruka/gocommon v1.60.2 h1:AvvSSAV70SV49ocNtvjpdb9NlcdiA2OQAL4NYVUcuV0=
github.com/nyaruka/gocommon v1.60.2/go.mod h1:kFJuOq8COneV7ssfK6xgCMJ8gP8fQifLQnNXBnE4YL0=
github.com/nyaruka/librato v1.1.1 h1:0nTYtJLl3Sn7lX3CuHsLf+nXy1k/tGV0OjVxLy3Et4s=
github.com/nyaruka/librato v1.1.1/go.mod h1:fme1Fu1PT2qvkaBZyw8WW+SrnFe2qeeCWpvqmAaKAKE=
github.com/nyaruka/null/v2 v2.0.3 h1:rdmMRQyVzrOF3Jff/gpU/7BDR9mQX0lcLl4yImsA3kw=
Expand Down
10 changes: 0 additions & 10 deletions runtime/config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package runtime

import "os"

type Config struct {
ElasticURL string `help:"the url for our elastic search instance"`
DB string `help:"the connection string for our database"`
Expand All @@ -18,18 +16,12 @@ type Config struct {
CloudwatchNamespace string `help:"the namespace to use for cloudwatch metrics"`
DeploymentID string `help:"the deployment identifier to use for metrics"`

LibratoUsername string `help:"the username that will be used to authenticate to Librato"`
LibratoToken string `help:"the token that will be used to authenticate to Librato"`
InstanceName string `help:"the unique name of this instance used for analytics"`

ContactsIndex string `help:"the alias to use for the contact index"`
ContactsShards int `help:"the number of shards to use for the contacts index"`
ContactsReplicas int `help:"the number of replicas to use for the contacts index"`
}

func NewDefaultConfig() *Config {
hostname, _ := os.Hostname()

return &Config{
ElasticURL: "http://localhost:9200",
DB: "postgres://localhost/temba?sslmode=disable",
Expand All @@ -45,8 +37,6 @@ func NewDefaultConfig() *Config {
CloudwatchNamespace: "Temba",
DeploymentID: "dev",

InstanceName: hostname,

ContactsIndex: "contacts",
ContactsShards: 2,
ContactsReplicas: 1,
Expand Down

0 comments on commit 1f7e63e

Please sign in to comment.