delta

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2022 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Copyright 2020 New Relic Corporation. All rights reserved. SPDX-License-Identifier: Apache-2.0

Index

Constants

View Source
const (
	DATA_DIR_MODE             = 0755 // default mode for data directories
	DATA_FILE_MODE            = 0644 // default mode for data files
	CACHE_DIR                 = ".delta_repo"
	SAMPLING_REPO             = ".sampling_repo"
	CACHE_ID_FILE             = "delta_id_cache.json"
	UNSENT_DELTA_JOURNAL_EXT  = ".pending"
	ARCHIVE_DELTA_JOURNAL_EXT = ".sent"
	NO_DELTA_ID               = 0

	DisableInventorySplit = 0
)

Variables

View Source
var EMPTY_DELTA = []byte{'{', '}'}
View Source
var ErrNoPreviousSuccessSubmissionTime = fmt.Errorf("no previous success submission time")
View Source
var NULL = []byte{'n', 'u', 'l', 'l'}

Functions

This section is empty.

Types

type EntityIDFilePersist

type EntityIDFilePersist struct {
	// contains filtered or unexported fields
}

EntityIDFilePersist will store on the given file the EntityID in order to persist it between agent restarts.

func NewEntityIDFilePersist

func NewEntityIDFilePersist(dataDir string, fileName string) *EntityIDFilePersist

NewEntityIDFilePersist create a new instance of EntityIDFilePersist.

func (*EntityIDFilePersist) GetEntityID

func (e *EntityIDFilePersist) GetEntityID() (entity.ID, error)

GetEntityID will return entityID from memory or disk.

func (*EntityIDFilePersist) UpdateEntityID

func (e *EntityIDFilePersist) UpdateEntityID(id entity.ID) error

UpdateEntityID will store the entityID on memory and disk.

type EntityIDPersist

type EntityIDPersist interface {
	GetEntityID() (entity.ID, error)
	UpdateEntityID(id entity.ID) error
}

type LastSubmissionFileStore

type LastSubmissionFileStore struct {
	// contains filtered or unexported fields
}

LastSubmissionFileStore persists last successful submission date.

func (*LastSubmissionFileStore) Time

func (l *LastSubmissionFileStore) Time() (time.Time, error)

func (*LastSubmissionFileStore) UpdateTime

func (l *LastSubmissionFileStore) UpdateTime(t time.Time) error

type LastSubmissionInMemory

type LastSubmissionInMemory struct {
	// contains filtered or unexported fields
}

LastSubmissionInMemory stores last successful submission date in memory.

func (*LastSubmissionInMemory) Time

func (l *LastSubmissionInMemory) Time() (time.Time, error)

func (*LastSubmissionInMemory) UpdateTime

func (l *LastSubmissionInMemory) UpdateTime(t time.Time) error

type LastSubmissionStore

type LastSubmissionStore interface {
	Time() (time.Time, error)
	UpdateTime(time.Time) error
}

LastSubmissionStore retrieves and stores last inventory successful submission time.

func NewLastSubmissionInMemory

func NewLastSubmissionInMemory() LastSubmissionStore

NewLastSubmissionInMemory creates a fake LastSubmissionStore with ephemeral persistence for tests new instance assumes current time as last submission.

func NewLastSubmissionStore

func NewLastSubmissionStore(dataDir, fileName string) LastSubmissionStore

NewLastSubmissionStore creates a new LastSubmissionStore storing data in file.

type PIEntity

type PIEntity struct {
	MostRecentID int64 `json:"mru_id"`       // latest ID for an plugin entity to be used for submission
	LastSentID   int64 `json:"last_sent_id"` // latest ID from platform, decides whether archive or keep delta
}

PIEntity persisted info about an entity for a plugin.

type PluginInfo

type PluginInfo struct {
	Source   string              `json:"source"`
	Plugin   string              `json:"plugin"`
	FileName string              `json:"filename"`
	Entities map[string]PIEntity `json:"entities"`
}

PluginInfo persisted information about plugins.

func (*PluginInfo) ID

