Skip to content

Commit

Permalink
mode
Browse files Browse the repository at this point in the history
  • Loading branch information
aljo242 committed Aug 30, 2024
1 parent 0fb9422 commit 58c6e16
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 20 deletions.
25 changes: 20 additions & 5 deletions cmd/connect/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/skip-mev/connect/v2/providers/apis/marketmap"
oraclefactory "github.com/skip-mev/connect/v2/providers/factories/oracle"
mmservicetypes "github.com/skip-mev/connect/v2/service/clients/marketmap/types"
promclient "github.com/skip-mev/connect/v2/service/clients/prometheus"

Check warning on line 28 in cmd/connect/main.go

View workflow job for this annotation

GitHub Actions / Spell checking

`promclient` is not a recognized word. (unrecognized-spelling)
oracleserver "github.com/skip-mev/connect/v2/service/servers/oracle"
promserver "github.com/skip-mev/connect/v2/service/servers/prometheus"
mmtypes "github.com/skip-mev/connect/v2/x/marketmap/types"
Expand Down Expand Up @@ -83,7 +84,7 @@ var (
const (
DefaultLegacyConfigPath = "./oracle.json"

defaultValidationPeriod = 10 * time.Minute
defaultValidationPeriod = 2 * time.Minute
)

type runMode string
Expand Down Expand Up @@ -426,7 +427,17 @@ func runOracle() error {
logger.Info("running in validation mode", zap.Int("validation period",
validationPeriod))

go validate(cancel, logger)
go func(c context.CancelFunc) {
defer c()

err := validate(cfg.Metrics.PrometheusServerAddress, logger)
if err != nil {
logger.Error("failed to validate metrics", zap.Error(err))
return
}
logger.Info("shutting down after validation")

}(cancel)
}

// start server (blocks).
Expand All @@ -452,9 +463,13 @@ func overwriteMarketMapEndpoint(cfg config.OracleConfig, overwrite string) (conf
return cfg, fmt.Errorf("no market-map provider found in config")
}

func validate(c context.CancelFunc, logger *zap.Logger) {
func validate(address string, logger *zap.Logger) error {
_, err := promclient.NewClient(address, logger)

Check warning on line 467 in cmd/connect/main.go

View workflow job for this annotation

GitHub Actions / Spell checking

`promclient` is not a recognized word. (unrecognized-spelling)
if err != nil {
return err
}

time.Sleep(time.Duration(validationPeriod))

logger.Info("cancelling context after validation period")
c()
return nil
}
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,7 @@ github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfC
github.com/jmhodges/levigo v1.0.0 h1:q5EC36kV79HWeTBWsod3mG11EgStG3qArTKcvlksN1U=
github.com/jmhodges/levigo v1.0.0/go.mod h1:Q6Qx+uH3RAqyK4rFQroq9RL7mdkABMcfhEI+nNuzMJQ=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA=
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
Expand Down
16 changes: 16 additions & 0 deletions pkg/http/address.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package http

import "net"

func IsValidAddress(address string) bool {
host, port, err := net.SplitHostPort(address)
if err != nil {
return false
}

if host == "" || port == "" {
return false
}

return true
}
50 changes: 50 additions & 0 deletions service/clients/prometheus/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package prometheus

import (
"fmt"
"strings"

"github.com/prometheus/client_golang/api"
v1 "github.com/prometheus/client_golang/api/prometheus/v1"
"go.uber.org/zap"

libhttp "github.com/skip-mev/connect/v2/pkg/http"

Check warning on line 11 in service/clients/prometheus/client.go

View workflow job for this annotation

GitHub Actions / Spell checking

`libhttp` is not a recognized word. (unrecognized-spelling)
)

type Client struct {
v1.API
logger *zap.Logger
}

func NewClient(address string, logger *zap.Logger) (Client, error) {
if logger == nil {
logger = zap.NewNop()
}

logger = logger.With(zap.String("service", "prometheus_client"))
logger.Info("creating prometheus client", zap.String("address", address))

// get the prometheus server address
if address == "" || !libhttp.IsValidAddress(address) {

Check warning on line 28 in service/clients/prometheus/client.go

View workflow job for this annotation

GitHub Actions / Spell checking

`libhttp` is not a recognized word. (unrecognized-spelling)
return Client{}, fmt.Errorf("invalid prometheus server address: %s", address)
}

const httpPrefix = "http://"
if !strings.HasPrefix(address, httpPrefix) {
address = httpPrefix + address
}

// Create a Prometheus API client
client, err := api.NewClient(api.Config{
Address: address, // Address of your Prometheus server
})
if err != nil {
return Client{}, fmt.Errorf("failed to create prometheus client: %w", err)
}

// Create a new Prometheus API v1 client
return Client{
API: v1.NewAPI(client),
logger: logger,
}, nil
}
17 changes: 2 additions & 15 deletions service/servers/prometheus/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package prometheus
import (
"errors"
"fmt"
"net"
"net/http"
"time"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"go.uber.org/zap"

libhttp "github.com/skip-mev/connect/v2/pkg/http"

Check warning on line 13 in service/servers/prometheus/server.go

View workflow job for this annotation

GitHub Actions / Spell checking

`libhttp` is not a recognized word. (unrecognized-spelling)
"github.com/skip-mev/connect/v2/pkg/sync"
)

Expand All @@ -34,7 +34,7 @@ type PrometheusServer struct { //nolint
// address is set, and valid. Notice, this method does not start the server.
func NewPrometheusServer(prometheusAddress string, logger *zap.Logger) (*PrometheusServer, error) {
// get the prometheus server address
if prometheusAddress == "" || !isValidAddress(prometheusAddress) {
if prometheusAddress == "" || !libhttp.IsValidAddress(prometheusAddress) {

Check warning on line 37 in service/servers/prometheus/server.go

View workflow job for this annotation

GitHub Actions / Spell checking

`libhttp` is not a recognized word. (unrecognized-spelling)
return nil, fmt.Errorf("invalid prometheus server address: %s", prometheusAddress)
}
srv := &http.Server{
Expand Down Expand Up @@ -79,16 +79,3 @@ func (ps *PrometheusServer) Start() {
// close the done channel
close(ps.done)
}

func isValidAddress(address string) bool {
host, port, err := net.SplitHostPort(address)
if err != nil {
return false
}

if host == "" || port == "" {
return false
}

return true
}

1 comment on commit 58c6e16

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@check-spelling-bot Report

🔴 Please review

See the 📜action log or 📝 job summary for details.

Unrecognized words (2)

libhttp
promclient

These words are not needed and should be removed alr anypb anys arounds badprice beginblocker bitsets cdb cmthash commitheight Concluson coretypes cvp ddd Devation dfa endblocker goautoneg GOM goodprice IDbz incentivize initgenesis Macbook msc munnerz oraclevetypes outpkg pbk pkany pkb pkv Prce pubkeys pvks sdktypes statelessly submitters tmhash UIDs underperform unescrow unmashalling VEbz vih voteaggregator wrt

To accept these unrecognized words as correct and remove the previously acknowledged and now absent words, you could run the following commands

... in a clone of the git@github.com:skip-mev/connect.git repository
on the chore/debug-timeout branch (ℹ️ how do I use this?):

curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/prerelease/apply.pl' |
perl - 'https://github.com/skip-mev/connect/actions/runs/10637332368/attempts/1'
Available 📚 dictionaries could cover words (expected and unrecognized) not in the 📘 dictionary

This includes both expected items (800) from .github/actions/spelling/expect.txt and unrecognized words (2)

Dictionary Entries Covers Uniquely
cspell:python/src/python/python-lib.txt 2417 8 4
cspell:fullstack/dict/fullstack.txt 419 5 4
cspell:java/src/java.txt 2464 5 3
cspell:filetypes/filetypes.txt 264 4 3
cspell:java/src/java-terms.txt 920 4 1

Consider adding them (in .github/workflows/spell.yml) in jobs:/build: to extra_dictionaries:

          cspell:python/src/python/python-lib.txt
          cspell:fullstack/dict/fullstack.txt
          cspell:java/src/java.txt
          cspell:filetypes/filetypes.txt
          cspell:java/src/java-terms.txt

To stop checking additional dictionaries, add (in .github/workflows/spell.yml):

check_extra_dictionaries: ''
Warnings (1)

See the 📜action log or 📝 job summary for details.

⚠️ Warnings Count
⚠️ no-newline-at-eof 3

See ⚠️ Event descriptions for more information.

If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

🚂 If you're seeing this message and your PR is from a branch that doesn't have check-spelling,
please merge to your PR's base branch to get the version configured for your repository.

Please sign in to comment.