detector

package
v0.0.0-...-ce4a229 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2025 License: AGPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var OtelSupportedLanguages = map[string]string{
	"Go":     "go",
	"nodejs": "node",
	"Python": "python",
	"Java":   "java",
	".NET":   "dotnet",
}

OtelSupportedLanguages lists languages supported for OpenTelemetry auto-instrumentation

Functions

This section is empty.

Types

type CacheEntry

type CacheEntry struct {
	Info ContainerInfo
}

CacheEntry represents a cached detection result (no expiration)

type ContainerInfo

type ContainerInfo struct {
	PodName         string
	Namespace       string
	ContainerName   string
	Image           string
	Kind            string
	EnvVars         map[string]string
	ProcessCommands []string
	DetectedAt      time.Time
	Language        string
	Framework       string
	Enabled         bool
	Confidence      string
	DeploymentName  string
	Evidence        []string
}

ContainerInfo holds the detected information for a single container.

type EBPFDetector

type EBPFDetector struct {
	Clientset        *kubernetes.Clientset
	LanguageDetector *inspectors.LanguageDetector
	Cache            *LanguageCache
	Logger           *zap.Logger
	// contains filtered or unexported fields
}

EBPFDetector uses the pattern: watch pods, then inspect with eBPF

func NewEBPFDetector

func NewEBPFDetector(clientset *kubernetes.Clientset, cache *LanguageCache, logger *zap.Logger, queue chan ContainerInfo) (*EBPFDetector, error)

NewEBPFDetector creates a new eBPF-based detector

func (*EBPFDetector) Start

func (ed *EBPFDetector) Start(ctx context.Context) error

Start begins the detection: watch pods, inspect each one

type LanguageCache

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

LanguageCache provides thread-safe caching of language detection results It maintains both image-based cache and workload-based cache for cluster state synchronization Cache entries persist until workload is explicitly deleted - no time-based expiration

func NewLanguageCache

func NewLanguageCache(ttl time.Duration) *LanguageCache

NewLanguageCache creates a new cache (ttl parameter kept for compatibility but not used)

func (*LanguageCache) Get

func (lc *LanguageCache) Get(image string, envVars map[string]string) (*ContainerInfo, bool)

Get retrieves a cached result if it exists (no expiration check)

func (*LanguageCache) GetAllActiveContainers

func (lc *LanguageCache) GetAllActiveContainers() []ContainerInfo

GetAllActiveContainers returns all container infos from all workloads

func (*LanguageCache) GetAllActiveWorkloads

func (lc *LanguageCache) GetAllActiveWorkloads() []WorkloadCacheEntry

GetAllActiveWorkloads returns all workloads in the cache

func (*LanguageCache) GetWorkload

func (lc *LanguageCache) GetWorkload(namespace, workloadName string) (*WorkloadCacheEntry, bool)

GetWorkload retrieves cached detection results for a workload

func (*LanguageCache) RemoveWorkload

func (lc *LanguageCache) RemoveWorkload(namespace, workloadName string)

RemoveWorkload completely removes a workload from the cache

func (*LanguageCache) Set

func (lc *LanguageCache) Set(image string, envVars map[string]string, info ContainerInfo)

Set stores a detection result in the cache (persists until manually removed)

func (*LanguageCache) SetWorkload

func (lc *LanguageCache) SetWorkload(namespace, workloadName, workloadKind string, containers map[string]ContainerInfo)

SetWorkload stores detection results for a specific workload

func (*LanguageCache) UpdateWorkloadContainer

func (lc *LanguageCache) UpdateWorkloadContainer(namespace, workloadName, workloadKind string, info ContainerInfo)

UpdateWorkloadContainer updates a single container in a workload's cache

type PolylangDetector

