Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Commit

Permalink
testing prometheus
Browse files Browse the repository at this point in the history
  • Loading branch information
okedeji committed Jul 3, 2024
1 parent a1ac98c commit f1f97db
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 3 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/ecr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# This workflow will build and push a new container image to Amazon ECR,
# and then will deploy a new task definition to Amazon ECS which will be run by Fargate when a release is created
name: Build and Push docker image to ECR

on:
push:
branches:
- add-prometheus-metrics


concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
jobs:
build-push:
name: Build and Push docker image
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Build, tag, and push image to Amazon ECR
id: build-push-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: worker-prometheus-test
run: |
IMAGE_TAG="test-latest"
# compute-node HEADS
ECR_REPOSITORY_HEAD="${ECR_REPOSITORY}-head"
docker build --pull -f docker/Dockerfile_head \
--build-arg "GH_TOKEN=${{ secrets.GH_READONLY_PAT }}" \
-t $ECR_REGISTRY/$ECR_REPOSITORY_HEAD:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY_HEAD:$IMAGE_TAG
# Build a docker container and push it to ECR so that it can be deployed to ECS.
# compute-node workers
docker build --pull -f docker/Dockerfile_worker \
--build-arg "GH_TOKEN=${{ secrets.GH_READONLY_PAT }}" \
-t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
24 changes: 24 additions & 0 deletions cmd/node/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import (
"github.com/allora-network/b7s/node"
"github.com/allora-network/b7s/peerstore"
"github.com/allora-network/b7s/store"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)

const (
Expand All @@ -41,6 +43,17 @@ const (
notFoundValue = -1
)

var (
opsProcessed = prometheus.NewCounter(prometheus.CounterOpts{
Name: "allora_node_operations",
Help: "The total number of processed operations",
})
)

func init() {
prometheus.MustRegister(opsProcessed)
}

func main() {
os.Exit(run())
}
Expand Down Expand Up @@ -410,6 +423,8 @@ func (e *AlloraExecutor) ExecuteFunction(requestID string, req execute.Request)
result.Result.Stdout = outputJson
}
}

opsProcessed.Inc()
return result, err
}

Expand All @@ -433,6 +448,15 @@ func run() int {
}
log = log.Level(level)

// Start HTTP server for Prometheus metrics.
http.Handle("/metrics", promhttp.Handler())
go func() {
log.Info().Msg("Starting metrics server on :2112")
if err := http.ListenAndServe(":2112", nil); err != nil {
log.Error().Err(err).Str("level", cfg.Log.Level).Msg("could not start metric server")
}
}()

// Determine node role.
role, err := parseNodeRole(cfg.Role)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile_worker
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,6 @@ RUN groupadd -g 1001 ${USERNAME} \

USER ${USERNAME}

EXPOSE 8080 9527
EXPOSE 8080 9527 2112

ENTRYPOINT ["allora-node"]
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,9 @@ require (
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/polydawn/refmt v0.89.0 // indirect
github.com/prometheus/client_golang v1.18.0 // indirect
github.com/prometheus/client_golang v1.19.1 // indirect
github.com/prometheus/client_model v0.6.0 // indirect
github.com/prometheus/common v0.47.0 // indirect
github.com/prometheus/common v0.48.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/quic-go/qpack v0.4.0 // indirect
github.com/quic-go/quic-go v0.41.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,8 @@ github.com/prometheus/client_golang v1.4.0/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3O
github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
github.com/prometheus/client_golang v1.18.0 h1:HzFfmkOzH5Q8L8G+kSJKUx5dtG87sewO+FoDDqP5Tbk=
github.com/prometheus/client_golang v1.18.0/go.mod h1:T+GXkCk5wSJyOqMIzVgvvjFDlkOQntgjkJWKrN5txjA=
github.com/prometheus/client_golang v1.19.1 h1:wZWJDwK+NameRJuPGDhlnFgx8e8HN3XHQeLaYJFJBOE=
github.com/prometheus/client_golang v1.19.1/go.mod h1:mP78NwGzrVks5S2H6ab8+ZZGJLZUq1hoULYBAYBw1Ho=
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
Expand All @@ -814,6 +816,8 @@ github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB8
github.com/prometheus/common v0.15.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s=
github.com/prometheus/common v0.47.0 h1:p5Cz0FNHo7SnWOmWmoRozVcjEp0bIVU8cV7OShpjL1k=
github.com/prometheus/common v0.47.0/go.mod h1:0/KsvlIEfPQCQ5I2iNSAWKPZziNCvRs5EC6ILDTlAPc=
github.com/prometheus/common v0.48.0 h1:QO8U2CdOzSn1BBsmXJXduaaW+dY/5QLjfB8svtSzKKE=
github.com/prometheus/common v0.48.0/go.mod h1:0/KsvlIEfPQCQ5I2iNSAWKPZziNCvRs5EC6ILDTlAPc=
github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
Expand Down

0 comments on commit f1f97db

Please sign in to comment.