status-go/protocol/requests/community_metrics_request.go
Mikhail Rogachev 4ad84d80cc
feat: Collecting community messages count metrics (#3802)
* feat: proposal for collecting community metrics

https://github.com/status-im/status-desktop/issues/11152

* feat: collecting community message metrics with test

* feat: implement both strategies for fetching community metrics

* fix: review fixes

* fix: calc counts for timestamps
2023-08-01 17:08:57 +04:00

45 lines
1.2 KiB
Go

package requests
import (
"errors"
"github.com/status-im/status-go/eth-node/types"
)
var ErrNoCommunityID = errors.New("community metrics request has no community id")
var ErrInvalidTimestampIntervals = errors.New("community metrics request invalid time intervals")
type CommunityMetricsRequestType uint
const (
CommunityMetricsRequestMessagesTimestamps CommunityMetricsRequestType = iota
CommunityMetricsRequestMessagesCount
CommunityMetricsRequestMembers
CommunityMetricsRequestControlNodeUptime
)
type MetricsIntervalRequest struct {
StartTimestamp uint64 `json:"startTimestamp"`
EndTimestamp uint64 `json:"endTimestamp"`
}
type CommunityMetricsRequest struct {
CommunityID types.HexBytes `json:"communityId"`
Type CommunityMetricsRequestType `json:"type"`
Intervals []MetricsIntervalRequest `json:"intervals"`
}
func (r *CommunityMetricsRequest) Validate() error {
if len(r.CommunityID) == 0 {
return ErrNoCommunityID
}
for _, interval := range r.Intervals {
if interval.StartTimestamp == 0 || interval.EndTimestamp == 0 || interval.StartTimestamp >= interval.EndTimestamp {
return ErrInvalidTimestampIntervals
}
}
return nil
}