Skip to content

Commit 0435fa7

Browse files
committed
feat: support slack based alerts on failure and sla miss
1 parent a577ede commit 0435fa7

46 files changed

Lines changed: 4089 additions & 1679 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pack-files:
2727
generate-proto: ## regenerate protos
2828
@echo " > cloning protobuf from odpf/proton"
2929
@rm -rf proton/
30-
@git -c advice.detachedHead=false clone https://github.com/odpf/proton --depth 1 --quiet --branch main
30+
@git -c advice.detachedHead=false clone https://github.com/odpf/proton --depth 1 --quiet --branch optimus-job-event
3131
@echo " > generating protobuf"
3232
@echo " > info: make sure correct version of dependencies are installed using 'install'"
3333
@buf generate

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ brew install odpf/taps/optimus
6868
optimus version
6969
```
7070

71+
### Stability and Compatibility
72+
Optimus is currently undergoing heavy development with frequent, breaking API changes.
73+
74+
> ⭐ Current major version is zero (v0.x.x) to accommodate rapid development and fast iteration while getting early feedback from users (feedback on APIs are appreciated).
75+
> The public API could change without a major version update before v1.0.0 release.
76+
7177
## Credits
7278

7379
This project exists thanks to all the [contributors](https://github.com/odpf/optimus/graphs/contributors).

api/handler/v1/adapter.go

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,22 @@ func (adapt *Adapter) FromJobProto(spec *pb.JobSpecification) (models.JobSpec, e
7373
retryDelay := time.Duration(0)
7474
retryCount := 0
7575
retryExponentialBackoff := false
76-
if spec.Behavior != nil && spec.Behavior.Retry != nil {
77-
retryCount = int(spec.Behavior.Retry.Count)
78-
retryExponentialBackoff = spec.Behavior.Retry.ExponentialBackoff
79-
if spec.Behavior.Retry.Delay != nil && spec.Behavior.Retry.Delay.IsValid() {
80-
retryDelay = spec.Behavior.Retry.Delay.AsDuration()
76+
var notifiers []models.JobSpecNotifier
77+
if spec.Behavior != nil {
78+
if spec.Behavior.Retry != nil {
79+
retryCount = int(spec.Behavior.Retry.Count)
80+
retryExponentialBackoff = spec.Behavior.Retry.ExponentialBackoff
81+
if spec.Behavior.Retry.Delay != nil && spec.Behavior.Retry.Delay.IsValid() {
82+
retryDelay = spec.Behavior.Retry.Delay.AsDuration()
83+
}
84+
}
85+
86+
for _, notify := range spec.Behavior.Notify {
87+
notifiers = append(notifiers, models.JobSpecNotifier{
88+
On: models.JobEventType(strings.ToLower(notify.On.String())),
89+
Config: notify.Config,
90+
Channels: notify.Channels,
91+
})
8192
}
8293
}
8394
return models.JobSpec{
@@ -100,6 +111,7 @@ func (adapt *Adapter) FromJobProto(spec *pb.JobSpecification) (models.JobSpec, e
100111
Delay: retryDelay,
101112
ExponentialBackoff: retryExponentialBackoff,
102113
},
114+
Notify: notifiers,
103115
},
104116
Task: models.JobSpecTask{
105117
Unit: execUnit,
@@ -150,6 +162,15 @@ func (adapt *Adapter) ToJobProto(spec models.JobSpec) (*pb.JobSpecification, err
150162
return nil, err
151163
}
152164

165+
var notifyProto []*pb.JobSpecification_Behavior_Notifiers
166+
for _, notify := range spec.Behavior.Notify {
167+
notifyProto = append(notifyProto, &pb.JobSpecification_Behavior_Notifiers{
168+
On: pb.JobEvent_Type(pb.JobEvent_Type_value[strings.ToUpper(string(notify.On))]),
169+
Channels: notify.Channels,
170+
Config: notify.Config,
171+
})
172+
}
173+
153174
conf := &pb.JobSpecification{
154175
Version: int32(spec.Version),
155176
Name: spec.Name,
@@ -173,6 +194,7 @@ func (adapt *Adapter) ToJobProto(spec models.JobSpec) (*pb.JobSpecification, err
173194
Delay: ptypes.DurationProto(spec.Behavior.Retry.Delay),
174195
ExponentialBackoff: spec.Behavior.Retry.ExponentialBackoff,
175196
},
197+
Notify: notifyProto,
176198
},
177199
}
178200
if spec.Schedule.EndDate != nil {
@@ -185,7 +207,7 @@ func (adapt *Adapter) ToJobProto(spec models.JobSpec) (*pb.JobSpecification, err
185207
})
186208
}
187209

188-
taskConfigs := []*pb.JobConfigItem{}
210+
var taskConfigs []*pb.JobConfigItem
189211
for _, c := range spec.Task.Config {
190212
taskConfigs = append(taskConfigs, &pb.JobConfigItem{
191213
Name: strings.ToUpper(c.Name),

api/handler/v1/adapter_test.go

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ func TestAdapter(t *testing.T) {
4141
allTasksRepo.On("GetByName", "sample-task").Return(execUnit1, nil)
4242
defer allTasksRepo.AssertExpectations(t)
4343

44+
hookUnit1 := new(mock.HookPlugin)
45+
hookUnit1.On("GetHookSchema", context.Background(), models.GetHookSchemaRequest{}).Return(models.GetHookSchemaResponse{
46+
Name: "sample-hook",
47+
}, nil)
48+
defer hookUnit1.AssertExpectations(t)
49+
50+
allHookRepo := new(mock.SupportedHookRepo)
51+
allHookRepo.On("GetByName", "sample-hook").Return(hookUnit1, nil)
52+
defer allHookRepo.AssertExpectations(t)
53+
4454
jobSpec := models.JobSpec{
4555
Name: "test-job",
4656
Schedule: models.JobSpecSchedule{
@@ -55,6 +65,15 @@ func TestAdapter(t *testing.T) {
5565
Delay: 0,
5666
ExponentialBackoff: true,
5767
},
68+
Notify: []models.JobSpecNotifier{
69+
{
70+
On: models.JobEventTypeFailure,
71+
Config: map[string]string{
72+
"key": "val",
73+
},
74+
Channels: []string{"slack://@devs"},
75+
},
76+
},
5877
},
5978
Task: models.JobSpecTask{
6079
Unit: execUnit1,
@@ -79,9 +98,20 @@ func TestAdapter(t *testing.T) {
7998
},
8099
),
81100
Dependencies: map[string]models.JobSpecDependency{},
101+
Hooks: []models.JobSpecHook{
102+
{
103+
Config: models.JobSpecConfigs{
104+
{
105+
Name: "PROJECT",
106+
Value: "this",
107+
},
108+
},
109+
Unit: hookUnit1,
110+
},
111+
},
82112
}
83113

84-
adapter := v1.NewAdapter(allTasksRepo, nil, nil)
114+
adapter := v1.NewAdapter(allTasksRepo, allHookRepo, nil)
85115
inProto, err := adapter.ToJobProto(jobSpec)
86116
assert.Nil(t, err)
87117
original, err := adapter.FromJobProto(inProto)

0 commit comments

Comments
 (0)