-
Notifications
You must be signed in to change notification settings - Fork 53
feat: validate benchmark type #583
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
Changes from all commits
4fa50cf
1ebe7b9
db6084f
4bd0a5d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| // Licensed to Elasticsearch B.V. under one or more contributor | ||
| // license agreements. See the NOTICE file distributed with | ||
| // this work for additional information regarding copyright | ||
| // ownership. Elasticsearch B.V. licenses this file to you 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. | ||
|
|
||
| // Config is put into a different package to prevent cyclic imports in case | ||
| // it is needed in several locations | ||
|
|
||
| package config | ||
|
|
||
| // https://github.com/elastic/integrations/tree/main/packages/cloud_security_posture/data_stream/findings/agent/stream | ||
| const ( | ||
| CIS_K8S = "cis_k8s" | ||
| CIS_EKS = "cis_eks" | ||
| CIS_AWS = "cis_aws" | ||
| ) | ||
|
|
||
| var SupportedCIS = []string{CIS_AWS, CIS_K8S, CIS_EKS} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| // Licensed to Elasticsearch B.V. under one or more contributor | ||
| // license agreements. See the NOTICE file distributed with | ||
| // this work for additional information regarding copyright | ||
| // ownership. Elasticsearch B.V. licenses this file to you 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. | ||
|
|
||
| // Config is put into a different package to prevent cyclic imports in case | ||
| // it is needed in several locations | ||
|
|
||
| package errors | ||
|
|
||
| // BeaterUnhealthyError error is an error that is desgined to have an information that | ||
| // can help to end user to operate cloudbeat health issues. | ||
| // For example, when a cloudbeat configuration is invalid, the error will include | ||
| // more information about what is missing/expected and might have links to external sources as well | ||
| type BeaterUnhealthyError struct { | ||
| msg string | ||
| } | ||
|
|
||
| func NewUnhealthyError(msg string) BeaterUnhealthyError { | ||
| return BeaterUnhealthyError{msg} | ||
| } | ||
|
|
||
| func (c BeaterUnhealthyError) Error() string { | ||
| return c.msg | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| // Licensed to Elasticsearch B.V. under one or more contributor | ||
| // license agreements. See the NOTICE file distributed with | ||
| // this work for additional information regarding copyright | ||
| // ownership. Elasticsearch B.V. licenses this file to you 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. | ||
|
|
||
| // Config is put into a different package to prevent cyclic imports in case | ||
| // it is needed in several locations | ||
|
|
||
| package errors | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestUnwrapError(t *testing.T) { | ||
| e1 := NewUnhealthyError("error_1") | ||
| e2 := fmt.Errorf("error 2 = %w", e1) | ||
| healthErr := &BeaterUnhealthyError{} | ||
| assert.False(t, errors.Is(e1, healthErr)) | ||
| assert.True(t, errors.As(e2, healthErr)) | ||
| assert.Equal(t, "error_1", healthErr.Error()) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,11 +21,14 @@ | |
| package launcher | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
| "sync" | ||
| "time" | ||
|
|
||
| "github.com/elastic/beats/v7/libbeat/beat" | ||
| "github.com/elastic/beats/v7/libbeat/management" | ||
| cb_errors "github.com/elastic/cloudbeat/errors" | ||
| "github.com/elastic/elastic-agent-libs/config" | ||
| "github.com/elastic/elastic-agent-libs/logp" | ||
| "github.com/elastic/go-ucfg" | ||
|
|
@@ -239,6 +242,10 @@ func (l *launcher) reconfigureWait(timeout time.Duration) (*config.C, error) { | |
| err := l.validator.Validate(update) | ||
| if err != nil { | ||
| l.log.Errorf("Config update validation failed: %v", err) | ||
| heatlhErr := &cb_errors.BeaterUnhealthyError{} | ||
| if errors.As(err, heatlhErr) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's test this new functionality, it can be a part of
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, note that you are checking the error that returned from the
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I dont think we have an easy way to mock the
The test for the errors pkg checking exactly this. First, create the From golang https://pkg.go.dev/errors#As
|
||
| l.beat.Manager.UpdateStatus(management.Degraded, heatlhErr.Error()) | ||
| } | ||
| continue | ||
| } | ||
| } | ||
|
|
||
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.
This change requires a matching change to the integration, isn't it?
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.
We already have it https://github.com/elastic/integrations/pull/4752/files#diff-721297d41d05ea41cf84e1ee80fdda5ac230452caef26678a37e752e43fbb466R11