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 16 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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.22'
steps:
- checkout:
path: ~/core
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM golang:1.18-bullseye
FROM golang:1.22-bullseye

RUN apt-get update && apt-get upgrade -y && apt-get install -y unzip

ARG protoc_version=3.19.4
ARG protoc_arch=x86_64
ARG protoc_arch=aarch_64
ARG protoc_release=https://github.com/protocolbuffers/protobuf/releases/download/v${protoc_version}/protoc-${protoc_version}-linux-${protoc_arch}.zip

ADD $protoc_release /opt/protoc.zip
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,
FallbackPipelines: c.FallbackPipelines,
}
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.FallbackPipelines == nil {
c.FallbackPipelines = []*ResourceReference{}
}

type Clone Check
clone := &Clone{}
Expand Down
511 changes: 336 additions & 175 deletions v2/check.pb.go

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions v2/check.proto
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ message CheckConfig {
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.


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

//added fallback pieplines details in order of execution
repeated ResourceReference fallback_pipelines = 35 [ (gogoproto.jsontag) = "fallback_pipelines" ,(gogoproto.moretags) = "yaml: \"fallback_pipelines,omitempty\"" ];
}

// A Check is a check specification and optionally the results of the check's
Expand Down Expand Up @@ -334,6 +337,9 @@ message Check {

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

//fallback pieplines details in order of execution
repeated ResourceReference fallback_pipelines = 49 [ (gogoproto.jsontag) = "fallback_pipelines" ,(gogoproto.moretags) = "yaml: \"fallback_pipelines,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 _, fallpipelines := range e.FallbackPipelines {
if err := e.validateFallbackPipelineReference(fallpipelines); 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 pipelines
repeated ResourceReference fallback_pipelines = 9 [ (gogoproto.jsontag) = "fallback_pipelines" ];
}
Loading
Loading