Skip to content

Commit 848bdae

Browse files
committed
first attempt to add dkg metrics
1 parent d49a531 commit 848bdae

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

contracts/evoting/mod.go

+7
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ var (
4949
},
5050
[]string{"election"},
5151
)
52+
53+
PromElectionDkgStatus = prometheus.NewGaugeVec(prometheus.GaugeOpts{
54+
Name: "dvoting_dkg_status",
55+
Help: "status of distributed key generator",
56+
},
57+
[]string{"election"},
58+
)
5259
)
5360

5461
const (

services/dkg/pedersen/mod.go

+6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"go.dedis.ch/dela"
1313
"go.dedis.ch/dela/core/ordering"
1414

15+
"github.com/dedis/d-voting/contracts/evoting"
1516
etypes "github.com/dedis/d-voting/contracts/evoting/types"
1617

1718
"github.com/dedis/d-voting/internal/tracing"
@@ -134,6 +135,8 @@ func (s *Pedersen) NewActor(electionIDBuf []byte, pool pool.Pool, txmngr txn.Man
134135
status: dkg.Status{Status: dkg.Initialized},
135136
}
136137

138+
evoting.PromElectionDkgStatus.WithLabelValues(electionID).Set(float64(dkg.Initialized))
139+
137140
s.Lock()
138141
defer s.Unlock()
139142
s.actors[electionID] = a
@@ -169,6 +172,8 @@ func (a *Actor) setErr(err error, args map[string]interface{}) {
169172
Err: err,
170173
Args: args,
171174
}
175+
176+
evoting.PromElectionDkgStatus.WithLabelValues(a.electionID).Set(float64(dkg.Failed))
172177
}
173178

174179
// Setup implements dkg.Actor. It initializes the DKG protocol across all
@@ -297,6 +302,7 @@ func (a *Actor) Setup() (kyber.Point, error) {
297302
}
298303

299304
a.status = dkg.Status{Status: dkg.Setup}
305+
evoting.PromElectionDkgStatus.WithLabelValues(a.electionID).Set(float64(dkg.Setup))
300306

301307
return dkgPubKeys[0], nil
302308
}

services/dkg/pedersen/mod_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ import (
1414
"go.dedis.ch/dela/core/validation"
1515
"golang.org/x/xerrors"
1616

17+
"github.com/dedis/d-voting/contracts/evoting"
1718
etypes "github.com/dedis/d-voting/contracts/evoting/types"
1819
"github.com/dedis/d-voting/internal/testing/fake"
1920
"github.com/dedis/d-voting/services/dkg"
2021
"github.com/dedis/d-voting/services/dkg/pedersen/types"
22+
"github.com/prometheus/client_golang/prometheus/testutil"
2123
"github.com/stretchr/testify/require"
2224
"go.dedis.ch/dela/core/ordering/cosipbft/authority"
2325
"go.dedis.ch/dela/core/store/kv"
@@ -301,6 +303,8 @@ func TestPedersen_TwoListens(t *testing.T) {
301303
}
302304

303305
func TestPedersen_Setup(t *testing.T) {
306+
initMetrics()
307+
304308
electionID := "d3adbeef"
305309

306310
service := fake.NewService(electionID, etypes.Election{
@@ -325,6 +329,7 @@ func TestPedersen_Setup(t *testing.T) {
325329

326330
_, err := actor.Setup()
327331
require.EqualError(t, err, "failed to get election: election does not exist: <nil>")
332+
require.Equal(t, float64(dkg.Failed), testutil.ToFloat64(evoting.PromElectionDkgStatus))
328333

329334
actor.electionID = electionID
330335

@@ -333,6 +338,7 @@ func TestPedersen_Setup(t *testing.T) {
333338

334339
_, err = actor.Setup()
335340
require.EqualError(t, err, fake.Err("failed to stream"))
341+
require.Equal(t, float64(dkg.Failed), testutil.ToFloat64(evoting.PromElectionDkgStatus))
336342

337343
// RPC is bogus 2
338344
actor.rpc = fake.NewRPC()
@@ -396,6 +402,7 @@ func TestPedersen_Setup(t *testing.T) {
396402
// We test that particular behaviour later.
397403
_, err = actor.Setup()
398404
require.NoError(t, err)
405+
require.Equal(t, float64(dkg.Setup), testutil.ToFloat64(evoting.PromElectionDkgStatus))
399406
}
400407

401408
func TestPedersen_GetPublicKey(t *testing.T) {
@@ -623,6 +630,10 @@ func TestPedersen_ComputePubshares_OK(t *testing.T) {
623630
// -----------------------------------------------------------------------------
624631
// Utility functions
625632

633+
func initMetrics() {
634+
evoting.PromElectionDkgStatus.Reset()
635+
}
636+
626637
// actorsEqual checks that two actors hold the same data
627638
func requireActorsEqual(t require.TestingT, actor1, actor2 dkg.Actor) {
628639
actor1Data, err := actor1.MarshalJSON()

0 commit comments

Comments
 (0)