Skip to content

Commit

Permalink
Merge pull request #20 from BananaOps/feat/add-field
Browse files Browse the repository at this point in the history
feat: add news fields
  • Loading branch information
jplanckeel authored Oct 4, 2024
2 parents 318a550 + 2668f93 commit e4b039e
Show file tree
Hide file tree
Showing 6 changed files with 483 additions and 214 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
- name: Run Gosec Security Scanner
uses: securego/gosec@master
with:
args: ./...
args: -exclude=G115 ./...

test:
name: Go test
Expand Down
574 changes: 371 additions & 203 deletions generated/proto/event/v1alpha1/event.pb.go

Large diffs are not rendered by default.

70 changes: 70 additions & 0 deletions generated/proto/event/v1alpha1/event.pb.validate.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ func CreateFilter(e *v1alpha1.SearchEventsRequest) (map[string]interface{}, erro
if e.Priority != 0 {
filter["attributes.priority"] = e.Priority
}
if e.Environment != 0 {
filter["attributes.environment"] = e.Environment
}
if e.Status != 0 {
filter["attributes.status"] = e.Status
}
Expand All @@ -43,21 +46,21 @@ func CreateFilter(e *v1alpha1.SearchEventsRequest) (map[string]interface{}, erro
if err != nil {
return nil, err
}
filter["metadata.createdat.seconds"] = bson.D{{Key: "$gte", Value: start.Unix()}, {Key: "$lte", Value: end.Unix()}}
filter["attributes.startdate.seconds"] = bson.D{{Key: "$gte", Value: start.Unix()}, {Key: "$lte", Value: end.Unix()}}
}
if e.StartDate != "" && e.EndDate == "" {
date, err := parseDate(e.StartDate)
if err != nil {
return nil, err
}
filter["metadata.createdat.seconds"] = bson.D{{Key: "$gte", Value: date.Unix()}}
filter["attributes.startdate.seconds"] = bson.D{{Key: "$gte", Value: date.Unix()}}
}
if e.StartDate == "" && e.EndDate != "" {
date, err := parseDate(e.EndDate)
if err != nil {
return nil, err
}
filter["metadata.createdat.seconds"] = bson.D{{Key: "$lte", Value: date.Unix()}}
filter["attributes.startdate.seconds"] = bson.D{{Key: "$lte", Value: date.Unix()}}
}
if len(filter) == 0 {
err := errors.New("no filter for search events")
Expand Down
20 changes: 20 additions & 0 deletions proto/event/v1alpha1/event.proto
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ message EventAttributes {
string related_id = 5 [(validate.rules).string = {uuid: true}];
string service = 6;
Status status = 7;
Environment environment = 8;
bool impact = 9;
google.protobuf.Timestamp start_date = 10;
google.protobuf.Timestamp end_date = 11;
string owner = 12;
}

message EventMetadata {
Expand All @@ -46,6 +51,7 @@ message EventMetadata {

message EventLinks {
string pull_request_link = 1;
string ticket= 2;
}

message Event {
Expand Down Expand Up @@ -81,6 +87,8 @@ message SearchEventsRequest {
string service = 5;
string start_date = 6;
string end_date = 7;
Environment environment = 8;
bool impact = 9;
}

message SearchEventsResponse {
Expand Down Expand Up @@ -123,3 +131,15 @@ enum Status {
user_update = 7;
recommandation = 8;
}

enum Environment {
ENVIRONMENT_UNSPECIFIED = 0;
development = 1;
integration = 2;
TNR = 3;
UAT = 4;
recette = 5;
preproduction = 6;
production = 7;
mco = 8;
}
22 changes: 15 additions & 7 deletions server/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,18 @@ func (e *Event) CreateEvent(
var event = &v1alpha1.Event{
Title: i.Title,
Attributes: &v1alpha1.EventAttributes{
Message: i.Attributes.Message,
Source: i.Attributes.Source,
Type: i.Attributes.Type,
Priority: i.Attributes.Priority,
RelatedId: i.Attributes.RelatedId,
Service: i.Attributes.Service,
Status: i.Attributes.Status,
Message: i.Attributes.Message,
Source: i.Attributes.Source,
Type: i.Attributes.Type,
Priority: i.Attributes.Priority,
Impact: i.Attributes.Impact,
Environment: i.Attributes.Environment,
Owner: i.Attributes.Owner,
RelatedId: i.Attributes.RelatedId,
Service: i.Attributes.Service,
Status: i.Attributes.Status,
StartDate: i.Attributes.StartDate,
EndDate: i.Attributes.EndDate,
},
Links: &v1alpha1.EventLinks{
PullRequestLink: i.Links.PullRequestLink,
Expand Down Expand Up @@ -76,6 +81,9 @@ func (e *Event) CreateEvent(
"title", eventResult.Event.Title,
"message", eventResult.Event.Attributes.Message,
"priority", eventResult.Event.Attributes.Priority.String(),
"environment", eventResult.Event.Attributes.Environment.String(),
"owner", eventResult.Event.Attributes.Owner,
"impact", eventResult.Event.Attributes.Impact,
"service", eventResult.Event.Attributes.Service,
"status", eventResult.Event.Attributes.Status.String(),
"type", eventResult.Event.Attributes.Type.String(),
Expand Down

0 comments on commit e4b039e

Please sign in to comment.