common

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Namespace                = "cvms"           // cosmos_validator_monitoring_service
	Subsystem                = "root"           // root subsytem for skip, health, ops
	Timeout                  = 13 * time.Second // root timeout for each package api call
	IndexerSQLDefaultTimeout = 10 * time.Second
)
View Source
const (
	IndexPointerBlockHeightMetricName    = "latest_index_pointer_block_height"
	IndexPointerBlockTimestampMetricName = "latest_index_pointer_block_timestamp"
	LatestBlockHeightMetricName          = "latest_block_height"
	RecentMissCounterMetricName          = "recent_miss_counter"
)

metrics name for indexer

View Source
const (
	// labels for common
	ChainLabel        = "chain"
	ChainIDLabel      = "chain_id"
	TableChainIDLabel = "table_chain_id"
	PackageLabel      = "package"
	BaseURLLabel      = "endpoint"
	ErrLabel          = "err"
	MainnetLabel      = "mainnet"

	// labels for packages
	ValidatorAddressLabel    = "validator_opeartor_address"
	ConsensusAddressLabel    = "validator_consensus_address"
	MonikerLabel             = "moniker"
	ProposerAddressLabel     = "proposer_address"
	EvmChainLabel            = "evm_chain"
	OrchestratorAddressLabel = "orchestrator_address"
	BalanceAddressLabel      = "balance_address"
	UpgradeNameLabel         = "upgrade_name"
)
View Source
const ErrorPrefix = "cvms common errors"

Variables

View Source
var (
	ErrFailedToBuildPackager      = errors.New("failed to build the packger").Error()
	ErrUnDefinedSomeConfiguration = errors.New("undefinded port or something in your prometheus config file")
	ErrUnDefinedApp               = fmt.Errorf("%s: undefinded app name", ErrorPrefix)
	ErrUnSupportedPackage         = fmt.Errorf("%s: this is unsupported monitoring package", ErrorPrefix)
	ErrUnSupportedMethod          = fmt.Errorf("%s: this is unsupported method", ErrorPrefix)
	ErrUnsetHttpSchema            = fmt.Errorf("%s: failed to unset http schema for grpc connecting", ErrorPrefix)
	ErrFailedHttpRequest          = fmt.Errorf("%s: failed to request from node", ErrorPrefix)
	ErrGotStrangeStatusCode       = fmt.Errorf("%s: got strange status code in request", ErrorPrefix)
	ErrUnExpectedMethodCall       = fmt.Errorf("%s: got unexpected call method", ErrorPrefix)
	ErrFailedJsonUnmarshal        = fmt.Errorf("%s: failed to unmarshing json data", ErrorPrefix)
	ErrFailedConvertTypes         = fmt.Errorf("%s: failed to converting number types", ErrorPrefix)
	ErrOutOfSwitchCases           = fmt.Errorf("%s: out of switch case in router", ErrorPrefix)
	ErrFailedGatheringMiddleData  = fmt.Errorf("%s: failed to gather middle data like orchestrator address or somethings", ErrorPrefix)
	ErrFailedCreateGrpcConnection = fmt.Errorf("%s: failed to create grpc connection", ErrorPrefix)
	ErrFailedGrpcRequest          = fmt.Errorf("%s: failed to grpc request from node", ErrorPrefix)
	ErrFailedBuildingLogger       = fmt.Errorf("%s: failed to build logger by not found workspace string", ErrorPrefix)
)
View Source
var (
	// moniker is filter for ce
	Moniker string

	DefaultLabels = []string{ChainLabel, ChainIDLabel, PackageLabel, MainnetLabel, ErrLabel}

	// root skip counter for increasing count if any package is failed
	Skip = promauto.NewCounterVec(prometheus.CounterOpts{
		Namespace: Namespace,
		Subsystem: Subsystem,
		Name:      "skip_counter"},
		DefaultLabels,
	)

	Health = promauto.NewGaugeVec(prometheus.GaugeOpts{
		Namespace: Namespace,
		Subsystem: Subsystem,
		Name:      "health_checker"},
		DefaultLabels,
	)

	Ops = promauto.NewCounterVec(prometheus.CounterOpts{
		Namespace: Namespace,
		Subsystem: Subsystem,
		Name:      "processed_ops_total"},
		DefaultLabels,
	)
)
View Source
var (
	IndexPackages = []string{

		"voteindexer",
		"veindexer",
	}

	ExporterPackages = []string{

		"block",

		"uptime",

		"balance", "upgrade",

		"axelar-evm", "eventnonce", "oracle", "yoda",
	}
)
View Source
var ErrCanSkip = fmt.Errorf("skip")

Functions

func BuildPackageLabels

func BuildPackageLabels(p Packager) prometheus.Labels

func BuildPackageLabelsWithURL

func BuildPackageLabelsWithURL(p Packager, url string) prometheus.Labels

func BuildRootLabels

func BuildRootLabels(p Packager) prometheus.Labels

Types

type ClientType

type ClientType int

Client

const (
	RPC ClientType = iota
	API
	GRPC
)

type CollectorLoop

type CollectorLoop func(*Exporter, Packager)

type CollectorStart

type CollectorStart func(Packager) error

Collector Function Sig

type CommonApp

type CommonApp struct {
	CommonClient
	EndPoint string
	// optional client
	OptionalClient CommonClient
}

func NewCommonApp

