Skip to content
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

feat: event logs clean #256

Merged
merged 5 commits into from
Oct 14, 2022
Merged

feat: event logs clean #256

merged 5 commits into from
Oct 14, 2022

Conversation

Xvv-v
Copy link
Contributor

@Xvv-v Xvv-v commented Oct 13, 2022

Signed-off-by: xu.jingwen xu.jingwen@99cloud.net

What type of PR is this?

/kind feature

What this PR does / why we need it:

Which issue(s) this PR fixes:

Fixes #255

Special notes for reviewers:

Does this PR introduced a user-facing change?


Additional documentation, usage docs, etc.:


Signed-off-by: xu.jingwen <xu.jingwen@99cloud.net>
@kubeclipper-bot
Copy link
Collaborator

@Xvv-v: Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@kubeclipper-bot kubeclipper-bot added kind/feature Categorizes issue or PR as related to a new feature. dco-signoff: yes do-not-merge/release-note-label-needed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 13, 2022
Signed-off-by: xu.jingwen <xu.jingwen@99cloud.net>
@codecov-commenter
Copy link

codecov-commenter commented Oct 13, 2022

Codecov Report

Merging #256 (19e848c) into master (f1cb534) will decrease coverage by 0.00%.
The diff coverage is 61.11%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #256      +/-   ##
==========================================
- Coverage   13.12%   13.11%   -0.01%     
==========================================
  Files          98       98              
  Lines       15341    15359      +18     
==========================================
+ Hits         2014     2015       +1     
- Misses      13088    13105      +17     
  Partials      239      239              
Impacted Files Coverage Δ
pkg/cli/deploy/deploy.go 5.69% <0.00%> (-0.03%) ⬇️
pkg/auditing/audit.go 28.50% <78.57%> (+0.77%) ⬆️
pkg/scheme/core/v1/k8s/cluster.go 0.12% <0.00%> (-0.01%) ⬇️
pkg/component/nfs/nfs.go 0.56% <0.00%> (-0.01%) ⬇️
pkg/apis/core/v1/handler.go 0.33% <0.00%> (-0.01%) ⬇️

@Xvv-v
Copy link
Contributor Author

Xvv-v commented Oct 13, 2022

/cc @x893675

@x893675
Copy link
Collaborator

x893675 commented Oct 13, 2022

/cc @lixd

@x893675
Copy link
Collaborator

x893675 commented Oct 13, 2022

/milestone v1.3.1

@kubeclipper-bot kubeclipper-bot added this to the v1.3.1 milestone Oct 13, 2022
@@ -168,6 +169,14 @@ func ObjectMetaFilter(obj metav1.ObjectMeta, key, value string) bool {
if !strings.Contains(obj.Annotations[common.AnnotationDescription], value) {
return false
}
case "time":
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename create_before

@@ -57,6 +57,7 @@ type EventReader interface {
type EventReaderEx interface {
GetEventEx(ctx context.Context, name string, resourceVersion string) (*v1.Event, error)
ListEventsEx(ctx context.Context, query *query.Query) (*models.PageableResponse, error)
ListEventsWithTimeEx(ctx context.Context, query *query.Query) (*models.PageableResponse, error)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

@@ -138,6 +138,30 @@ func (p *platformOperator) ListEventsEx(ctx context.Context, query *query.Query)
return models.ListExV2(ctx, p.eventStorage, query, p.eventFilter, nil, nil)
}

func (p *platformOperator) ListEventsWithTimeEx(ctx context.Context, query *query.Query) (*models.PageableResponse, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

q := &query.Query{
FieldSelector: fieldSelector,
Reverse: false,
Limit: -1,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove Limit

FieldSelector: fieldSelector,
Reverse: false,
Limit: -1,
Pagination: &query.Pagination{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use query.NoPagination()

Offset: 0,
},
}
loginLogs, err := s.AuditOperator.ListEvents(context.TODO(), q)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

query with timestamp, then check entry size, if not allowd, skip direct

q.FuzzySearch = map[string]string{
"time": timestamp,
}
eventList, err := s.AuditOperator.ListEventsWithTimeEx(context.TODO(), q)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use ListEventEx instead

)

type AuditOptions struct {
EventLogHistoryRetentionPeriod time.Duration `json:"eventLogHistoryRetentionPeriod" yaml:"eventLogHistoryRetentionPeriod"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename RetentionPeriod
rename MaximumEntries


func (s *AuditStatusMon) monitorAuditStatus() {
timestamp := time.Now().Add(-s.AuditOptions.EventLogHistoryRetentionPeriod).Format(time.RFC3339)
s.cleanLogs("type", timestamp)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add annotate
// clean login / logout audit envent
s.cleanLogs("type", timestamp)

default:
return errors.New("[--period] format error, only support [h, d, w]")
}
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return error first

if !m.MatchString(o.period){
    return errors.New("only support [ None | Metadata | Request | RequestResponse ]")
}
// do parse


func (s *AuditStatusMon) monitorAuditStatus() {
timestamp := time.Now().Add(-s.AuditOptions.EventLogHistoryRetentionPeriod).Format(time.RFC3339)
s.cleanLogs("type", timestamp)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong FieldSelector format

Signed-off-by: xu.jingwen <xu.jingwen@99cloud.net>
Signed-off-by: xu.jingwen <xu.jingwen@99cloud.net>
var errors []error
errors = append(errors, s.GenericServerRunOptions.Validate()...)
errors = append(errors, s.EtcdOptions.Validate()...)
errors = append(errors, s.MQOptions.Validate()...)
errors = append(errors, s.LogOptions.Validate()...)
errors = append(errors, s.AuthenticationOptions.Validate()...)
if err = s.AuditOptions.Validate(); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rewrite to append(errors, s.AuditOptions.Validate())

@@ -56,6 +58,7 @@ type Config struct {
MQOptions *natsio.NatsOptions `json:"mq,omitempty" yaml:"mq,omitempty" mapstructure:"mq"`
LogOptions *logger.Options `json:"log,omitempty" yaml:"log,omitempty" mapstructure:"log"`
AuthenticationOptions *authoptions.AuthenticationOptions `json:"authentication,omitempty" yaml:"authentication,omitempty" mapstructure:"authentication"`
AuditOptions *auditoptions.AuditOptions `json:"auditOptions,omitempty" yaml:"auditOptions,omitempty" mapstructure:"authentication"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

audit tag not same with kubeclipper-server.yaml

Signed-off-by: xu.jingwen <xu.jingwen@99cloud.net>
Copy link
Contributor

@lixd lixd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@kubeclipper-bot kubeclipper-bot added the lgtm Indicates that a PR is ready to be merged. label Oct 14, 2022
@kubeclipper-bot
Copy link
Collaborator

LGTM label has been added.

Git tree hash: 85035ebb996ea51c7bfd8faa5c1b94678c4a3645

@x893675
Copy link
Collaborator

x893675 commented Oct 14, 2022

/approve

@kubeclipper-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lixd, x893675, Xvv-v

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubeclipper-bot kubeclipper-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 14, 2022
@kubeclipper-bot kubeclipper-bot merged commit 17bba1d into kubeclipper:master Oct 14, 2022
@Xvv-v Xvv-v deleted the clean branch October 21, 2022 01:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. dco-signoff: yes do-not-merge/release-note-label-needed kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

event logs clean
5 participants