Skip to content

Commit

Permalink
Merge pull request #1 from stakefish/feat/remove-feature
Browse files Browse the repository at this point in the history
add container CI and remove validator_delegation requests
  • Loading branch information
RicoToothless authored Apr 6, 2022
2 parents 62067f4 + e036375 commit 5f82aef
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 59 deletions.
40 changes: 37 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
name: goreleaser
name: goreleaser and container

on:
push:
tags:
- '*'

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

permissions:
contents: write

Expand All @@ -16,11 +20,41 @@ jobs:
- uses: actions/setup-go@v2
with:
go-version: '1.16.5'
-
name: Run GoReleaser
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for container
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push container image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
32 changes: 32 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM golang:1.18-alpine as builder

RUN apk update && \
apk add --no-cache ca-certificates git && \
update-ca-certificates

RUN adduser -D -g '' appuser

WORKDIR /app

ENV CGO_ENABLED=0

COPY go.mod .
COPY go.sum .
RUN go mod download
RUN go mod verify

COPY . .
RUN go build -o /go/bin/cosmos-exporter -ldflags '-extldflags "-static"'

# second step to build minimal image
FROM scratch

# add common trusted certificates from the build stage
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /etc/passwd /etc/passwd

USER appuser

COPY --from=builder /go/bin/cosmos-exporter /go/bin/cosmos-exporter

ENTRYPOINT ["/go/bin/cosmos-exporter"]
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@

![Latest release](https://img.shields.io/github/v/release/solarlabsteam/cosmos-exporter)
[![Actions Status](https://github.com/solarlabsteam/cosmos-exporter/workflows/test/badge.svg)](https://github.com/solarlabsteam/cosmos-exporter/actions)
This project is forked from [solarlabsteam/cosmos-exporter](https://github.com/solarlabsteam/cosmos-exporter) with extra container release and removes heavy requests. Make this exporter more focused on operating purposes for system operators.

cosmos-exporter is a Prometheus scraper that fetches the data from a full node of a Cosmos-based blockchain via gRPC.

## Where to get container image?

```sh
docker pull ghcr.io/stakefish/cosmos-exporter:latest
```

## What can I use it for?

You can run a full node, run cosmos-exporter on the same host, set up Prometheus to scrape the data from it (see below for instructions), then set up Grafana to visualize the data coming from the exporter and probably add some alerting. Here are some examples of Grafana dashboards we created for ourselves:
Expand All @@ -15,7 +22,7 @@ You can run a full node, run cosmos-exporter on the same host, set up Prometheus

## How can I set it up?

First of all, you need to download the latest release from [the releases page](https://github.com/solarlabsteam/cosmos-exporter/releases/). After that, you should unzip it and you are ready to go:
First of all, you need to download the latest release from [the releases page](https://github.com/stakefish/cosmos-exporter/releases/). After that, you should unzip it and you are ready to go:

```sh
wget <the link from the releases page>
Expand Down
55 changes: 0 additions & 55 deletions validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,6 @@ func ValidatorHandler(w http.ResponseWriter, r *http.Request, grpcConn *grpc.Cli
return
}

validatorDelegationsGauge := prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "cosmos_validator_delegations",
Help: "Delegations of the Cosmos-based blockchain validator",
ConstLabels: ConstLabels,
},
[]string{"address", "moniker", "denom", "delegated_by"},
)

validatorTokensGauge := prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "cosmos_validator_tokens",
Expand Down Expand Up @@ -153,7 +144,6 @@ func ValidatorHandler(w http.ResponseWriter, r *http.Request, grpcConn *grpc.Cli
)

registry := prometheus.NewRegistry()
registry.MustRegister(validatorDelegationsGauge)
registry.MustRegister(validatorTokensGauge)
registry.MustRegister(validatorDelegatorSharesGauge)
registry.MustRegister(validatorCommissionRateGauge)
Expand Down Expand Up @@ -251,51 +241,6 @@ func ValidatorHandler(w http.ResponseWriter, r *http.Request, grpcConn *grpc.Cli

var wg sync.WaitGroup

go func() {
defer wg.Done()

sublogger.Debug().
Str("address", address).
Msg("Started querying validator delegations")
queryStart := time.Now()

stakingClient := stakingtypes.NewQueryClient(grpcConn)
stakingRes, err := stakingClient.ValidatorDelegations(
context.Background(),
&stakingtypes.QueryValidatorDelegationsRequest{ValidatorAddr: myAddress.String()},
)
if err != nil {
sublogger.Error().
Str("address", address).
Err(err).
Msg("Could not get validator delegations")
return
}

sublogger.Debug().
Str("address", address).
Float64("request-time", time.Since(queryStart).Seconds()).
Msg("Finished querying validator delegations")

for _, delegation := range stakingRes.DelegationResponses {
value, err := strconv.ParseFloat(delegation.Balance.Amount.String(), 64)
if err != nil {
log.Error().
Err(err).
Str("address", address).
Msg("Could not convert delegation entry")
} else {
validatorDelegationsGauge.With(prometheus.Labels{
"moniker": validator.Validator.Description.Moniker,
"address": delegation.Delegation.ValidatorAddress,
"denom": Denom,
"delegated_by": delegation.Delegation.DelegatorAddress,
}).Set(value / DenomCoefficient)
}
}
}()
wg.Add(1)

go func() {
defer wg.Done()

Expand Down

0 comments on commit 5f82aef

Please sign in to comment.