mirror of
https://github.com/DeBrosOfficial/network.git
synced 2025-10-06 08:19:07 +00:00
Add node namespace and improve monitoring
The above changes introduce node namespacing and various monitoring improvements. Let's look at the key changes: - Add node_namespace config field for partitioning node identifiers - Initialize pubsub with peer exchange enabled - Reduce client monitoring interval to 30s - Add metric announcement logging I would write this commit message as: Add node namespace and improve monitoring - Add node_namespace config for partitioning identifiers - Enable pubsub peer exchange - Adjust monitoring intervals and add logging - Initialize pubsub with namespace support The subject line captures the two main themes (namespacing and monitoring), while the body provides helpful details about the specific changes made.
This commit is contained in:
parent
9d7c094360
commit
2acf969e61
@ -56,5 +56,13 @@
|
|||||||
"mode": "debug",
|
"mode": "debug",
|
||||||
"program": "./cmd/cli",
|
"program": "./cmd/cli",
|
||||||
"args": ["pubsub", "subscribe", "monitoring"]
|
"args": ["pubsub", "subscribe", "monitoring"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"adapter": "Delve",
|
||||||
|
"label": "Node Go (Delve)",
|
||||||
|
"request": "launch",
|
||||||
|
"mode": "debug",
|
||||||
|
"program": "./cmd/node",
|
||||||
|
"args": ["--config", "configs/node.yaml"]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
2
Makefile
2
Makefile
@ -21,7 +21,7 @@ test-e2e:
|
|||||||
|
|
||||||
.PHONY: build clean test run-node run-node2 run-node3 run-example deps tidy fmt vet lint clear-ports
|
.PHONY: build clean test run-node run-node2 run-node3 run-example deps tidy fmt vet lint clear-ports
|
||||||
|
|
||||||
VERSION := 0.42.1-beta
|
VERSION := 0.42.2-beta
|
||||||
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
|
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
|
||||||
DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
|
DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
|
||||||
LDFLAGS := -X 'main.version=$(VERSION)' -X 'main.commit=$(COMMIT)' -X 'main.date=$(DATE)'
|
LDFLAGS := -X 'main.version=$(VERSION)' -X 'main.commit=$(COMMIT)' -X 'main.date=$(DATE)'
|
||||||
|
@ -46,6 +46,7 @@ type DiscoveryConfig struct {
|
|||||||
BootstrapPort int `yaml:"bootstrap_port"` // Default port for bootstrap nodes
|
BootstrapPort int `yaml:"bootstrap_port"` // Default port for bootstrap nodes
|
||||||
HttpAdvAddress string `yaml:"http_adv_address"` // HTTP advertisement address
|
HttpAdvAddress string `yaml:"http_adv_address"` // HTTP advertisement address
|
||||||
RaftAdvAddress string `yaml:"raft_adv_address"` // Raft advertisement
|
RaftAdvAddress string `yaml:"raft_adv_address"` // Raft advertisement
|
||||||
|
NodeNamespace string `yaml:"node_namespace"` // Namespace for node identifiers
|
||||||
}
|
}
|
||||||
|
|
||||||
// SecurityConfig contains security-related configuration
|
// SecurityConfig contains security-related configuration
|
||||||
@ -115,6 +116,7 @@ func DefaultConfig() *Config {
|
|||||||
DiscoveryInterval: time.Second * 15, // Back to 15 seconds for testing
|
DiscoveryInterval: time.Second * 15, // Back to 15 seconds for testing
|
||||||
HttpAdvAddress: "",
|
HttpAdvAddress: "",
|
||||||
RaftAdvAddress: "",
|
RaftAdvAddress: "",
|
||||||
|
NodeNamespace: "default",
|
||||||
},
|
},
|
||||||
Security: SecurityConfig{
|
Security: SecurityConfig{
|
||||||
EnableTLS: false,
|
EnableTLS: false,
|
||||||
|
@ -115,6 +115,7 @@ func announceMetrics(n *Node, peers []peer.ID, cpuUsage uint64, memUsage *memory
|
|||||||
if err := n.pubsub.Publish(ctx, "monitoring", data); err != nil {
|
if err := n.pubsub.Publish(ctx, "monitoring", data); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
n.logger.Info("Announced metrics", zap.String("topic", "monitoring"))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -123,7 +124,7 @@ func announceMetrics(n *Node, peers []peer.ID, cpuUsage uint64, memUsage *memory
|
|||||||
// Unlike nodes which need extensive monitoring, clients only need basic health checks.
|
// Unlike nodes which need extensive monitoring, clients only need basic health checks.
|
||||||
func (n *Node) startConnectionMonitoring() {
|
func (n *Node) startConnectionMonitoring() {
|
||||||
go func() {
|
go func() {
|
||||||
ticker := time.NewTicker(60 * time.Second) // Less frequent than nodes (60s vs 30s)
|
ticker := time.NewTicker(30 * time.Second) // Less frequent than nodes (60s vs 30s)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
|
|
||||||
var lastPeerCount int
|
var lastPeerCount int
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/libp2p/go-libp2p"
|
"github.com/libp2p/go-libp2p"
|
||||||
|
libp2ppubsub "github.com/libp2p/go-libp2p-pubsub"
|
||||||
"github.com/libp2p/go-libp2p/core/crypto"
|
"github.com/libp2p/go-libp2p/core/crypto"
|
||||||
"github.com/libp2p/go-libp2p/core/host"
|
"github.com/libp2p/go-libp2p/core/host"
|
||||||
"github.com/libp2p/go-libp2p/core/network"
|
"github.com/libp2p/go-libp2p/core/network"
|
||||||
@ -258,6 +259,18 @@ func (n *Node) startLibP2P() error {
|
|||||||
|
|
||||||
n.host = h
|
n.host = h
|
||||||
|
|
||||||
|
// Initialize pubsub
|
||||||
|
ps, err := libp2ppubsub.NewGossipSub(context.Background(), h,
|
||||||
|
libp2ppubsub.WithPeerExchange(true),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to create pubsub: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create pubsub adapter with "node" namespace
|
||||||
|
n.pubsub = pubsub.NewClientAdapter(ps, n.config.Discovery.NodeNamespace)
|
||||||
|
n.logger.Info("Initialized pubsub adapter on namespace", zap.String("namespace", n.config.Discovery.NodeNamespace))
|
||||||
|
|
||||||
// Log configured bootstrap peers
|
// Log configured bootstrap peers
|
||||||
if len(n.config.Discovery.BootstrapPeers) > 0 {
|
if len(n.config.Discovery.BootstrapPeers) > 0 {
|
||||||
n.logger.ComponentInfo(logging.ComponentNode, "Configured bootstrap peers",
|
n.logger.ComponentInfo(logging.ComponentNode, "Configured bootstrap peers",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user