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

Fallback Pipeline addition in core/v2 #16

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
working_directory: ~/core/<< parameters.module>>
executor:
name: go/default
tag: '1.18'
tag: '1.19'
steps:
- checkout:
path: ~/core
Expand Down
4 changes: 4 additions & 0 deletions v2/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ func NewCheck(c *CheckConfig) *Check {
MaxOutputSize: c.MaxOutputSize,
Scheduler: c.Scheduler,
Pipelines: c.Pipelines,
FallbackPipeline: c.FallbackPipeline,
}
if check.Labels == nil {
check.Labels = make(map[string]string)
Expand Down Expand Up @@ -268,6 +269,9 @@ func (c *Check) MarshalJSON() ([]byte, error) {
if c.Pipelines == nil {
c.Pipelines = []*ResourceReference{}
}
if c.FallbackPipeline == nil {
c.FallbackPipeline = []*ResourceReference{}
}

type Clone Check
clone := &Clone{}
Expand Down
529 changes: 345 additions & 184 deletions v2/check.pb.go

Large diffs are not rendered by default.

15 changes: 11 additions & 4 deletions v2/check.proto
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,13 @@ message CheckConfig {
// Pipelines are the pipelines this check will use to process its events.
repeated ResourceReference pipelines = 32 [ (gogoproto.jsontag) = "pipelines" ];

repeated MetricThreshold output_metric_thresholds = 33 [ (gogoproto.jsontag) = "output_metric_thresholds,omitempty", (gogoproto.moretags) = "yaml: \"output_metric_thresholds,omitempty\"" ];
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe we need to avoid changing field numbers since they're used for serialization/deserialization. We might end up with a scenario where the data was stored with field number 33 in etcd and read back with field number 34, effectively breaking serialization.

//added fallback pieplines detials in order of execution
repeated ResourceReference fallback_pipeline = 33 [ (gogoproto.jsontag) = "fallback_pipeline" ,(gogoproto.moretags) = "yaml: \"fallback_pipeline,omitempty\"" ];

repeated TimeWindowRepeated subdues = 34 [ (gogoproto.jsontag) = "subdues,omitempty" ];

repeated MetricThreshold output_metric_thresholds = 34 [ (gogoproto.jsontag) = "output_metric_thresholds,omitempty", (gogoproto.moretags) = "yaml: \"output_metric_thresholds,omitempty\"" ];

repeated TimeWindowRepeated subdues = 35 [ (gogoproto.jsontag) = "subdues,omitempty" ];
}

// A Check is a check specification and optionally the results of the check's
Expand Down Expand Up @@ -328,11 +332,14 @@ message Check {
// Pipelines are the pipelines this check will use to process its events.
repeated ResourceReference pipelines = 46 [ (gogoproto.jsontag) = "pipelines" ];

//fallback pieplines detials in order of execution
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: should be details

repeated ResourceReference fallback_pipeline = 47 [ (gogoproto.jsontag) = "fallback_pipeline" ,(gogoproto.moretags) = "yaml: \"fallback_pipeline,omitempty\"" ];
Copy link
Contributor

Choose a reason for hiding this comment

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

If there can be more than one this field should be plural (fallback_pipelines).


// MetricThresholds are a list of thresholds to apply to metrics in order to determine
// the check status.
repeated MetricThreshold output_metric_thresholds = 47 [ (gogoproto.jsontag) = "output_metric_thresholds,omitempty", (gogoproto.moretags) = "yaml: \"output_metric_thresholds,omitempty\"" ];
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment about field numbers.

repeated MetricThreshold output_metric_thresholds = 48 [ (gogoproto.jsontag) = "output_metric_thresholds,omitempty", (gogoproto.moretags) = "yaml: \"output_metric_thresholds,omitempty\"" ];

repeated TimeWindowRepeated subdues = 48 [ (gogoproto.jsontag) = "subdues,omitempty" ];
repeated TimeWindowRepeated subdues = 49 [ (gogoproto.jsontag) = "subdues,omitempty" ];

// ExtendedAttributes store serialized arbitrary JSON-encoded data
bytes ExtendedAttributes = 99 [ (gogoproto.jsontag) = "-" ];
Expand Down
19 changes: 19 additions & 0 deletions v2/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ func (e *Event) Validate() error {
}
}

for _, fallpipeline := range e.FallbackPipeline {
if err := e.validateFallbackPipelineReference(fallpipeline); err != nil {
return errors.New("Fallback-pipeline reference is invalid: " + err.Error())
}
}

if e.Name != "" {
return errors.New("events cannot be named")
}
Expand Down Expand Up @@ -205,6 +211,19 @@ func (e *Event) validatePipelineReference(ref *ResourceReference) error {
return fmt.Errorf("resource type not capable of acting as a pipeline: %s.%s", ref.APIVersion, ref.Type)
}

// validateFallbackPipelineReference validates that a resource reference is capable of
// acting as a pipeline.
func (e *Event) validateFallbackPipelineReference(ref *ResourceReference) error {
switch ref.APIVersion {
case "core/v2":
switch ref.Type {
case "LegacyPipeline":
return nil
}
}
return fmt.Errorf("resource type not capable of acting as a fallbackpipeline: %s.%s", ref.APIVersion, ref.Type)
}

// FixtureEvent returns a testing fixture for an Event object.
func FixtureEvent(entityName, checkID string) *Event {
id := uuid.New()
Expand Down
153 changes: 116 additions & 37 deletions v2/event.pb.go

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

2 changes: 2 additions & 0 deletions v2/event.proto
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,6 @@ message Event {
// APIVersion should default to "core/v2" and Type should default to
// "Pipeline".
repeated ResourceReference pipelines = 8 [ (gogoproto.jsontag) = "pipelines" ];
//fallback pipeline
repeated ResourceReference fallback_pipeline = 9 [ (gogoproto.jsontag) = "fallback_pipeline" ];
}
Loading