-
Notifications
You must be signed in to change notification settings - Fork 221
OTA-1813: Populate risks from alerts #1329
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
hongkailiu
wants to merge
5
commits into
openshift:main
Choose a base branch
from
hongkailiu:OTA-1813
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 all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
aa0abb2
OTA-1813: Populate risks from alerts
hongkailiu ff63cec
Add e2e test case for alert risks
hongkailiu 9613f28
go mod vendor
hongkailiu 8f7c808
ToSquash: Associate alert risks to every update
hongkailiu 7039cbe
ToSquash: make update
hongkailiu 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
14 changes: 14 additions & 0 deletions
14
.openshift-tests-extension/openshift_payload_cluster-version-operator.json
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| package promql | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "sync" | ||
| "time" | ||
|
|
||
| "github.com/prometheus/client_golang/api" | ||
| prometheusv1 "github.com/prometheus/client_golang/api/prometheus/v1" | ||
| "github.com/prometheus/common/config" | ||
|
|
||
| "k8s.io/klog/v2" | ||
|
|
||
| "github.com/openshift/cluster-version-operator/pkg/clusterconditions" | ||
| ) | ||
|
|
||
| type Getter interface { | ||
| Get(ctx context.Context) (prometheusv1.AlertsResult, error) | ||
| } | ||
|
|
||
| func NewAlertGetter(promQLTarget clusterconditions.PromQLTarget) Getter { | ||
| p := NewPromQL(promQLTarget) | ||
| condition := p.Condition | ||
| v, ok := condition.(*PromQL) | ||
| if !ok { | ||
| panic("invalid condition type") | ||
| } | ||
| return &ocAlertGetter{promQL: v, expiration: 1 * time.Minute} | ||
| } | ||
|
|
||
| type ocAlertGetter struct { | ||
| promQL *PromQL | ||
|
|
||
| mutex sync.Mutex | ||
| cached prometheusv1.AlertsResult | ||
| expiration time.Duration | ||
| lastRefresh time.Time | ||
| } | ||
|
|
||
| func (o *ocAlertGetter) Get(ctx context.Context) (prometheusv1.AlertsResult, error) { | ||
| if time.Now().After(o.lastRefresh.Add(o.expiration)) { | ||
| if err := o.refresh(ctx); err != nil { | ||
| klog.Errorf("Failed to refresh alerts, using stale cache instead: %v", err) | ||
| } | ||
| } | ||
| return o.cached, nil | ||
| } | ||
|
|
||
| func (o *ocAlertGetter) refresh(ctx context.Context) error { | ||
| o.mutex.Lock() | ||
| defer o.mutex.Unlock() | ||
|
|
||
| klog.Info("refresh alerts ...") | ||
| p := o.promQL | ||
| host, err := p.Host(ctx) | ||
| if err != nil { | ||
| return fmt.Errorf("failure determine thanos IP: %w", err) | ||
| } | ||
| p.url.Host = host | ||
| clientConfig := api.Config{Address: p.url.String()} | ||
|
|
||
| if roundTripper, err := config.NewRoundTripperFromConfig(p.HTTPClientConfig, "cluster-conditions"); err == nil { | ||
| clientConfig.RoundTripper = roundTripper | ||
| } else { | ||
| return fmt.Errorf("creating PromQL round-tripper: %w", err) | ||
| } | ||
|
|
||
| promqlClient, err := api.NewClient(clientConfig) | ||
| if err != nil { | ||
| return fmt.Errorf("creating PromQL client: %w", err) | ||
| } | ||
|
|
||
| client := &statusCodeNotImplementedForPostClient{ | ||
| client: promqlClient, | ||
| } | ||
|
|
||
| v1api := prometheusv1.NewAPI(client) | ||
|
|
||
| queryContext := ctx | ||
| if p.QueryTimeout > 0 { | ||
| var cancel context.CancelFunc | ||
| queryContext, cancel = context.WithTimeout(ctx, p.QueryTimeout) | ||
| defer cancel() | ||
| } | ||
|
|
||
| r, err := v1api.Alerts(queryContext) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to get alerts: %w", err) | ||
| } | ||
| o.cached = r | ||
| o.lastRefresh = time.Now() | ||
| klog.Infof("refreshed: %d alerts", len(o.cached.Alerts)) | ||
| return nil | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind also add
"Slow" in labels?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I admit that I like more on the label checking than strings.contains on names (we do not need to rename the test case to control if it is qualified in a suite).
But this is not really related to this pull, right?
We could do it by another separate pull.
Do you need the Slow label at the moment?