Skip to content

Commit

Permalink
Add counter metric to already closed guard
Browse files Browse the repository at this point in the history
  • Loading branch information
AlgoAxel committed Feb 24, 2023
1 parent 06decfe commit d409823
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
43 changes: 43 additions & 0 deletions ledger/store/storetest/helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (C) 2019-2023 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// go-algorand is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with go-algorand. If not, see <https://www.gnu.org/licenses/>.

package storetest

import (
"fmt"
"strings"
"testing"

"github.com/algorand/go-algorand/crypto"
"github.com/algorand/go-algorand/logging"
"github.com/algorand/go-algorand/util/db"
"github.com/stretchr/testify/require"
)

// DbOpenTest opens a db file for testing purposes.
func DbOpenTest(t testing.TB, inMemory bool) (db.Pair, string) {
fn := fmt.Sprintf("%s.%d", strings.ReplaceAll(t.Name(), "/", "."), crypto.RandUint64())
dbs, err := db.OpenPair(fn, inMemory)
require.NoErrorf(t, err, "Filename : %s\nInMemory: %v", fn, inMemory)
return dbs, fn
}

// SetDbLogging sets a testing logger on a database.
func SetDbLogging(t testing.TB, dbs db.Pair) {
dblogger := logging.TestingLog(t)
dbs.Rdb.SetLogger(dblogger)
dbs.Wdb.SetLogger(dblogger)
}
49 changes: 49 additions & 0 deletions ledger/store/storetest/testinterfaces.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package storetest

import (
"context"
"testing"

"github.com/algorand/go-algorand/config"
"github.com/algorand/go-algorand/data/basics"
"github.com/algorand/go-algorand/ledger/ledgercore"
"github.com/algorand/go-algorand/ledger/store"
"github.com/algorand/go-algorand/logging"
"github.com/algorand/go-algorand/protocol"
)

// testinterfaces.go contains interface extensions for the store package
// to use test-only functionality, cast your Interface to the test-version, eg:
// testTx := tx.(TransactionTestScope)
// implementations of test functionality should live in the store package to prevent import cycles

type BatchTestScope interface {
store.BatchScope

AccountsInitTest(tb testing.TB, initAccounts map[basics.Address]basics.AccountData, proto protocol.ConsensusVersion) (newDatabase bool)
AccountsUpdateSchemaTest(ctx context.Context) (err error)
RunMigrations(ctx context.Context, params store.TrackerDBParams, log logging.Logger, targetVersion int32) (mgr store.TrackerDBInitParams, err error)
}

type TransactionTestScope interface {
store.TransactionScope

MakeAccountsOptimizedReader() (store.AccountsReader, error)
MakeOnlineAccountsOptimizedReader() (store.OnlineAccountsReader, error)
AccountsInitTest(tb testing.TB, initAccounts map[basics.Address]basics.AccountData, proto protocol.ConsensusVersion) (newDatabase bool)
AccountsInitLightTest(tb testing.TB, initAccounts map[basics.Address]basics.AccountData, proto config.ConsensusParams) (newDatabase bool, err error)
}

type TestAccountsReaderExt interface {
store.AccountsReaderExt

AccountsAllTest() (bals map[basics.Address]basics.AccountData, err error)
CheckCreatablesTest(t *testing.T, iteration int, expectedDbImage map[basics.CreatableIndex]ledgercore.ModifiedCreatable)
}

type TestTrackerStore interface {
store.TrackerStore

CleanupTest(dbName string, inMemory bool)
ResetToV6Test(ctx context.Context) error
}
2 changes: 2 additions & 0 deletions network/wsNetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ var networkPeerBroadcastDropped = metrics.MakeCounter(metrics.MetricName{Name: "

var networkPeerIdentityDisconnect = metrics.MakeCounter(metrics.MetricName{Name: "algod_network_identity_duplicate", Description: "number of times identity challenge cause us to disconnect a peer"})
var networkPeerIdentityError = metrics.MakeCounter(metrics.MetricName{Name: "algod_network_identity_error", Description: "number of times an error occurs (besides expected) when processing identity challenges"})
var networkPeerAlreadyClosed = metrics.MakeCounter(metrics.MetricName{Name: "algod_network_peer_already_closed", Description: "number of times a peer would be added but the peer connection is already closed"})

var networkSlowPeerDrops = metrics.MakeCounter(metrics.MetricName{Name: "algod_network_slow_drops_total", Description: "number of peers dropped for being slow to send to"})
var networkIdlePeerDrops = metrics.MakeCounter(metrics.MetricName{Name: "algod_network_idle_drops_total", Description: "number of peers dropped due to idle connection"})
Expand Down Expand Up @@ -2459,6 +2460,7 @@ func (wn *WebsocketNetwork) addPeer(peer *wsPeer) {
defer wn.peersLock.Unlock()
// guard against peers which are closed or closing
if atomic.LoadInt32(&peer.didSignalClose) == 1 {
networkPeerAlreadyClosed.Inc(nil)
wn.log.Debugf("peer closing %s", peer.conn.RemoteAddr().String())
return
}
Expand Down

0 comments on commit d409823

Please sign in to comment.