type PolylangDetector struct {
	Clientset    *kubernetes.Clientset
	Config       *rest.Config
	RpcClient    *rpc.Client
	ServerAddr   string
	Logger       *zap.Logger
	DomainLogger interface {
		LanguageDetectionStarted(namespace, podName, containerName string)
		LanguageDetected(namespace, podName, containerName, image, language, framework, confidence string)
		LanguageDetectionFailed(namespace, podName, containerName string, err error)
		UnsupportedLanguage(language string)
		CacheHit(image, language string)
		CacheMiss(image string)
		CacheStored(image, language string)
		RPCBatchSent(count int, response string)
		RPCBatchFailed(count int, err error)
		DeploymentInfoRetrieved(namespace, podName, deploymentName, kind string)
		DeploymentInfoFailed(namespace, podName string, err error)
	}
	IgnoredNamespaces   []string
	MonitoredNamespaces []string
	Queue               chan ContainerInfo
	QueueSize           int
	BatchMutex          sync.Mutex
	Cache               *LanguageCache
}

PolylangDetector contains the Kubernetes client to interact with the cluster.

func NewPolylangDetector

func NewPolylangDetector(config *rest.Config, client *kubernetes.Clientset, domainLogger interface {
	LanguageDetectionStarted(namespace, podName, containerName string)
	LanguageDetected(namespace, podName, containerName, image, language, framework, confidence string)
	LanguageDetectionFailed(namespace, podName, containerName string, err error)
	UnsupportedLanguage(language string)
	CacheHit(image, language string)
	CacheMiss(image string)
	CacheStored(image, language string)
	RPCBatchSent(count int, response string)
	RPCBatchFailed(count int, err error)
	DeploymentInfoRetrieved(namespace, podName, deploymentName, kind string)
	DeploymentInfoFailed(namespace, podName string, err error)
}) *PolylangDetector

NewPolylangDetector creates a new language detector

func (*PolylangDetector) DetectLanguageWithProcInspection

func (pd *PolylangDetector) DetectLanguageWithProcInspection(namespace, podName string) ([]ContainerInfo, error)

DetectLanguageWithProcInspection detects language using /proc filesystem inspection (DaemonSet mode)

func (*PolylangDetector) DialWithRetry

func (c *PolylangDetector) DialWithRetry(ctx context.Context, retryInterval time.Duration) error

DialWithRetry attempts to connect to the RPC server with a backoff

func (*PolylangDetector) SendBatch

func (pd *PolylangDetector) SendBatch(batch []ContainerInfo)

SendBatch sends a batch of container info to the RPC server

func (*PolylangDetector) ShouldMonitorNamespace

func (pd *PolylangDetector) ShouldMonitorNamespace(namespace string) bool

ShouldMonitorNamespace determines if a namespace should be monitored based on configuration Priority: KM_K8S_MONITORED_NAMESPACES > KM_IGNORED_NS

func (*PolylangDetector) StartEBPFDetection

func (pd *PolylangDetector) StartEBPFDetection(ctx context.Context) error

StartEBPFDetection starts eBPF-based real-time process detection (recommended mode)

type ProcBasedDetector

type ProcBasedDetector struct {
	Clientset        *kubernetes.Clientset
	LanguageDetector *inspectors.LanguageDetector
	Cache            *LanguageCache
	Logger           *zap.Logger
}

ProcBasedDetector uses /proc filesystem for language detection (DaemonSet mode)

func NewProcBasedDetector

func NewProcBasedDetector(clientset *kubernetes.Clientset, cache *LanguageCache, logger *zap.Logger) *ProcBasedDetector

NewProcBasedDetector creates a new /proc-based language detector

func (*ProcBasedDetector) DetectLanguageForPod

func (pd *ProcBasedDetector) DetectLanguageForPod(ctx context.Context, namespace, podName string) ([]ContainerInfo, error)

DetectLanguageForPod detects languages for all containers in a pod using /proc inspection

type WorkloadCacheEntry

type WorkloadCacheEntry struct {
	Namespace    string
	WorkloadName string
	WorkloadKind string
	Containers   map[string]ContainerInfo // containerName -> ContainerInfo
}

WorkloadCacheEntry represents detection results for a specific workload (deployment/daemonset/replicaset)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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