func NewCommonApp(p Packager) CommonApp

type CommonClient

type CommonClient struct {
	RPCClient  *resty.Client
	APIClient  *resty.Client
	GRPCClient *resty.Client
	*logrus.Entry
}

func NewOptionalClient

func NewOptionalClient(entry *logrus.Entry) CommonClient

func (*CommonClient) GetAPIEndPoint

func (c *CommonClient) GetAPIEndPoint() string

func (*CommonClient) GetGRPCEndPoint

func (c *CommonClient) GetGRPCEndPoint() string

func (*CommonClient) GetRPCEndPoint

func (c *CommonClient) GetRPCEndPoint() string

func (*CommonClient) SetAPIEndPoint

func (c *CommonClient) SetAPIEndPoint(endpoint string) *resty.Client

func (*CommonClient) SetGRPCEndPoint

func (c *CommonClient) SetGRPCEndPoint(endpoint string) *resty.Client

func (*CommonClient) SetRPCEndPoint

func (c *CommonClient) SetRPCEndPoint(endpoint string) *resty.Client

type Endpoints

type Endpoints struct {
	APIs     []string
	CheckAPI bool

	RPCs     []string
	CheckRPC bool

	GRPCs     []string
	CheckGRPC bool
}

type Exporter

type Exporter struct {
	CommonApp
	Monikers  []string
	ChainName string
	ChainID   string
}

func NewExporter

func NewExporter(p Packager) *Exporter

type ICollector

type ICollector interface {
	Start(p Packager) error
}

TODO

type IIndexer

type IIndexer interface {
	Start() error
	Loop(lastIndexPointerHeight int64)
	FetchValidatorInfoList() error
}

TODO: All Methods in VoteIndexer, we need to add here?

type Indexer

type Indexer struct {
	CommonApp
	ChainName    string
	Mainnet      bool
	ChainID      string
	ChainInfoID  int64
	ProtocolType string
	IsConsumer   bool
	Monikers     []string
	MonikerIDMap indexertypes.MonikerIDMap
	Endpoints
	*IndexerDB
	Vim           indexertypes.ValidatorIDMap
	Lh            indexertypes.LatestHeightCache
	Factory       promauto.Factory
	MetricsMap    map[string]prometheus.Gauge
	MetricsVecMap map[string]*prometheus.GaugeVec
	RootLabels    prometheus.Labels
	PackageLabels prometheus.Labels
}

func NewIndexer

func NewIndexer(p Packager, subsystem string, chainID string) *Indexer

TODO: not implemented

func (*Indexer) FetchLatestHeight

func (indexer *Indexer) FetchLatestHeight()

type IndexerDB

type IndexerDB struct {
	*bun.DB
	RetentionPeriod string
}

func NewIndexerDB

func NewIndexerDB(cfg IndexerDBConfig) (*IndexerDB, error)

func NewTestIndexerDB

func NewTestIndexerDB(dsn string) (*IndexerDB, error)

func (*IndexerDB) CloseConn

func (db *IndexerDB) CloseConn() error

TODO: currently, we don't use this helper.DB

func (*IndexerDB) SetRetentionTime

func (db *IndexerDB) SetRetentionTime(retentionPeriod string)

type IndexerDBConfig

type IndexerDBConfig struct {
	Host     string `toml:"host"`
	Database string `toml:"database"`
	Port     string `toml:"port"`
	User     string `toml:"user"`
	Password string `toml:"password"`
	Timeout  int64  `toml:"db_timeout"`
}

type Method

type Method int

Methods

const (
	GET Method = iota
	POST
)

type Mode

type Mode int
const (
	INVALID_APP Mode = -1   // Invalid Case
	NETWORK     Mode = iota // Network Mode to provide network status overview
	VALIDATOR               // Validator Mode to provide whole chains' status overview about validator
)

func (Mode) String

func (a Mode) String() string

type OptionPackager

type OptionPackager struct {
	// optional for balance package
	BalanceDenom     string
	BalanceExponent  int
	BalanceAddresses []string

	// optional for indexers
	*IndexerDB
	RetentionPeriod string

	// optional for consumer chain
	IsConsumerChain   bool
	ProviderEndPoints Endpoints
}

type Packager

type Packager struct {
	Mode         Mode
	Logger       *logrus.Logger
	Factory      promauto.Factory
	ChainName    string
	Mainnet      bool
	ChainID      string
	Package      string
	ProtocolType string
	Endpoints

	// optional info by mode
	Monikers []string
	// optional info by package
	OptionPackager
}

func NewPackager

func NewPackager(
	m Mode, f promauto.Factory, l *logrus.Logger,
	mainnet bool, chainID, chainName, pkg, protocolType string,
	cc config.ChainConfig, endpoints Endpoints,
	monikers ...string,
) (*Packager, error)

func (*Packager) SetAddtionalEndpoints

func (p *Packager) SetAddtionalEndpoints(providerEndpoints Endpoints) *Packager

func (*Packager) SetConsumer

func (p *Packager) SetConsumer() *Packager

func (*Packager) SetIndexerDB

func (p *Packager) SetIndexerDB(idxDB *IndexerDB) *Packager

func (*Packager) SetInfoForBalancePackage

func (p *Packager) SetInfoForBalancePackage(balanceAddresses []string, balanceDenom string, balanceExponent int) *Packager

Directories

Path Synopsis
indexer

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL