agent

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: 48 Imported by: 0

Documentation

Overview

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

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

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

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

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

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

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

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

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

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

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

Index

Constants

View Source
const (
	EVENT_QUEUE_CAPACITY       = 1000
	BATCH_QUEUE_CAPACITY       = 200 // Queue memory consumption cCould be a MAX of config.MaxMetricsBatchSizeBytes * BATCH_QUEUE_CAPACITY in size
	MAX_EVENT_BATCH_COUNT      = 500
	EVENT_BATCH_TIMER_DURATION = 1 // seconds, How often we will queue batches of events even if we haven't hit max batch size
)

Variables

View Source
var ErrEmptyEntityID = errors.New("the agentID provided is empty. make sure you have connected if this is not expected")

ErrEmptyEntityID is returned when the entityID is empty.

Functions

func GenerateUserAgent

func GenerateUserAgent(what, version string) string

func NewContext

func NewContext(
	cfg *config.Config,
	buildVersion string,
	resolver hostname.ResolverChangeNotifier,
	lookup host.IDLookup,
	sampleMatchFn sampler.IncludeSampleMatchFn,
) *context

NewContext creates a new context.

func NewIdLookup

func NewIdLookup(resolver hostname.Resolver, cloudHarvester cloud.Harvester, displayName string) host.IDLookup

NewIdLookup creates a new agent ID lookup table.

func NewIdentityConnectService

func NewIdentityConnectService(client identityapi.IdentityConnectClient, fingerprintHarvest fingerprint.Harvester) *identityConnectService

Types

type Agent

type Agent struct {
	Context *context // Agent context data that is passed around the place
	// contains filtered or unexported fields
}

func New

func New(
	cfg *config.Config,
	ctx *context,
	userAgent string,
	idLookupTable host.IDLookup,
	s *delta.Store,
	connectSrv *identityConnectService,
	provideIDs ProvideIDs,
	dataClient backendhttp.Client,
	transport http.RoundTripper,
	cloudHarvester cloud.Harvester,
	fpHarvester fingerprint.Harvester,
	notificationHandler *ctl.NotificationHandlerWithCancellation,
) (*Agent, error)

New creates a new agent using given context and services.

func NewAgent

func NewAgent(
	cfg *config.Config,
	buildVersion string,
	userAgent string,
	ffRetriever feature_flags.Retriever) (a *Agent, err error)

NewAgent returns a new instance of an agent built from the config.

func (*Agent) DeprecatePlugin

func (a *Agent) DeprecatePlugin(plugin ids.PluginID)

DeprecatePlugin builds the list of deprecated plugins

func (*Agent) ExternalPluginsHealthCheck

func (a *Agent) ExternalPluginsHealthCheck()

ExternalPluginsHealthCheck schedules the plugins health checks.

func (*Agent) GetCloudHarvester

func (a *Agent) GetCloudHarvester() cloud.Harvester

GetCloudHarvester will return the CloudHarvester service.

func (*Agent) GetContext

func (a *Agent) GetContext() AgentContext

func (*Agent) LogExternalPluginsInfo

func (a *Agent) LogExternalPluginsInfo()

LogExternalPluginsInfo iterates over the list of plugins and logs the information of the external plugins only.

func (*Agent) Plugins

func (a *Agent) Plugins() []Plugin

func (*Agent) RegisterMetricsSender

func (a *Agent) RegisterMetricsSender(s registerableSender)

func (*Agent) RegisterPlugin

func (a *Agent) RegisterPlugin(p Plugin)

RegisterPlugin takes a Plugin instance and registers it in the agent's plugin map

func (*Agent) Run

func (a *Agent) Run() (err error)

Run is the main event loop for the agent it starts up the plugins kicks off a filesystem seed and watcher and listens for data from the plugins

func (*Agent) Terminate

func (a *Agent) Terminate()

Terminate takes all the reactive actions required before a termination (e.g. killing all the running processes)

