Skip to content
Snippets Groups Projects
Unverified Commit 43970a0c authored by Angelo Capossele's avatar Angelo Capossele Committed by GitHub
Browse files

Make the payload registry also take in names for the different payloads (#557)

* :art: Add object name to the payload registry

* :bulb: Add comment

* :recycle: Make ObjectName exported

* :chart_with_upwards_trend: Update Grafana dashboard
parent 32ed993a
No related branches found
No related tags found
No related merge requests found
...@@ -9,6 +9,11 @@ import ( ...@@ -9,6 +9,11 @@ import (
"github.com/iotaledger/goshimmer/packages/binary/messagelayer/payload" "github.com/iotaledger/goshimmer/packages/binary/messagelayer/payload"
) )
const (
// ObjectName defines the name of the facuet object.
ObjectName = "faucet"
)
// Payload represents a request which contains an address for the faucet to send funds to. // Payload represents a request which contains an address for the faucet to send funds to.
type Payload struct { type Payload struct {
payloadType payload.Type payloadType payload.Type
...@@ -27,7 +32,7 @@ func New(addr address.Address) *Payload { ...@@ -27,7 +32,7 @@ func New(addr address.Address) *Payload {
} }
func init() { func init() {
payload.RegisterType(Type, GenericPayloadUnmarshalerFactory(Type)) payload.RegisterType(Type, ObjectName, GenericPayloadUnmarshalerFactory(Type))
} }
// FromBytes parses the marshaled version of a Payload into an object. // FromBytes parses the marshaled version of a Payload into an object.
......
...@@ -9,6 +9,11 @@ import ( ...@@ -9,6 +9,11 @@ import (
"github.com/mr-tron/base58" "github.com/mr-tron/base58"
) )
const (
// ObjectName defines the name of the networkdelay object.
ObjectName = "networkdelay"
)
// ID represents a 32 byte ID of a network delay object. // ID represents a 32 byte ID of a network delay object.
type ID [32]byte type ID [32]byte
...@@ -145,7 +150,7 @@ func (o *Object) Unmarshal(data []byte) (err error) { ...@@ -145,7 +150,7 @@ func (o *Object) Unmarshal(data []byte) (err error) {
} }
func init() { func init() {
payload.RegisterType(Type, func(data []byte) (payload payload.Payload, err error) { payload.RegisterType(Type, ObjectName, func(data []byte) (payload payload.Payload, err error) {
payload = &Object{} payload = &Object{}
err = payload.Unmarshal(data) err = payload.Unmarshal(data)
......
...@@ -12,6 +12,11 @@ import ( ...@@ -12,6 +12,11 @@ import (
"github.com/iotaledger/goshimmer/packages/binary/messagelayer/payload" "github.com/iotaledger/goshimmer/packages/binary/messagelayer/payload"
) )
const (
// ObjectName defines the name of the value object.
ObjectName = "value"
)
// Payload represents the entity that forms the Tangle by referencing other Payloads using their trunk and branch. // Payload represents the entity that forms the Tangle by referencing other Payloads using their trunk and branch.
// A Payload contains a transaction and defines, where in the Tangle a transaction is attached. // A Payload contains a transaction and defines, where in the Tangle a transaction is attached.
type Payload struct { type Payload struct {
...@@ -253,7 +258,7 @@ func (payload *Payload) Unmarshal(data []byte) (err error) { ...@@ -253,7 +258,7 @@ func (payload *Payload) Unmarshal(data []byte) (err error) {
} }
func init() { func init() {
payload.RegisterType(Type, func(data []byte) (payload payload.Payload, err error) { payload.RegisterType(Type, ObjectName, func(data []byte) (payload payload.Payload, err error) {
payload, _, err = FromBytes(data) payload, _, err = FromBytes(data)
return return
......
...@@ -9,6 +9,11 @@ import ( ...@@ -9,6 +9,11 @@ import (
"github.com/iotaledger/hive.go/stringify" "github.com/iotaledger/hive.go/stringify"
) )
const (
// ObjectName defines the name of the dRNG object.
ObjectName = "dRNG"
)
// Payload defines a DRNG payload. // Payload defines a DRNG payload.
type Payload struct { type Payload struct {
header.Header header.Header
...@@ -140,7 +145,7 @@ func (payload *Payload) Unmarshal(data []byte) (err error) { ...@@ -140,7 +145,7 @@ func (payload *Payload) Unmarshal(data []byte) (err error) {
} }
func init() { func init() {
payload.RegisterType(Type, func(data []byte) (payload payload.Payload, err error) { payload.RegisterType(Type, ObjectName, func(data []byte) (payload payload.Payload, err error) {
payload = &Payload{} payload = &Payload{}
err = payload.Unmarshal(data) err = payload.Unmarshal(data)
......
...@@ -4,11 +4,16 @@ import ( ...@@ -4,11 +4,16 @@ import (
"github.com/iotaledger/hive.go/marshalutil" "github.com/iotaledger/hive.go/marshalutil"
) )
const (
// ObjectName defines the name of the data object.
ObjectName = "data"
)
func init() { func init() {
// register the generic unmarshaler // register the generic unmarshaler
SetGenericUnmarshalerFactory(GenericPayloadUnmarshalerFactory) SetGenericUnmarshalerFactory(GenericPayloadUnmarshalerFactory)
// register the generic data payload type // register the generic data payload type
RegisterType(DataType, GenericPayloadUnmarshalerFactory(DataType)) RegisterType(DataType, ObjectName, GenericPayloadUnmarshalerFactory(DataType))
} }
// Payload represents some kind of payload of data which only gains meaning by having // Payload represents some kind of payload of data which only gains meaning by having
......
...@@ -7,16 +7,25 @@ import ( ...@@ -7,16 +7,25 @@ import (
// Unmarshaler takes some data and unmarshals it into a payload. // Unmarshaler takes some data and unmarshals it into a payload.
type Unmarshaler func(data []byte) (Payload, error) type Unmarshaler func(data []byte) (Payload, error)
// Definition defines the properties of a payload type.
type Definition struct {
Name string
Unmarshaler
}
var ( var (
typeRegister = make(map[Type]Unmarshaler) typeRegister = make(map[Type]Definition)
typeRegisterMutex sync.RWMutex typeRegisterMutex sync.RWMutex
genericUnmarshalerFactory func(payloadType Type) Unmarshaler genericUnmarshalerFactory func(payloadType Type) Unmarshaler
) )
// RegisterType registers a payload type with the given unmarshaler. // RegisterType registers a payload type with the given unmarshaler.
func RegisterType(payloadType Type, unmarshaler Unmarshaler) { func RegisterType(payloadType Type, payloadName string, unmarshaler Unmarshaler) {
typeRegisterMutex.Lock() typeRegisterMutex.Lock()
typeRegister[payloadType] = unmarshaler typeRegister[payloadType] = Definition{
Name: payloadName,
Unmarshaler: unmarshaler,
}
typeRegisterMutex.Unlock() typeRegisterMutex.Unlock()
} }
...@@ -25,8 +34,8 @@ func RegisterType(payloadType Type, unmarshaler Unmarshaler) { ...@@ -25,8 +34,8 @@ func RegisterType(payloadType Type, unmarshaler Unmarshaler) {
func GetUnmarshaler(payloadType Type) Unmarshaler { func GetUnmarshaler(payloadType Type) Unmarshaler {
typeRegisterMutex.RLock() typeRegisterMutex.RLock()
defer typeRegisterMutex.RUnlock() defer typeRegisterMutex.RUnlock()
if unmarshaler, exists := typeRegister[payloadType]; exists { if definition, exists := typeRegister[payloadType]; exists {
return unmarshaler return definition.Unmarshaler
} }
return genericUnmarshalerFactory(payloadType) return genericUnmarshalerFactory(payloadType)
} }
...@@ -35,3 +44,13 @@ func GetUnmarshaler(payloadType Type) Unmarshaler { ...@@ -35,3 +44,13 @@ func GetUnmarshaler(payloadType Type) Unmarshaler {
func SetGenericUnmarshalerFactory(unmarshalerFactory func(payloadType Type) Unmarshaler) { func SetGenericUnmarshalerFactory(unmarshalerFactory func(payloadType Type) Unmarshaler) {
genericUnmarshalerFactory = unmarshalerFactory genericUnmarshalerFactory = unmarshalerFactory
} }
// Name returns the name of a given payload type.
func Name(payloadType Type) string {
typeRegisterMutex.RLock()
defer typeRegisterMutex.RUnlock()
if definition, exists := typeRegister[payloadType]; exists {
return definition.Name
}
return ObjectName
}
...@@ -57,22 +57,9 @@ func collectTangleMetrics() { ...@@ -57,22 +57,9 @@ func collectTangleMetrics() {
messageTips.Set(float64(metrics.MessageTips())) messageTips.Set(float64(metrics.MessageTips()))
msgCountPerPayload := metrics.MessageCountPerPayload() msgCountPerPayload := metrics.MessageCountPerPayload()
for payloadType, count := range msgCountPerPayload { for payloadType, count := range msgCountPerPayload {
messagePerTypeCount.WithLabelValues(convertPayloadTypeToString(payloadType)).Set(float64(count)) messagePerTypeCount.WithLabelValues(payload.Name(payloadType)).Set(float64(count))
} }
messageTotalCount.Set(float64(metrics.MessageTotalCount())) messageTotalCount.Set(float64(metrics.MessageTotalCount()))
transactionCounter.Set(float64(metrics.ValueTransactionCounter())) transactionCounter.Set(float64(metrics.ValueTransactionCounter()))
valueTips.Set(float64(metrics.ValueTips())) valueTips.Set(float64(metrics.ValueTips()))
} }
func convertPayloadTypeToString(p payload.Type) string {
switch p {
case 0:
return "data"
case 1:
return "value"
case 111:
return "drng"
default:
return "unknown"
}
}
...@@ -486,14 +486,20 @@ ...@@ -486,14 +486,20 @@
{ {
"expr": "irate(tangle_messages_per_type_count{message_type=\"drng\"}[5m])", "expr": "irate(tangle_messages_per_type_count{message_type=\"drng\"}[5m])",
"interval": "", "interval": "",
"legendFormat": "DRNG Message Per Second", "legendFormat": "dRNG Messages Per Second",
"refId": "C" "refId": "C"
}, },
{ {
"expr": "irate(tangle_messages_per_type_count{message_type=\"unknown\"}[5m])", "expr": "irate(tangle_messages_per_type_count{message_type=\"faucet\"}[5m])",
"interval": "", "interval": "",
"legendFormat": "Unknown Type Message Per Second", "legendFormat": "Faucet Messages Per Second",
"refId": "D" "refId": "D"
},
{
"expr": "irate(tangle_messages_per_type_count{message_type=\"netowrkdelay\"}[5m])",
"interval": "",
"legendFormat": "Network Delay Messages Per Second",
"refId": "E"
} }
], ],
"thresholds": [], "thresholds": [],
......
...@@ -486,14 +486,20 @@ ...@@ -486,14 +486,20 @@
{ {
"expr": "irate(tangle_messages_per_type_count{message_type=\"drng\"}[5m])", "expr": "irate(tangle_messages_per_type_count{message_type=\"drng\"}[5m])",
"interval": "", "interval": "",
"legendFormat": "DRNG Message Per Second", "legendFormat": "dRNG Messages Per Second",
"refId": "C" "refId": "C"
}, },
{ {
"expr": "irate(tangle_messages_per_type_count{message_type=\"unknown\"}[5m])", "expr": "irate(tangle_messages_per_type_count{message_type=\"faucet\"}[5m])",
"interval": "", "interval": "",
"legendFormat": "Unknown Type Message Per Second", "legendFormat": "Faucet Messages Per Second",
"refId": "D" "refId": "D"
},
{
"expr": "irate(tangle_messages_per_type_count{message_type=\"netowrkdelay\"}[5m])",
"interval": "",
"legendFormat": "Network Delay Messages Per Second",
"refId": "E"
} }
], ],
"thresholds": [], "thresholds": [],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment