Skip to content

Commit 2a8bf34

Browse files
committed
refac(observability): Use new WaitHelper for waiters
STACKITSDK-384 Signed-off-by: Alexander Dahmen <alexander.dahmen@inovex.de>
1 parent 26bdb2a commit 2a8bf34

4 files changed

Lines changed: 39 additions & 33 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,8 @@
312312
- **Breaking change:** Updated `InstanceSensitiveData` model because of misbehaving API
313313
- [v0.23.0](services/observability/CHANGELOG.md#v0230)
314314
- **Feature:** Introduce enums for various attributes
315+
- [v0.24.0](services/observability/CHANGELOG.md#v0240)
316+
- **Improvement:** Use new WaiterHelper for observability waiters
315317
- `opensearch`:
316318
- [v0.26.3](services/opensearch/CHANGELOG.md#v0263)
317319
- **Dependencies:** Bump STACKIT SDK core module from `v0.24.0` to `v0.24.1`

services/observability/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## v0.24.0
2+
- **Improvement:** Use new WaiterHelper for observability waiters
3+
14
## v0.23.0
25
- **Feature:** Introduce enums for various attributes
36

services/observability/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.23.0
1+
v0.24.0

services/observability/v1api/wait/wait.go

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package wait
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"time"
78

@@ -41,22 +42,22 @@ const (
4142

4243
// CreateInstanceWaitHandler will wait for instance creation
4344
func CreateInstanceWaitHandler(ctx context.Context, a observability.DefaultAPI, instanceId, projectId string) *wait.AsyncActionHandler[observability.GetInstanceResponse] {
44-
handler := wait.New(func() (waitFinished bool, response *observability.GetInstanceResponse, err error) {
45-
s, err := a.GetInstance(ctx, instanceId, projectId).Execute()
46-
if err != nil {
47-
return false, nil, err
48-
}
49-
if s == nil {
50-
return false, nil, nil
51-
}
52-
if s.Id == instanceId && s.Status == observability.STATUS_CREATE_SUCCEEDED {
53-
return true, s, nil
54-
}
55-
if s.Id == instanceId && s.Status == observability.STATUS_CREATE_FAILED {
56-
return true, s, fmt.Errorf("create failed for instance with id %s", instanceId)
57-
}
58-
return false, nil, nil
59-
})
45+
waitConfig := wait.WaiterHelper[observability.GetInstanceResponse, observability.Status]{
46+
FetchInstance: a.GetInstance(ctx, instanceId, projectId).Execute,
47+
GetState: func(s *observability.GetInstanceResponse) (observability.Status, error) {
48+
if s == nil {
49+
return "", errors.New("empty response")
50+
}
51+
if s.Id != instanceId {
52+
return "", fmt.Errorf("instance id mismatch: expected %s, got %s", instanceId, s.Id)
53+
}
54+
return s.Status, nil
55+
},
56+
ActiveState: []observability.Status{observability.STATUS_CREATE_SUCCEEDED},
57+
ErrorState: []observability.Status{observability.STATUS_CREATE_FAILED},
58+
}
59+
60+
handler := wait.New(waitConfig.Wait())
6061
handler.SetTimeout(45 * time.Minute)
6162
return handler
6263
}
@@ -86,22 +87,22 @@ func UpdateInstanceWaitHandler(ctx context.Context, a observability.DefaultAPI,
8687

8788
// DeleteInstanceWaitHandler will wait for instance deletion
8889
func DeleteInstanceWaitHandler(ctx context.Context, a observability.DefaultAPI, instanceId, projectId string) *wait.AsyncActionHandler[observability.GetInstanceResponse] {
89-
handler := wait.New(func() (waitFinished bool, response *observability.GetInstanceResponse, err error) {
90-
s, err := a.GetInstance(ctx, instanceId, projectId).Execute()
91-
if err != nil {
92-
return false, nil, err
93-
}
94-
if s == nil {
95-
return false, nil, nil
96-
}
97-
if s.Id == instanceId && s.Status == observability.STATUS_DELETE_SUCCEEDED {
98-
return true, s, nil
99-
}
100-
if s.Id == instanceId && s.Status == observability.STATUS_DELETE_FAILED {
101-
return true, s, fmt.Errorf("delete failed for instance with id %s", instanceId)
102-
}
103-
return false, nil, nil
104-
})
90+
waitConfig := wait.WaiterHelper[observability.GetInstanceResponse, observability.Status]{
91+
FetchInstance: a.GetInstance(ctx, instanceId, projectId).Execute,
92+
GetState: func(s *observability.GetInstanceResponse) (observability.Status, error) {
93+
if s == nil {
94+
return "", errors.New("empty response")
95+
}
96+
if s.Id != instanceId {
97+
return "", fmt.Errorf("instance id mismatch: expected %s, got %s", instanceId, s.Id)
98+
}
99+
return s.Status, nil
100+
},
101+
ActiveState: []observability.Status{observability.STATUS_DELETE_SUCCEEDED},
102+
ErrorState: []observability.Status{observability.STATUS_DELETE_FAILED},
103+
}
104+
105+
handler := wait.New(waitConfig.Wait())
105106
handler.SetTimeout(20 * time.Minute)
106107
return handler
107108
}

0 commit comments

Comments
 (0)