Skip to content

Commit

Permalink
lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
BominRahmani committed Jan 8, 2025
1 parent cbff773 commit 82811b3
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
10 changes: 10 additions & 0 deletions connector/loganomalyconnector/anomaly.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions connector/loganomalyconnector/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
22 changes: 21 additions & 1 deletion connector/loganomalyconnector/connector.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down Expand Up @@ -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() {
Expand All @@ -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}
}
Expand Down
14 changes: 14 additions & 0 deletions connector/loganomalyconnector/factory.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down

0 comments on commit 82811b3

Please sign in to comment.