-
Notifications
You must be signed in to change notification settings - Fork 38
Add anomaly detection transform stage to flowlogs-pipeline #1143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vatankh
wants to merge
13
commits into
netobserv:main
Choose a base branch
from
vatankh:feature/anomaly-transform
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
cb400ab
Add anomaly transform support
vatankh a832727
Merge pull request #1 from vatankh/codex/add-anomaly-transform-type-a…
vatankh 91d45cc
Add anomaly detection transform stage (EWMA + Z-score)
vatankh 6158ab5
chore: remove IDE files and ignore .idea
vatankh 16fd553
Replaced logging with error metric
vatankh b38b108
Replaced fmt with ConvertToString
vatankh 2c4daa9
Add configurable output prefix to Anomaly stage to support multiple d…
vatankh d00581e
Introduce anomaly type enum
vatankh 30dd466
add a typed anomalyType enum to represent anomaly classifications
vatankh 2d52427
fixed syntax
vatankh 6307856
updated the example
vatankh 556a139
Apply suggestions from code review
jotak 627b824
Apply suggestion from @jotak
jotak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,3 +3,4 @@ | |
| /bin/ | ||
| cover.out | ||
| y.output | ||
| .idea/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| log-level: info | ||
| pipeline: | ||
| - name: ingest | ||
| - name: detect-anomaly | ||
| follows: ingest | ||
| - name: write_stdout # for debugging | ||
| follows: detect-anomaly | ||
| # Uncomment for production: export anomaly metrics to Prometheus | ||
| # - name: write_metrics | ||
| # follows: detect-anomaly | ||
| # write: | ||
| # type: prometheus | ||
| # prometheus: | ||
| # port: 9102 | ||
| # prefix: flowlogs_pipeline_ | ||
| # metrics: | ||
| # - name: anomaly_score | ||
| # type: gauge | ||
| # valueKey: bytes_anomaly_score | ||
| # labels: | ||
| # - SrcAddr | ||
| # - DstAddr | ||
| # - Proto | ||
| # - anomaly_type | ||
| parameters: | ||
| - name: ingest | ||
| ingest: | ||
| type: synthetic | ||
| synthetic: | ||
| flowLogsPerMin: 10 | ||
| - name: detect-anomaly | ||
| transform: | ||
| type: anomaly | ||
| anomaly: | ||
| algorithm: zscore | ||
| valueField: Bytes | ||
| keyFields: [SrcAddr, DstAddr, Proto] | ||
| prefix: bytes_ | ||
| windowSize: 20 | ||
| baselineWindow: 5 | ||
| sensitivity: 3 | ||
| - name: write_stdout | ||
| write: | ||
| type: stdout |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| /* | ||
| * Copyright (C) 2024 IBM, 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 api | ||
|
|
||
| // TransformAnomalyAlgorithm defines the supported anomaly detection strategies. | ||
| // For doc generation, enum definitions must match format `Constant Type = "value" // doc` | ||
| type TransformAnomalyAlgorithm string | ||
|
|
||
| const ( | ||
| AnomalyAlgorithmEWMA TransformAnomalyAlgorithm = "ewma" // exponentially weighted moving average baseline | ||
| AnomalyAlgorithmZScore TransformAnomalyAlgorithm = "zscore" // rolling z-score over a sliding window | ||
| ) | ||
|
|
||
| // TransformAnomaly describes configuration for anomaly detection stages. | ||
| type TransformAnomaly struct { | ||
| Algorithm TransformAnomalyAlgorithm `yaml:"algorithm,omitempty" json:"algorithm,omitempty" doc:"(enum) algorithm used to score anomalies: ewma or zscore"` | ||
| ValueField string `yaml:"valueField,omitempty" json:"valueField,omitempty" doc:"field containing the numeric value to evaluate"` | ||
| KeyFields []string `yaml:"keyFields,omitempty" json:"keyFields,omitempty" doc:"list of fields combined to build the per-entity baseline key"` | ||
| Prefix string `yaml:"prefix,omitempty" json:"prefix,omitempty" doc:"prefix added to output fields to disambiguate when multiple anomaly stages are used"` | ||
| WindowSize int `yaml:"windowSize,omitempty" json:"windowSize,omitempty" doc:"number of recent samples to keep for baseline statistics"` | ||
| BaselineWindow int `yaml:"baselineWindow,omitempty" json:"baselineWindow,omitempty" doc:"minimum number of samples before anomaly scores are emitted"` | ||
| Sensitivity float64 `yaml:"sensitivity,omitempty" json:"sensitivity,omitempty" doc:"threshold multiplier for flagging anomalies (e.g., z-score)"` | ||
| EWMAAlpha float64 `yaml:"ewmaAlpha,omitempty" json:"ewmaAlpha,omitempty" doc:"smoothing factor for ewma algorithm; derived from windowSize if omitted"` | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.