Skip to content

Commit acd6c8f

Browse files
committed
lint fix
1 parent cbff773 commit acd6c8f

File tree

4 files changed

+52
-1
lines changed

4 files changed

+52
-1
lines changed

connector/loganomalyconnector/anomaly.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
// Package loganomalyconnector provides an OpenTelemetry collector connector that detects
16+
// anomalies in log throughput using statistical analysis. It monitors the rate of incoming
17+
// logs and generates alerts when significant deviations from the baseline are detected,
18+
// using both Z-score and Median Absolute Deviation (MAD) methods for anomaly detection.
1519
package loganomalyconnector
1620

1721
import (
@@ -26,11 +30,15 @@ import (
2630
"go.uber.org/zap"
2731
)
2832

33+
// Sample represents a single measurement of log throughput at a specific point in time.
34+
// It pairs a timestamp with the corresponding rate of logs per minute for that sample period.
2935
type Sample struct {
3036
timestamp time.Time
3137
rate float64
3238
}
3339

40+
// Statistics holds statistical measures calculated from a set of log rate samples.
41+
// These statistics are used to establish a baseline and detect anomalies in log throughput.
3442
type Statistics struct {
3543
mean float64
3644
stdDev float64
@@ -39,6 +47,8 @@ type Statistics struct {
3947
samples []float64
4048
}
4149

50+
// AnomalyStat contains information about a detected log throughput anomaly,
51+
// including the type of anomaly, baseline statistics, and deviation metrics.
4252
type AnomalyStat struct {
4353
anomalyType string
4454
baselineStats Statistics

connector/loganomalyconnector/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323

2424
var _ component.Config = (*Config)(nil)
2525

26+
// Config defines the configuration parameters for the log anomaly detector connector.
2627
type Config struct {
2728
// How often to take measurements
2829
SampleInterval time.Duration `mapstructure:"sample_interval"`

connector/loganomalyconnector/connector.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright observIQ, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
package loganomalyconnector
216

317
import (
@@ -11,6 +25,10 @@ import (
1125
"go.uber.org/zap"
1226
)
1327

28+
// Detector implements the log anomaly detection connector.
29+
// It maintains a rolling window of log rate samples and uses statistical analysis
30+
// to detect anomalies in log throughput. The detector processes incoming logs,
31+
// calculates rates, and generates alerts when anomalous patterns are detected.
1432
type Detector struct {
1533
ctx context.Context
1634
cancel context.CancelFunc
@@ -48,7 +66,9 @@ func newDetector(config *Config, logger *zap.Logger, nextConsumer consumer.Logs)
4866
}
4967
}
5068

51-
func (d *Detector) Start(_ context.Context, host component.Host) error {
69+
// Start begins the anomaly detection process, sampling at intervals specified in the config.
70+
// It launches a background goroutine that periodically checks for and updates anomalies.
71+
func (d *Detector) Start(_ context.Context, _ component.Host) error {
5272
ticker := time.NewTicker(d.config.SampleInterval)
5373

5474
go func() {
@@ -65,15 +85,21 @@ func (d *Detector) Start(_ context.Context, host component.Host) error {
6585
return nil
6686
}
6787

88+
// Shutdown stops the detector's operations by canceling its context.
89+
// It cleans up any resources and stops the background sampling process.
6890
func (d *Detector) Shutdown(_ context.Context) error {
6991
d.cancel()
7092
return nil
7193
}
7294

95+
// Capabilities returns the consumer capabilities of the detector.
96+
// It indicates that this detector does not mutate the data it processes.
7397
func (d *Detector) Capabilities() consumer.Capabilities {
7498
return consumer.Capabilities{MutatesData: false}
7599
}
76100

101+
// ConsumeLogs processes incoming log data, counting the logs and maintaining time-based sampling buckets.
102+
// The logs are then forwarded to the next consumer in the pipeline.
77103
func (d *Detector) ConsumeLogs(ctx context.Context, ld plog.Logs) error {
78104
d.stateLock.Lock()
79105
defer d.stateLock.Unlock()

connector/loganomalyconnector/factory.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright observIQ, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
package loganomalyconnector
216

317
import (

0 commit comments

Comments
 (0)