-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(observability): add prometheus metrics and detailed logging (#45)
* feat: install cobra and add version command * fix: makefile targets * feat: add release-snapshot command * chore: add more detailed error logging * fix: goreleaser commands * fix: version * fix: dockerfile * feat: add prometheus counter * feat: add aggregate price provider metric * feat: add post prices prometheus counter * chore: add metrics documentation * chore: add metrics documentation
- Loading branch information
Showing
20 changed files
with
260 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,7 @@ This would allow you to run `pricefeeder` using a local instance of the network. | |
```bash | ||
git clone [email protected]:NibiruChain/nibiru.git | ||
cd nibiru | ||
git checkout v1.0.0 | ||
git checkout v1.0.3 | ||
make localnet | ||
``` | ||
|
||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package cmd | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"net/http" | ||
"os" | ||
"os/signal" | ||
|
||
"github.com/NibiruChain/nibiru/app" | ||
"github.com/NibiruChain/pricefeeder/config" | ||
"github.com/NibiruChain/pricefeeder/feeder" | ||
"github.com/NibiruChain/pricefeeder/feeder/eventstream" | ||
"github.com/NibiruChain/pricefeeder/feeder/priceposter" | ||
"github.com/NibiruChain/pricefeeder/feeder/priceprovider" | ||
"github.com/prometheus/client_golang/prometheus/promhttp" | ||
"github.com/rs/zerolog" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func setupLogger() zerolog.Logger { | ||
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix | ||
debug := flag.Bool("debug", false, "sets log level to debug") | ||
flag.Parse() | ||
// Default level is INFO, unless debug flag is present | ||
zerolog.SetGlobalLevel(zerolog.InfoLevel) | ||
if *debug { | ||
zerolog.SetGlobalLevel(zerolog.DebugLevel) | ||
} | ||
|
||
return zerolog.New(os.Stderr).With().Timestamp().Logger() | ||
} | ||
|
||
// handleInterrupt listens for SIGINT and gracefully shuts down the feeder. | ||
func handleInterrupt(logger zerolog.Logger, f *feeder.Feeder) { | ||
interrupt := make(chan os.Signal, 1) | ||
signal.Notify(interrupt, os.Interrupt) | ||
|
||
go func() { | ||
<-interrupt | ||
logger.Info().Msg("shutting down gracefully") | ||
f.Close() | ||
os.Exit(1) | ||
}() | ||
} | ||
|
||
var rootCmd = &cobra.Command{ | ||
Use: "pricefeeder", | ||
Short: "Pricefeeder daemon for posting prices to Nibiru Chain", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
logger := setupLogger() | ||
app.SetPrefixes(app.AccountAddressPrefix) | ||
|
||
c := config.MustGet() | ||
|
||
eventStream := eventstream.Dial(c.WebsocketEndpoint, c.GRPCEndpoint, c.EnableTLS, logger) | ||
priceProvider := priceprovider.NewAggregatePriceProvider(c.ExchangesToPairToSymbolMap, c.DataSourceConfigMap, logger) | ||
kb, valAddr, feederAddr := config.GetAuth(c.FeederMnemonic) | ||
|
||
if c.ValidatorAddr != nil { | ||
valAddr = *c.ValidatorAddr | ||
} | ||
pricePoster := priceposter.Dial(c.GRPCEndpoint, c.ChainID, c.EnableTLS, kb, valAddr, feederAddr, logger) | ||
|
||
f := feeder.NewFeeder(eventStream, priceProvider, pricePoster, logger) | ||
f.Run() | ||
defer f.Close() | ||
|
||
handleInterrupt(logger, f) | ||
|
||
http.Handle("/metrics", promhttp.Handler()) | ||
http.ListenAndServe(":8080", nil) | ||
|
||
select {} | ||
}, | ||
} | ||
|
||
func Execute() { | ||
if err := rootCmd.Execute(); err != nil { | ||
fmt.Fprintln(os.Stderr, err) | ||
os.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
rootCmd.AddCommand(versionCmd) | ||
} | ||
|
||
var versionCmd = &cobra.Command{ | ||
Use: "version", | ||
Short: "Print the version number of Hugo", | ||
Long: `All software has versions. This is Hugo's`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Println("v1.0.3") | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.