-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
See merge request Blockdaemon/solana/pyth_exporter!1
- Loading branch information
Showing
14 changed files
with
1,638 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# IDE | ||
.idea/ | ||
|
||
# Pyth | ||
*keypair.json | ||
.pythd/ | ||
keystore | ||
|
||
# Env vars | ||
*.env | ||
!docker.example.env | ||
|
||
# Binaries | ||
/pyth_exporter |
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,40 @@ | ||
include: | ||
- template: Jobs/Build.gitlab-ci.yml | ||
- template: Jobs/Code-Intelligence.gitlab-ci.yml | ||
- template: Security/SAST.gitlab-ci.yml | ||
- template: Security/Container-Scanning.gitlab-ci.yml | ||
- template: Security/License-Scanning.gitlab-ci.yml | ||
- template: Security/Secret-Detection.gitlab-ci.yml | ||
- template: Security/Dependency-Scanning.gitlab-ci.yml | ||
|
||
stages: | ||
- build | ||
- test | ||
|
||
.go-cache: | ||
image: golang:1.17-alpine | ||
variables: | ||
GOPATH: $CI_PROJECT_DIR/.go | ||
GOPRIVATE: go.blockdaemon.com,gitlab.com/Blockdaemon | ||
before_script: | ||
- mkdir -p .go build/ | ||
- apk add --no-cache build-base linux-headers git | ||
- git config --global url."https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com/".insteadOf "https://gitlab.com/" | ||
cache: | ||
paths: | ||
- .go/pkg/mod/ | ||
|
||
lint: | ||
image: registry.gitlab.com/gitlab-org/gitlab-build-images:golangci-lint-alpine | ||
stage: test | ||
allow_failure: true | ||
extends: .go-cache | ||
needs: [] | ||
script: | ||
- '[ -e .golangci.yml ] || cp /golangci/.golangci.yml .' | ||
- golangci-lint run --issues-exit-code 0 --out-format code-climate | tee gl-code-quality-report.json | jq -r '.[] | "\(.location.path):\(.location.lines.begin) \(.description)"' | ||
artifacts: | ||
reports: | ||
codequality: gl-code-quality-report.json | ||
paths: | ||
- gl-code-quality-report.json |
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,7 @@ | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.1.0 | ||
hooks: | ||
- id: trailing-whitespace | ||
- id: end-of-file-fixer | ||
- id: mixed-line-ending |
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,9 @@ | ||
FROM golang:1.17-alpine as builder | ||
WORKDIR /app | ||
COPY . . | ||
RUN go build -ldflags="-w -s" -o /app/pyth_exporter . | ||
|
||
FROM alpine | ||
RUN apk add ca-certificates | ||
COPY --from=builder /app/pyth_exporter /pyth_exporter | ||
ENTRYPOINT ["/pyth_exporter"] |
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,52 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/gagliardetto/solana-go" | ||
"github.com/gagliardetto/solana-go/rpc" | ||
"github.com/prometheus/client_golang/prometheus" | ||
"go.blockdaemon.com/pyth_exporter/metrics" | ||
"go.uber.org/zap" | ||
) | ||
|
||
// balanceScraper retrieves the Pyth publisher balances on request. | ||
type balanceScraper struct { | ||
*prometheus.GaugeVec | ||
|
||
log *zap.Logger | ||
rpc *rpc.Client | ||
publishers []solana.PublicKey | ||
} | ||
|
||
func newBalanceScraper(publishers []solana.PublicKey, rpcURL string, log *zap.Logger) *balanceScraper { | ||
return &balanceScraper{ | ||
GaugeVec: metrics.PublisherBalances, | ||
rpc: rpc.New(rpcURL), | ||
log: log, | ||
publishers: publishers, | ||
} | ||
} | ||
|
||
// Collect gets invoked by the Prometheus exporter when a new scrape is requested. | ||
func (b *balanceScraper) Collect(metrics chan<- prometheus.Metric) { | ||
const collectTimeout = 5 * time.Second | ||
ctx, cancel := context.WithTimeout(context.Background(), collectTimeout) | ||
defer cancel() | ||
b.update(ctx) | ||
b.GaugeVec.Collect(metrics) | ||
} | ||
|
||
func (b *balanceScraper) update(ctx context.Context) { | ||
res, err := b.rpc.GetMultipleAccounts(ctx, b.publishers...) | ||
if err != nil { | ||
b.log.Warn("Failed to check publisher SOL balances", zap.Error(err)) | ||
return | ||
} | ||
for i, acc := range res.Value { | ||
b.GaugeVec. | ||
WithLabelValues(b.publishers[i].String()). | ||
Set(float64(acc.Lamports)) | ||
} | ||
} |
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,59 @@ | ||
module go.blockdaemon.com/pyth_exporter | ||
|
||
go 1.17 | ||
|
||
require ( | ||
github.com/cenkalti/backoff/v4 v4.1.2 | ||
github.com/gagliardetto/binary v0.6.1 | ||
github.com/gagliardetto/solana-go v1.3.0 | ||
github.com/prometheus/client_golang v1.12.1 | ||
go.uber.org/zap v1.16.0 | ||
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a | ||
) | ||
|
||
require ( | ||
contrib.go.opencensus.io/exporter/stackdriver v0.13.4 // indirect | ||
filippo.io/edwards25519 v1.0.0-rc.1 // indirect | ||
github.com/andres-erbsen/clock v0.0.0-20160526145045-9e14626cd129 // indirect | ||
github.com/aybabtme/rgbterm v0.0.0-20170906152045-cc83f3b3ce59 // indirect | ||
github.com/beorn7/perks v1.0.1 // indirect | ||
github.com/blendle/zapdriver v1.3.1 // indirect | ||
github.com/buger/jsonparser v1.1.1 // indirect | ||
github.com/cespare/xxhash/v2 v2.1.2 // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/dfuse-io/logging v0.0.0-20210109005628-b97a57253f70 // indirect | ||
github.com/fatih/color v1.9.0 // indirect | ||
github.com/gagliardetto/treeout v0.1.4 // indirect | ||
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect | ||
github.com/golang/protobuf v1.5.2 // indirect | ||
github.com/gorilla/rpc v1.2.0 // indirect | ||
github.com/gorilla/websocket v1.4.2 // indirect | ||
github.com/json-iterator/go v1.1.12 // indirect | ||
github.com/klauspost/compress v1.13.6 // indirect | ||
github.com/logrusorgru/aurora v2.0.3+incompatible // indirect | ||
github.com/mattn/go-colorable v0.1.4 // indirect | ||
github.com/mattn/go-isatty v0.0.11 // indirect | ||
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect | ||
github.com/mitchellh/go-testing-interface v1.14.1 // indirect | ||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | ||
github.com/modern-go/reflect2 v1.0.2 // indirect | ||
github.com/mostynb/zstdpool-freelist v0.0.0-20201229113212-927304c0c3b1 // indirect | ||
github.com/mr-tron/base58 v1.2.0 // indirect | ||
github.com/prometheus/client_model v0.2.0 // indirect | ||
github.com/prometheus/common v0.32.1 // indirect | ||
github.com/prometheus/procfs v0.7.3 // indirect | ||
github.com/teris-io/shortid v0.0.0-20201117134242-e59966efd125 // indirect | ||
github.com/tidwall/gjson v1.9.3 // indirect | ||
github.com/tidwall/match v1.1.1 // indirect | ||
github.com/tidwall/pretty v1.2.0 // indirect | ||
go.opencensus.io v0.22.5 // indirect | ||
go.uber.org/atomic v1.7.0 // indirect | ||
go.uber.org/multierr v1.6.0 // indirect | ||
go.uber.org/ratelimit v0.2.0 // indirect | ||
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a // indirect | ||
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 // indirect | ||
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf // indirect | ||
google.golang.org/protobuf v1.26.0 // indirect | ||
) | ||
|
||
replace github.com/gagliardetto/solana-go => github.com/Blockdaemon/solana-go v0.5.2-0.20220222095515-4a3ecddb010b |
Oops, something went wrong.