diff --git a/connector/loganomalyconnector/anomaly.go b/connector/loganomalyconnector/anomaly.go index 847fa58b0..974e7fd64 100644 --- a/connector/loganomalyconnector/anomaly.go +++ b/connector/loganomalyconnector/anomaly.go @@ -12,6 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. +// Package loganomalyconnector provides an OpenTelemetry collector connector that detects +// anomalies in log throughput using statistical analysis. It monitors the rate of incoming +// logs and generates alerts when significant deviations from the baseline are detected, +// using both Z-score and Median Absolute Deviation (MAD) methods for anomaly detection. package loganomalyconnector import ( @@ -26,11 +30,15 @@ import ( "go.uber.org/zap" ) +// Sample represents a single measurement of log throughput at a specific point in time. +// It pairs a timestamp with the corresponding rate of logs per minute for that sample period. type Sample struct { timestamp time.Time rate float64 } +// Statistics holds statistical measures calculated from a set of log rate samples. +// These statistics are used to establish a baseline and detect anomalies in log throughput. type Statistics struct { mean float64 stdDev float64 @@ -39,6 +47,8 @@ type Statistics struct { samples []float64 } +// AnomalyStat contains information about a detected log throughput anomaly, +// including the type of anomaly, baseline statistics, and deviation metrics. type AnomalyStat struct { anomalyType string baselineStats Statistics diff --git a/connector/loganomalyconnector/config.go b/connector/loganomalyconnector/config.go index 40eebef16..607932b2f 100644 --- a/connector/loganomalyconnector/config.go +++ b/connector/loganomalyconnector/config.go @@ -23,6 +23,7 @@ import ( var _ component.Config = (*Config)(nil) +// Config defines the configuration parameters for the log anomaly detector connector. type Config struct { // How often to take measurements SampleInterval time.Duration `mapstructure:"sample_interval"` diff --git a/connector/loganomalyconnector/connector.go b/connector/loganomalyconnector/connector.go index 2be8b5dc5..3a9cbdb41 100644 --- a/connector/loganomalyconnector/connector.go +++ b/connector/loganomalyconnector/connector.go @@ -1,3 +1,17 @@ +// Copyright observIQ, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package loganomalyconnector import ( @@ -48,7 +62,9 @@ func newDetector(config *Config, logger *zap.Logger, nextConsumer consumer.Logs) } } -func (d *Detector) Start(_ context.Context, host component.Host) error { +// Start begins the anomaly detection process, sampling at intervals specified in the config. +// It launches a background goroutine that periodically checks for and updates anomalies. +func (d *Detector) Start(_ context.Context, _ component.Host) error { ticker := time.NewTicker(d.config.SampleInterval) go func() { @@ -65,11 +81,15 @@ func (d *Detector) Start(_ context.Context, host component.Host) error { return nil } +// Shutdown stops the detector's operations by canceling its context. +// It cleans up any resources and stops the background sampling process. func (d *Detector) Shutdown(_ context.Context) error { d.cancel() return nil } +// Capabilities returns the consumer capabilities of the detector. +// It indicates that this detector does not mutate the data it processes. func (d *Detector) Capabilities() consumer.Capabilities { return consumer.Capabilities{MutatesData: false} } diff --git a/connector/loganomalyconnector/factory.go b/connector/loganomalyconnector/factory.go index 01e708ea6..6ec68d7b6 100644 --- a/connector/loganomalyconnector/factory.go +++ b/connector/loganomalyconnector/factory.go @@ -1,3 +1,17 @@ +// Copyright observIQ, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package loganomalyconnector import (