Documentation ¶
Overview ¶
Package util provides util type definitions and helper methods for the language detection client and handler
Package util implements utility functions and types for language detection feature.
For more information about the language detection and library injection feature, refer to this document.
Index ¶
- Constants
- Variables
- func ExtractContainerFromAnnotationKey(annotationKey string) (string, bool)
- func GetGVR(namespacedOwnerRef *NamespacedOwnerReference) (schema.GroupVersionResource, error)
- func GetLanguageAnnotationKey(containerName string) string
- type Container
- type ContainersLanguages
- type Language
- type LanguageSet
- type NamespacedOwnerReference
- type TimedContainersLanguages
- func (c TimedContainersLanguages) EqualTo(other TimedContainersLanguages) bool
- func (c TimedContainersLanguages) GetOrInitialize(container Container) *TimedLanguageSet
- func (c TimedContainersLanguages) Merge(other TimedContainersLanguages) bool
- func (c TimedContainersLanguages) RemoveExpiredLanguages() bool
- type TimedLanguageSet
- func (s TimedLanguageSet) Add(language Language, expiration time.Time) bool
- func (s TimedLanguageSet) EqualTo(other TimedLanguageSet) bool
- func (s TimedLanguageSet) Has(language Language) bool
- func (s TimedLanguageSet) Merge(other TimedLanguageSet) bool
- func (s TimedLanguageSet) Remove(language Language)
- func (s TimedLanguageSet) RemoveExpired() bool
Constants ¶
const ( // KindDeployment represents the deployment resource kind KindDeployment = "Deployment" // KindReplicaset represents the replicaset resource kind KindReplicaset = "ReplicaSet" )
const ( // AnnotationPrefix represents a prefix of the language detection annotations AnnotationPrefix string = "internal.dd.datadoghq.com/" )
Variables ¶
var AnnotationRegex = regexp.MustCompile(`internal\.dd\.datadoghq\.com\/(init\.)?(.+?)\.detected_langs`)
AnnotationRegex defines the regex pattern of language detection annotations
var SupportedBaseOwners = map[string]struct{}{ KindDeployment: {}, }
SupportedBaseOwners is the set of owner resource types supported by language detection Currently only deployments are supported For KindReplicaset, we use the parent deployment
Functions ¶
func ExtractContainerFromAnnotationKey ¶
ExtractContainerFromAnnotationKey extracts container name from annotation key and indicates if it is an init container if the annotation key is not a language annotation it returns an empty container name
func GetGVR ¶
func GetGVR(namespacedOwnerRef *NamespacedOwnerReference) (schema.GroupVersionResource, error)
GetGVR returns the GroupVersionResource of the ownerRef
func GetLanguageAnnotationKey ¶
GetLanguageAnnotationKey returns the language annotation key for the specified container
Types ¶
type Container ¶
Container identifies a pod container by its name and an init boolean flag
func NewContainer ¶
NewContainer creates and returns a new Container object with unset init flag
func NewInitContainer ¶
NewInitContainer creates and returns a new Container object with set init flag
type ContainersLanguages ¶
type ContainersLanguages map[Container]LanguageSet
ContainersLanguages handles mapping containers to language sets
func (ContainersLanguages) ToAnnotations ¶
func (c ContainersLanguages) ToAnnotations() map[string]string
ToAnnotations converts the containers languages to language annotations
func (ContainersLanguages) ToProto ¶
func (c ContainersLanguages) ToProto() (containersDetailsProto, initContainersDetailsProto []*pbgo.ContainerLanguageDetails)
ToProto returns two proto messages ContainerLanguageDetails The first one contains standard containers The second one contains init containers
type LanguageSet ¶
type LanguageSet map[Language]struct{}
LanguageSet represents a set of languages
func (LanguageSet) Add ¶
func (s LanguageSet) Add(language Language) bool
Add adds a new language to the language set returns false if the language is already included in the set, and true otherwise
func (LanguageSet) ToProto ¶
func (s LanguageSet) ToProto() []*pbgo.Language
ToProto returns a proto message Language
type NamespacedOwnerReference ¶
NamespacedOwnerReference defines an owner reference bound to a namespace
func GetNamespacedBaseOwnerReference ¶
func GetNamespacedBaseOwnerReference(podDetails *pbgo.PodLanguageDetails) NamespacedOwnerReference
GetNamespacedBaseOwnerReference creates a new namespaced owner reference object representing the base owner of the pod In case the first owner's kind is replicaset, it returns an owner reference to the parent deployment of the replicaset
func NewNamespacedOwnerReference ¶
func NewNamespacedOwnerReference(apiVersion string, kind string, name string, namespace string) NamespacedOwnerReference
NewNamespacedOwnerReference returns a new namespaced owner reference
type TimedContainersLanguages ¶
type TimedContainersLanguages map[Container]TimedLanguageSet
TimedContainersLanguages handles mapping containers to timed language sets
func (TimedContainersLanguages) EqualTo ¶
func (c TimedContainersLanguages) EqualTo(other TimedContainersLanguages) bool
EqualTo checks if current TimedContainersLanguages object has identical content in comparison another TimedContainersLanguages
func (TimedContainersLanguages) GetOrInitialize ¶
func (c TimedContainersLanguages) GetOrInitialize(container Container) *TimedLanguageSet
GetOrInitialize returns the language set of a container if it exists, or initializes it otherwise
func (TimedContainersLanguages) Merge ¶
func (c TimedContainersLanguages) Merge(other TimedContainersLanguages) bool
Merge merges another containers languages object to the current object Returns true if new languages were added, and false otherwise
func (TimedContainersLanguages) RemoveExpiredLanguages ¶
func (c TimedContainersLanguages) RemoveExpiredLanguages() bool
RemoveExpiredLanguages removes expired languages from each container language set Returns true if at least one language is expired and removed
type TimedLanguageSet ¶
TimedLanguageSet handles storing sets of languages along with their expiration times
func (TimedLanguageSet) Add ¶
func (s TimedLanguageSet) Add(language Language, expiration time.Time) bool
Add adds a new language to the language set with an expiration time returns false if the language is already included in the set, and true otherwise
func (TimedLanguageSet) EqualTo ¶
func (s TimedLanguageSet) EqualTo(other TimedLanguageSet) bool
EqualTo determines if the current timed languageset has the same languages as another timed languageset
func (TimedLanguageSet) Has ¶
func (s TimedLanguageSet) Has(language Language) bool
Has returns whether the set contains a specific language
func (TimedLanguageSet) Merge ¶
func (s TimedLanguageSet) Merge(other TimedLanguageSet) bool
Merge merges another timed language set with the current language set returns true if the set new languages were introduced, and false otherwise
func (TimedLanguageSet) Remove ¶
func (s TimedLanguageSet) Remove(language Language)
Remove deletes a language from the language set
func (TimedLanguageSet) RemoveExpired ¶
func (s TimedLanguageSet) RemoveExpired() bool
RemoveExpired removes all expired languages from the set Returns true if at least one language is expired and removed