func (p *PluginInfo) ID() string

ID returns plugin serialized ID.

type Storage

type Storage interface {
	ReadDeltas(entityKey string) ([]inventoryapi.RawDeltaBlock, error)
	RemoveEntity(entityKey string) error
	CompactStorage(entityKey string, threshold uint64) (err error)
	ResetAllDeltas(entityKey string)
	UpdateState(entityKey string, deltas []*inventoryapi.RawDelta, deltaStateResults *inventoryapi.DeltaStateMap)
	SaveState() (err error)
}

type Store

type Store struct {
	// DataDir holds the agent data directory
	DataDir string
	// CacheDir holds the agent cache directory
	CacheDir string
	// contains filtered or unexported fields
}

Store handles information about the storage of Deltas.

func NewStore

func NewStore(dataDir string, defaultEntityKey string, maxInventorySize int) *Store

NewStore creates a new Store and returns a pointer to it. If maxInventorySize <= 0, the inventory splitting is disabled

func (*Store) ChangeDefaultEntity

func (s *Store) ChangeDefaultEntity(newEntityKey string)

func (*Store) CompactStorage

func (s *Store) CompactStorage(entityKey string, threshold uint64) (err error)

CompactStorage reduces the size of the Delta Storage

func (*Store) DeltaFilePath

func (s *Store) DeltaFilePath(pluginItem *PluginInfo, entityKey string) string

func (*Store) EntityFolder

func (s *Store) EntityFolder(entityKey string) string

EntityFolder provides the folder name for a given entity ID, or for the agent default entity in case entityKey is an empty string

func (*Store) PluginDirPath

func (s *Store) PluginDirPath(pluginCategory, entityKey string) string

func (*Store) ReadDeltas

func (s *Store) ReadDeltas(entityKey string) ([]inventoryapi.RawDeltaBlock, error)

ReadDeltas collects the plugins and read their deltas, grouped in blocks of size < maxInventorySize

func (*Store) RemoveEntity

func (s *Store) RemoveEntity(entityKey string) error

RemoveEntity removes the entity cached storage.

func (*Store) RemoveEntityFolders

func (s *Store) RemoveEntityFolders(entityFolder string) error

RemoveEntityFolders removes the entity cached storage from the entities whose folder is equal to the argument.

func (*Store) ResetAllDeltas

func (s *Store) ResetAllDeltas(entityKey string)

ResetAllDeltas clears the plugin delta store for all the existing plugins

func (*Store) SavePluginSource

func (s *Store) SavePluginSource(entityKey, category, term string, source map[string]interface{}) (err error)

StorePluginOutput will take a PluginOutput blob and write it to the data directory in JSON format

func (*Store) SaveState

func (s *Store) SaveState() (err error)

SaveState writes on disk the plugin ID maps

func (*Store) ScanEntityFolders

func (s *Store) ScanEntityFolders() (map[string]interface{}, error)

ScanEntityFolders returns a set of those entities that have been found in the different plugin folders.

func (*Store) SourceFilePath

func (s *Store) SourceFilePath(pluginItem *PluginInfo, entityKey string) string

func (*Store) StorageSize

func (s *Store) StorageSize(path string) (uint64, error)

StorageSize returns the size used in bytes of all the loose objects in the cache, non-inclusive of dirs

func (*Store) UpdatePluginsInventoryCache

func (s *Store) UpdatePluginsInventoryCache(entityKey string) (err error)

UpdatePluginsInventoryCache looks for all the plugins of the given entityKey located in the store DataDir, for each of the plugins, it compares the inventory json source and compares it against the cached json.

If the JSONs differ, creates a delta file and replaces the cache with the source file. Then finally writes on disk the plugin ID maps.

func (*Store) UpdateState

func (s *Store) UpdateState(entityKey string, deltas []*inventoryapi.RawDelta, deltaStateResults *inventoryapi.DeltaStateMap)

UpdateState updates in disk the state of the deltas according to the passed PostDeltaBody, whose their ExternalKeys field may be empty.

Jump to

Keyboard shortcuts

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