entity

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: 10 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

Index

Constants

View Source
const (
	EmptyKey  = Key("")
	EmptyID   = ID(0)
	EmptyGUID = GUID("")
)

Variables

View Source
var (
	EmptyIdentity = Identity{
		ID:   EmptyID,
		GUID: EmptyGUID,
	}
)

Functions

func ReplaceLoopback

func ReplaceLoopback(value string, lookup host.IDLookup, protocolVersion int) (string, error)

ReplaceLoopback returns the value replacing localhost for agent hostname

Types

type Entity

type Entity struct {
	Key
	ID
}

Entity information.

func New

func New(entityKey Key, entityID ID) Entity

New will create a new Entity object.

func NewFromNameWithoutID

func NewFromNameWithoutID(entityName string) Entity

NewFromNameWithoutID will create a new Entity object without entityID from a string entityName.

func NewWithoutID

func NewWithoutID(entityKey Key) Entity

NewWithoutID will create a new Entity object without entityID.

type Fields

type Fields struct {
	Name         string                 `json:"name"`
	Type         Type                   `json:"type"`
	IDAttributes IDAttributes           `json:"id_attributes"`
	DisplayName  string                 `json:"displayName"`
	Metadata     map[string]interface{} `json:"metadata"`
}

Fields store the identifying fields of an entity, which can be used to compose the entity Key

func (*Fields) IsAgent

func (f *Fields) IsAgent() bool

IsAgent returns if entity is (local) agent.

func (*Fields) JsonSize

func (f *Fields) JsonSize() int

JsonSize will return the size of the json serialization.

func (*Fields) Key

func (f *Fields) Key() (Key, error)

NewKey generates an entity Key to uniquely identify this entity

func (*Fields) ResolveUniqueEntityKey

func (f *Fields) ResolveUniqueEntityKey(agentID string, lookup host.IDLookup, entityRewrite data.EntityRewrites, protocol int) (Key, error)

ResolveUniqueEntityKey determine an unique entity key for agent and integrations to avoid collision.

type GUID

type GUID string

GUID entity GUID

func (GUID) String

func (g GUID) String() string

String stringer stuff

type ID

type ID int64

ID entity ID

func (ID) IsEmpty

func (i ID) IsEmpty() bool

IsEmpty returns if ID is empty

func (ID) String

func (i ID) String() string

String stringer stuff

type IDAttribute

type IDAttribute struct {
	Key   string
	Value string
}

IDAttribute is an attribute which defines uniqueness in the entity key.

type IDAttributes

type IDAttributes []IDAttribute

IDAttributes this sorted list ensures uniqueness for the entity key.

func (IDAttributes) Len

func (a IDAttributes) Len() int

Len is part of sort.Interface.

func (IDAttributes) Less

func (a IDAttributes) Less(i, j int) bool

Less is part of sort.Interface.

func (IDAttributes) Swap

func (a IDAttributes) Swap(i, j int)

Swap is part of sort.Interface.

type Identity

type Identity struct {
	ID   ID
	GUID GUID
}

Identity entity identifiers

type Key

type Key string

Key entity key

func (Key) IsEmpty

func (k Key) IsEmpty() bool

IsEmpty returns if key is empty

func (Key) String

func (k Key) String() string

String stringer stuff

type KnownIDs

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

KnownIDs maps the entity IDs given their respective entity Keys.

It associates a TTL to each entry, which expires after a given time without being accesses (both for setting and for reading values).

The default TTL is 24h, but it is possible to register custom TTLs per entity type.

func NewKnownIDs

func NewKnownIDs() KnownIDs

NewKnownIDs creates and returns an empty KnownIDs map

func (*KnownIDs) CleanOld

func (k *KnownIDs) CleanOld()

Clean removes the expired Key <-> ID entries

func (*KnownIDs) Get

func (k *KnownIDs) Get(key Key) (ID, bool)

Get returns the entity ID for the given entity Key, if exists. If the entry is found, its expiration time is updated to the current time + TTL.

func (*KnownIDs) Put

func (k *KnownIDs) Put(key Key, id ID)

Put registers an entity ID for a given entity Key. The entry has a default TTL of 24 hours.

func (*KnownIDs) PutType

func (k *KnownIDs) PutType(entityType Type, key Key, id ID)

PutType registers an entity ID for a given entity Key of the given Type. The new entry has a TTL according to the type registered with the SetTTL function. If the entity type has not been registered, it assumes the default TTL of 24 hours.

func (*KnownIDs) SetTTL

func (k *KnownIDs) SetTTL(entityType Type, ttl time.Duration)

SetTTL registers a custom TTL for the given entity Type

type Type

type Type string

Type is the type of an Entity

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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