Skip to content

Commit

Permalink
Check log metrics value in integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
aditya1702 committed Feb 16, 2024
1 parent 1ccba2a commit 6a2c7b9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
5 changes: 5 additions & 0 deletions cmd/soroban-rpc/internal/daemon/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package daemon

import (
"context"
supportlog "github.com/stellar/go/support/log"
"runtime"
"time"

Expand Down Expand Up @@ -102,3 +103,7 @@ func (c *CoreClientWithMetrics) SubmitTransaction(ctx context.Context, envelopeB
func (d *Daemon) CoreClient() interfaces.CoreClient {
return d.coreClient
}

func (d *Daemon) Logger() *supportlog.Entry {
return d.logger
}
36 changes: 25 additions & 11 deletions cmd/soroban-rpc/internal/test/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ package test

import (
"fmt"
"github.com/prometheus/client_golang/prometheus/testutil"
"github.com/sirupsen/logrus"
io_prometheus_client "github.com/prometheus/client_model/go"
"github.com/stellar/go/support/errors"
supportlog "github.com/stellar/go/support/log"
"github.com/stellar/go/support/logmetrics"
"github.com/stretchr/testify/assert"
"io"
"net/http"
Expand All @@ -31,21 +28,38 @@ func TestMetrics(t *testing.T) {
config.Version,
)
require.Contains(t, metrics, buildMetric)
}

func TestLogMetrics(t *testing.T) {
logMetrics := logmetrics.New("log_metrics_test")
logger := supportlog.New()
logger.AddHook(logMetrics)

logger := test.daemon.Logger()
err := errors.Errorf("test-error")
logger.WithError(err).Error("test error 1")
logger.WithError(err).Error("test error 2")

val := testutil.ToFloat64(logMetrics[logrus.ErrorLevel])
metricFamilies, err := test.daemon.MetricsRegistry().Gather()
assert.NoError(t, err)
var metric *io_prometheus_client.MetricFamily
for _, mf := range metricFamilies {
if *mf.Name == "soroban_rpc_log_error_total" {
metric = mf
break
}
}
val := metric.Metric[0].Counter.GetValue()
assert.Equal(t, val, 2.0)
}

//func TestLogMetrics(t *testing.T) {
// logMetrics := logmetrics.New("log_metrics_test")
// logger := supportlog.New()
// logger.AddHook(logMetrics)
//
// err := errors.Errorf("test-error")
// logger.WithError(err).Error("test error 1")
// logger.WithError(err).Error("test error 2")
//
// val := testutil.ToFloat64(logMetrics[logrus.ErrorLevel])
// assert.Equal(t, val, 2.0)
//}

func getMetrics(test *Test) string {
metricsURL, err := url.JoinPath(test.adminURL(), "/metrics")
require.NoError(test.t, err)
Expand Down

0 comments on commit 6a2c7b9

Please sign in to comment.