type AgentContext

type AgentContext interface {
	Context() context2.Context
	SendData(PluginOutput)
	SendEvent(event sample.Event, entityKey entity.Key)
	Unregister(ids.PluginID)
	// Reconnecting tells the agent that this plugin must be re-executed when the agent reconnects after long time
	// disconnected (> 24 hours).
	AddReconnecting(Plugin)
	// Reconnect invokes again all the plugins that have been registered with the AddReconnecting function
	Reconnect()
	Config() *config.Config
	// EntityKey stores agent entity key (name), value may change in runtime.
	EntityKey() string
	Version() string

	// Service -> PID cache. This is used so we can translate between PIDs and service names easily.
	// The cache is populated by all plugins which produce lists of services, and used by metrics
	// which get processes and want to determine which service each process is for.
	CacheServicePids(source string, pidMap map[int]string)
	GetServiceForPid(pid int) (service string, ok bool)
	ActiveEntitiesChannel() chan string
	// HostnameResolver returns the host name resolver associated to the agent context
	HostnameResolver() hostname.Resolver
	IDLookup() host.IDLookup

	// Identity returns the entity ID of the infra agent
	Identity() entity.Identity
}

AgentContext defines the interfaces between plugins and the agent

type Inventories

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

Inventories processes inventories from multiple entities and splits them if they are too big for the limited sizes imposed by the inventory ingest API

func NewInventories

func NewInventories(store *delta.Store, ctx AgentContext, client *inventoryapi.IngestClient, inventories *map[string]*inventory,
	agentIdentifier string, compactEnabled bool, compactThreshold uint64, maxDataSize int) Inventories

NewInventories instantiates and returns a new Inventories object given the configuration passed as arguments

func (*Inventories) BulkPatchProcess

func (i *Inventories) BulkPatchProcess() error

BulkPatchProcess processes the deltas from all the entities in the Delta Store and submits them to the ingest service, splitting them if necessary into multiple requests. This function is not thread-safe. This function is blocking.

type Killable

type Killable interface {
	// Kill terminates the receiver of the function.
	Kill()
}

Killable defines the behaviour of a plugin that can be externally terminated.

type MetricPost

type MetricPost struct {
	ExternalKeys []string          `json:"ExternalKeys,omitempty"`
	EntityID     entity.ID         `json:"EntityID,omitempty"`
	IsAgent      bool              `json:"IsAgent"`
	Events       []json.RawMessage `json:"Events"`
	// Entity ID of the reporting agent, which will = EntityID when IsAgent == true.
	// The field is required in the backend for host metadata matching of the remote entities
	ReportingAgentID entity.ID `json:"ReportingAgentID,omitempty"`
}

MetricPost entity item for the HTTP post to be sent to the ingest service.

type MetricPostBatch

type MetricPostBatch []*MetricPost

MetricPostBatch HTTP post batching all the MetricPost per entity to be sent to the ingest service.

type MetricVortexPost

type MetricVortexPost struct {
	EntityID  entity.ID         `json:"EntityID"`
	EntityKey entity.Key        `json:"EntityKey"`
	IsAgent   bool              `json:"IsAgent"`
	Events    []json.RawMessage `json:"Events"`
	// Entity ID of the reporting agent, which will = EntityID when IsAgent == true.
	// The field is required in the backend for host metadata matching of the remote entities
	ReportingAgentID entity.ID `json:"ReportingAgentID"`
}

MetricPost entity item for the HTTP post to be sent to the ingest service.

type MetricVortexPostBatch

type MetricVortexPostBatch []*MetricVortexPost

MetricPostBatch HTTP post batching all the MetricPost per entity to be sent to the ingest service.

type Plugin

type Plugin interface {
	Run()
	Id() ids.PluginID
	IsExternal() bool
	GetExternalPluginName() string
	LogInfo()
	ScheduleHealthCheck()
}

Plugin describes the interface all agent plugins implement

