analytics

package
v0.5.16 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2024 License: Apache-2.0, MIT Imports: 15 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Enabled = true
View Source
var Identity string
View Source
var Instance string

Functions

func Init

func Init(ctx context.Context, db *gorm.DB) error

Init initializes the global variables 'Instance' and 'Enabled' based on values stored in the database and environment variables respectively. The function uses the 'instance_id' key to fetch the 'Instance' value from the database. If the 'Instance' value is already set, the function returns early. If the environment variable 'SINGULARITY_ANALYTICS' is set to "0", 'Enabled' is set to false.

Parameters:

  • ctx: The context for managing timeouts and cancellation.
  • db: The gorm.DB instance for making database queries.

Returns:

  • An error if there are issues fetching the instance id from the database or if the database appears empty.

Types

type Collector

type Collector struct {
	// contains filtered or unexported fields
}
var Default Collector = Collector{}

func (*Collector) Flush

func (c *Collector) Flush() error

Flush ensures that all buffered events in the Collector are sent to the remote metrics service. This function uses batch processing to send events in chunks. Each chunk can have a maximum of 100 events. If the global 'Enabled' flag is false, the function exits early without doing anything.

Process:

  1. The function checks if there are any events buffered in the Collector.
  2. If there are more than 100 events of a specific type, it picks the first 100 and sends them. Otherwise, it sends all available events.
  3. It then encodes the selected events using CBOR and compresses them using the zstandard compression algorithm.
  4. The compressed data is encoded using Base64 encoding and sent to the remote metrics service using an HTTP POST request.
  5. If the HTTP response is not '200 OK', the function reads the response body and returns an error.

Returns:

  • nil if all buffered events are successfully sent.
  • An error if there are issues during any stage of the process.

func (*Collector) QueueDealEvent

func (c *Collector) QueueDealEvent(event DealProposalEvent)

func (*Collector) QueuePushJobEvent

func (c *Collector) QueuePushJobEvent(event PackJobEvent)

func (*Collector) Start

func (c *Collector) Start(ctx context.Context)

type DealProposalEvent

type DealProposalEvent struct {
	Timestamp int64  `cbor:"1,keyasint"`
	Instance  string `cbor:"2,keyasint"`

	PieceCID   string `cbor:"3,keyasint"`
	DataCID    string `cbor:"4,keyasint"`
	PieceSize  int64  `cbor:"5,keyasint"`
	Provider   string `cbor:"6,keyasint"`
	Client     string `cbor:"7,keyasint"`
	Verified   bool   `cbor:"8,keyasint"`
	StartEpoch int32  `cbor:"9,keyasint"`
	EndEpoch   int32  `cbor:"10,keyasint"`

	Identity string `cbor:"11,keyasint"`
}

type EventType

type EventType int
const (
	PackJobComplete EventType = iota
	DealProposal
)

type Events

type Events struct {
	PackJobEvents []PackJobEvent      `cbor:"1,keyasint"`
	DealEvents    []DealProposalEvent `cbor:"2,keyasint"`
}

type PackJobEvent

type PackJobEvent struct {
	Timestamp int64  `cbor:"1,keyasint"`
	Instance  string `cbor:"2,keyasint"`

	SourceType string `cbor:"3,keyasint"`
	OutputType string `cbor:"4,keyasint"`
	PieceSize  int64  `cbor:"5,keyasint"`
	PieceCID   string `cbor:"6,keyasint"`
	CarSize    int64  `cbor:"7,keyasint"`
	NumOfFiles int64  `cbor:"8,keyasint"`

	Identity string `cbor:"9,keyasint"`
}

Jump to

Keyboard shortcuts

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