Documentation
      ¶
    
    
  
    
  
    Index ¶
Constants ¶
This section is empty.
Variables ¶
var Enabled = true
    var Identity string
    var Instance string
    Functions ¶
func Init ¶
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
}
    func (*Collector) Flush ¶
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:
- The function checks if there are any events buffered in the Collector.
 - 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.
 - It then encodes the selected events using CBOR and compresses them using the zstandard compression algorithm.
 - The compressed data is encoded using Base64 encoding and sent to the remote metrics service using an HTTP POST request.
 - 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)
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 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"`
}