type PluginCommon

type PluginCommon struct {
	ID                 ids.PluginID // the "ID" is the path we write the json to
	Context            AgentContext // a reference to the calling agent context
	External           bool         // If the plugin is an external plugin
	ExternalPluginName string       // The external plugin name. Ex: com.newrelic.nginx
	// Returns all the information related to the plugin, including
	// runtime environment variables
	DetailedLogFields func() logrus.Fields
	LogFields         logrus.Fields // fields to include when logging about the plugin
	HealthCheckCh     chan struct{} // notifies the plugin to execute a health check
	// contains filtered or unexported fields
}

PluginCommon contains attributes and methods available to all plugins

func NewExternalPluginCommon

func NewExternalPluginCommon(id ids.PluginID, ctx AgentContext, name string) PluginCommon

func (*PluginCommon) EmitEvent

func (pc *PluginCommon) EmitEvent(eventData map[string]interface{}, entityKey entity.Key)

func (*PluginCommon) EmitInventory

func (pc *PluginCommon) EmitInventory(data PluginInventoryDataset, entity entity.Entity)

EmitInventory sends data collected by the plugin to the agent

func (*PluginCommon) GetExternalPluginName

func (pc *PluginCommon) GetExternalPluginName() string

GetExternalPluginName is the accessor for the ExternalPluginName field

func (*PluginCommon) Id

func (pc *PluginCommon) Id() ids.PluginID

Id is the accessor for the id field

func (*PluginCommon) IsExternal

func (pc *PluginCommon) IsExternal() bool

IsExternal is the accessor for the External field

func (*PluginCommon) LogInfo

func (pc *PluginCommon) LogInfo()

LogInfo retrieves logs the plugin name for internal plugins, and for the external plugins it logs the data specified in the log fields.

func (*PluginCommon) ScheduleHealthCheck

func (pc *PluginCommon) ScheduleHealthCheck()

func (*PluginCommon) Unregister

func (pc *PluginCommon) Unregister()

Unregister tells the agent that this plugin cannot run

type PluginEmitter

type PluginEmitter interface {
	EmitInventory(data PluginInventoryDataset, entity entity.Entity)
	EmitEvent(eventData map[string]interface{}, entityKey entity.Key)
}

type PluginInventoryDataset

type PluginInventoryDataset []Sortable // PluginInventoryDataset is a slice of sortable things

func (PluginInventoryDataset) Len

func (pd PluginInventoryDataset) Len() int

PluginInventoryDataset also implements the sort.Sort interface

func (PluginInventoryDataset) Less

func (pd PluginInventoryDataset) Less(i, j int) bool

func (PluginInventoryDataset) Swap

func (pd PluginInventoryDataset) Swap(i, j int)

type PluginOutput

type PluginOutput struct {
	Id            ids.PluginID
	Entity        entity.Entity
	Data          PluginInventoryDataset
	NotApplicable bool
}

PluginOutput contains metadata about the inventory provided by Plugins, which will be used for its later addition to the delta store

func NewNotApplicableOutput

func NewNotApplicableOutput(id ids.PluginID) PluginOutput

func NewPluginOutput

func NewPluginOutput(id ids.PluginID, entity entity.Entity, data PluginInventoryDataset) PluginOutput

type ProvideIDs

type ProvideIDs func(agentIdn entity.Identity, entities []identityapi.RegisterEntity) ([]identityapi.RegisterEntityResponse, error)

ProvideIDs provides remote entity IDs. Waits for next retry if register endpoint status is not healthy.

func NewProvideIDs

func NewProvideIDs(
	client identityapi.RegisterClient,
	sm state.RegisterSM,
) ProvideIDs

NewProvideIDs creates a new remote entity IDs provider.

type Sortable

type Sortable interface {
	SortKey() string
}

Anything implementing the sortable interface must implement a method to return a string Sort key

Jump to

Keyboard shortcuts

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