From 4d17561e61cad6a9205cd448b6d54bedb064c9f2 Mon Sep 17 00:00:00 2001 From: Oleksandr Zanichkovskyi Date: Tue, 28 Apr 2026 21:17:32 +0200 Subject: [PATCH 01/11] feat: telemetryrouter waiters and examples --- examples/telemetryrouter/go.mod | 16 + examples/telemetryrouter/go.sum | 8 + examples/telemetryrouter/telemetryrouter.go | 234 ++++++ go.work | 1 + services/telemetryrouter/go.mod | 5 +- .../telemetryrouter/v1betaapi/wait/wait.go | 199 +++++ .../v1betaapi/wait/wait_test.go | 707 ++++++++++++++++++ 7 files changed, 1169 insertions(+), 1 deletion(-) create mode 100644 examples/telemetryrouter/go.mod create mode 100644 examples/telemetryrouter/go.sum create mode 100644 examples/telemetryrouter/telemetryrouter.go create mode 100644 services/telemetryrouter/v1betaapi/wait/wait.go create mode 100644 services/telemetryrouter/v1betaapi/wait/wait_test.go diff --git a/examples/telemetryrouter/go.mod b/examples/telemetryrouter/go.mod new file mode 100644 index 000000000..8b5f0ac9a --- /dev/null +++ b/examples/telemetryrouter/go.mod @@ -0,0 +1,16 @@ +module github.com/stackitcloud/stackit-sdk-go/examples/telemetryrouter + +go 1.25 + +// This is not needed in production. This is only here to point the golangci linter to the local version instead of the last release on GitHub. +replace github.com/stackitcloud/stackit-sdk-go/services/telemetryrouter => ../../services/telemetryrouter + +require ( + github.com/stackitcloud/stackit-sdk-go/core v0.26.0 + github.com/stackitcloud/stackit-sdk-go/services/telemetryrouter v0.1.0 +) + +require ( + github.com/golang-jwt/jwt/v5 v5.3.1 // indirect + github.com/google/uuid v1.6.0 // indirect +) diff --git a/examples/telemetryrouter/go.sum b/examples/telemetryrouter/go.sum new file mode 100644 index 000000000..3712a0c87 --- /dev/null +++ b/examples/telemetryrouter/go.sum @@ -0,0 +1,8 @@ +github.com/golang-jwt/jwt/v5 v5.3.1 h1:kYf81DTWFe7t+1VvL7eS+jKFVWaUnK9cB1qbwn63YCY= +github.com/golang-jwt/jwt/v5 v5.3.1/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE= +github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= +github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/stackitcloud/stackit-sdk-go/core v0.26.0 h1:jQEb9gkehfp6VCP6TcYk7BI10cz4l0KM2L6hqYBH2QA= +github.com/stackitcloud/stackit-sdk-go/core v0.26.0/go.mod h1:WU1hhxnjXw2EV7CYa1nlEvNpMiRY6CvmIOaHuL3pOaA= diff --git a/examples/telemetryrouter/telemetryrouter.go b/examples/telemetryrouter/telemetryrouter.go new file mode 100644 index 000000000..56f2a156f --- /dev/null +++ b/examples/telemetryrouter/telemetryrouter.go @@ -0,0 +1,234 @@ +package main + +import ( + "context" + "log" + + "github.com/stackitcloud/stackit-sdk-go/core/utils" + telemetryrouter "github.com/stackitcloud/stackit-sdk-go/services/telemetryrouter/v1betaapi" +) + +func main() { + ctx := context.Background() + + projectId := "PROJECT_ID" // the uuid of your STACKIT project + regionId := "eu01" + + client, err := telemetryrouter.NewAPIClient() + if err != nil { + log.Fatalf("[TelemetryRouter API] Creating API client: %v\n", err) + } + + // Create a Telemetry Router Instance + var createdInstance string + createInstancePayload := telemetryrouter.CreateTelemetryRouterPayload{ + DisplayName: "my-tlmr-instance", + } + createResp, err := client.DefaultAPI.CreateTelemetryRouter(ctx, projectId, regionId). + CreateTelemetryRouterPayload(createInstancePayload). + Execute() + if err != nil { + log.Fatalf("[TelemetryRouter API] Error when calling `CreateTelemetryRouter`: %v\n", err) + } + log.Printf("[TelemetryRouter API] Created TelemetryRouter Instance with ID \"%s\".\n", createResp.Id) + createdInstance = createResp.Id + + // List Telemetry Router Instances + listResp, err := client.DefaultAPI.ListTelemetryRouters(ctx, projectId, regionId).Execute() + if err != nil { + log.Fatalf("[Telemetry Router API] Error when calling `ListTelemetryRouters`: %v\n", err) + } + log.Printf("[Telemetry Router API] Retrieved %d Logs Instances.\n", len(listResp.TelemetryRouters)) + + // Get the created Telemetry Router Instance + getResp, err := client.DefaultAPI.GetTelemetryRouter(ctx, projectId, regionId, createdInstance).Execute() + if err != nil { + log.Fatalf("[Telemetry Router API] Error when calling `GetTelemetryRouter`: %v\n", err) + } + log.Printf("[Telemetry Router API] Retrieved TelemetryRouter Instance with ID \"%s\" and Display Name \"%s\".\n", getResp.Id, getResp.DisplayName) + + // Update the created Telemetry Router Instance + updatePayload := telemetryrouter.UpdateTelemetryRouterPayload{ + DisplayName: utils.Ptr("my-updated-tlmr-instance"), + Filter: &telemetryrouter.ConfigFilter{ + Attributes: []telemetryrouter.ConfigFilterAttributes{ + { + Key: "service.name", + Level: "logRecord", + Matcher: "=", + Values: []string{"service1", "service2"}, + }, + }, + }, + } + updateResp, err := client.DefaultAPI.UpdateTelemetryRouter(ctx, projectId, regionId, createdInstance). + UpdateTelemetryRouterPayload(updatePayload). + Execute() + if err != nil { + log.Fatalf("[Telemetry Router API] Error when calling `UpdateTelemetryRouter`: %v\n", err) + } + log.Printf("[Telemetry Router API] Updated Telemetry Router Instance with ID \"%s\" to Display Name \"%s\".\n", updateResp.Id, updateResp.DisplayName) + + // Create an Access Token + createTokenPayload := telemetryrouter.CreateAccessTokenPayload{ + DisplayName: "my-access-token", + } + createTokenResp, err := client.DefaultAPI.CreateAccessToken(ctx, projectId, regionId, createdInstance). + CreateAccessTokenPayload(createTokenPayload). + Execute() + if err != nil { + log.Fatalf("[Telemetry Router API] Error when calling `CreateAccessToken`: %v\n", err) + } + log.Printf("[Telemetry Router API] Created Access Token with ID \"%s\".\n", createTokenResp.Id) + + newDisplayName := "my-updated-acc-token" + newDisplayNameNS := telemetryrouter.NullableString{} + newDisplayNameNS.Set(&newDisplayName) + updateTokenPayload := telemetryrouter.UpdateAccessTokenPayload{ + DisplayName: newDisplayNameNS, + } + // Update an Access Token + updateTokenResp, err := client.DefaultAPI.UpdateAccessToken(ctx, projectId, regionId, createdInstance, createTokenResp.Id). + UpdateAccessTokenPayload(updateTokenPayload). + Execute() + if err != nil { + log.Fatalf("[Telemetry Router API] Error when calling `UpdateAccessToken`: %v\n", err) + } + log.Printf("[Telemetry Router API] Updated Access Token with ID \"%s\" to Display Name \"%s\".\n.\n", updateTokenResp.Id, updateTokenResp.DisplayName) + + // Delete Access Token + err = client.DefaultAPI.DeleteAccessToken(ctx, projectId, regionId, createdInstance, updateTokenResp.Id).Execute() + if err != nil { + log.Fatalf("[Telemetry Router API] Error when calling `DeleteAccessToken`: %v\n", err) + } + log.Printf("[Telemetry Router API] Deleted Access Tokens.\n") + + // Create S3 Destination + createS3DestinationPayload := telemetryrouter.CreateDestinationPayload{ + DisplayName: "s3-destination", + Config: telemetryrouter.DestinationConfig{ + ConfigType: "S3", + S3: &telemetryrouter.DestinationConfigS3{ + AccessKey: &telemetryrouter.DestinationConfigS3AccessKey{ + Id: "id", + Secret: "secret", + }, + Bucket: "bucket", + Endpoint: "https://bucket.endpoint.com", + }, + }, + } + createS3DestinationResp, err := client.DefaultAPI.CreateDestination(ctx, projectId, regionId, createdInstance). + CreateDestinationPayload(createS3DestinationPayload).Execute() + if err != nil { + log.Fatalf("[Telemetry Router API] Error when calling `CreateDestination`: %v\n", err) + } + log.Printf("[Telemetry Router API] Created Destination with ID \"%s\".\n", createS3DestinationResp.Id) + + // Update S3 Destination + newS3DestinationDisplayName := "updated-s3-destination" + updateS3DestinationPayload := telemetryrouter.UpdateDestinationPayload{ + DisplayName: &newS3DestinationDisplayName, + Config: &telemetryrouter.DestinationConfig{ + ConfigType: "S3", + S3: &telemetryrouter.DestinationConfigS3{ + AccessKey: &telemetryrouter.DestinationConfigS3AccessKey{ + Id: "id", + Secret: "secret", + }, + Bucket: "bucket", + Endpoint: "https://bucket.endpoint.com", + }, + Filter: &telemetryrouter.ConfigFilter{ + Attributes: []telemetryrouter.ConfigFilterAttributes{ + { + Key: "service.name", + Level: "logRecord", + Matcher: "=", + Values: []string{"service1", "service2"}, + }, + }, + }, + }, + } + updateS3DestinationResp, err := client.DefaultAPI.UpdateDestination(ctx, projectId, regionId, createdInstance, createS3DestinationResp.Id). + UpdateDestinationPayload(updateS3DestinationPayload).Execute() + if err != nil { + log.Fatalf("[Telemetry Router API] Error when calling `UpdateDestination`: %v\n", err) + } + log.Printf("[Telemetry Router API] Updated Destination with ID \"%s\".\n", updateS3DestinationResp.Id) + + // Delete S3 Destination + err = client.DefaultAPI.DeleteDestination(ctx, projectId, regionId, createdInstance, updateS3DestinationResp.Id).Execute() + if err != nil { + log.Fatalf("[Telemetry Router API] Error when calling `DeleteDestination`: %v\n", err) + } + log.Printf("[Telemetry Router API] Deleted Destination with ID \"%s\".\n", updateS3DestinationResp.Id) + + // Create OpenTelemetry Destination + createOpenTelemetryDestinationPayload := telemetryrouter.CreateDestinationPayload{ + DisplayName: "otlp-destination", + Config: telemetryrouter.DestinationConfig{ + ConfigType: "OpenTelemetry", + OpenTelemetry: &telemetryrouter.DestinationConfigOpenTelemetry{ + BasicAuth: &telemetryrouter.DestinationConfigOpenTelemetryBasicAuth{ + Password: "password", + Username: "user", + }, + Uri: "https://otlp.endpoint.com/v1/logs", + }, + }, + } + createOpenTelemetryDestinationResp, err := client.DefaultAPI.CreateDestination(ctx, projectId, regionId, createdInstance). + CreateDestinationPayload(createOpenTelemetryDestinationPayload).Execute() + if err != nil { + log.Fatalf("[Telemetry Router API] Error when calling `CreateDestination`: %v\n", err) + } + log.Printf("[Telemetry Router API] Created Destination with ID \"%s\".\n", createOpenTelemetryDestinationResp.Id) + + // Update S3 Destination + newOTLPDestinationDisplayName := "updated-otlp-destination" + updateOTLPDestinationPayload := telemetryrouter.UpdateDestinationPayload{ + DisplayName: &newOTLPDestinationDisplayName, + Config: &telemetryrouter.DestinationConfig{ + ConfigType: "OpenTelemetry", + OpenTelemetry: &telemetryrouter.DestinationConfigOpenTelemetry{ + BasicAuth: &telemetryrouter.DestinationConfigOpenTelemetryBasicAuth{ + Username: "user1", + Password: "pass", + }, + Uri: "https://otlp.endpoint.com/v1/logs", + }, + Filter: &telemetryrouter.ConfigFilter{ + Attributes: []telemetryrouter.ConfigFilterAttributes{ + { + Key: "service.name", + Level: "logRecord", + Matcher: "=", + Values: []string{"service1", "service2"}, + }, + }, + }, + }, + } + updateOTLPDestinationResp, err := client.DefaultAPI.UpdateDestination(ctx, projectId, regionId, createdInstance, createS3DestinationResp.Id). + UpdateDestinationPayload(updateOTLPDestinationPayload).Execute() + if err != nil { + log.Fatalf("[Telemetry Router API] Error when calling `UpdateDestination`: %v\n", err) + } + log.Printf("[Telemetry Router API] Updated Destination with ID \"%s\".\n", updateOTLPDestinationResp.Id) + + // Delete OpenTelemetry Destination + err = client.DefaultAPI.DeleteDestination(ctx, projectId, regionId, createdInstance, updateOTLPDestinationResp.Id).Execute() + if err != nil { + log.Fatalf("[Telemetry Router API] Error when calling `DeleteDestination`: %v\n", err) + } + log.Printf("[Telemetry Router API] Deleted Destination with ID \"%s\".\n", updateOTLPDestinationResp.Id) + + // Delete the created TelemetryRouter Instance + err = client.DefaultAPI.DeleteTelemetryRouter(ctx, projectId, regionId, createdInstance).Execute() + if err != nil { + log.Fatalf("[Telemetry Router API] Error when calling `DeleteTelemetryRouter`: %v\n", err) + } + log.Printf("[Telemetry Router API] Deleted Telemetry Router Instance with ID \"%s\".\n", createdInstance) +} diff --git a/go.work b/go.work index 570ca9e4d..cf8c009e8 100644 --- a/go.work +++ b/go.work @@ -34,6 +34,7 @@ use ( ./examples/sfs ./examples/ske ./examples/sqlserverflex + ./examples/telemetryrouter ./examples/waiter ./services/alb ./services/albwaf diff --git a/services/telemetryrouter/go.mod b/services/telemetryrouter/go.mod index 81adf4d2a..a1ccc874f 100644 --- a/services/telemetryrouter/go.mod +++ b/services/telemetryrouter/go.mod @@ -2,7 +2,10 @@ module github.com/stackitcloud/stackit-sdk-go/services/telemetryrouter go 1.25 -require github.com/stackitcloud/stackit-sdk-go/core v0.26.0 +require ( + github.com/google/go-cmp v0.7.0 + github.com/stackitcloud/stackit-sdk-go/core v0.26.0 +) require ( github.com/golang-jwt/jwt/v5 v5.3.1 // indirect diff --git a/services/telemetryrouter/v1betaapi/wait/wait.go b/services/telemetryrouter/v1betaapi/wait/wait.go new file mode 100644 index 000000000..a8a0ab703 --- /dev/null +++ b/services/telemetryrouter/v1betaapi/wait/wait.go @@ -0,0 +1,199 @@ +package wait + +import ( + "context" + "errors" + "net/http" + "time" + + "github.com/stackitcloud/stackit-sdk-go/core/wait" + telemetryrouter "github.com/stackitcloud/stackit-sdk-go/services/telemetryrouter/v1betaapi" +) + +const ( + TELEMETRYROUTER_ACTIVE = "active" + TELEMETRYROUTER_DELETED = "deleted" + TELEMETRYROUTER_FAILED = "failed" + + DESTINATION_ACTIVE = "active" + DESTINATION_DELETED = "deleted" + DESTINATION_FAILED = "failed" + + ACCESSTOKEN_ACTIVE = "active" + ACCESSTOKEN_DELETED = "deleted" + ACCESSTOKEN_FAILED = "failed" +) + +// CreateTelemetryRouterWaitHandler will wait for TelemetryRouter creation +func CreateTelemetryRouterWaitHandler(ctx context.Context, a telemetryrouter.DefaultAPI, projectId, regionId, instanceId string) *wait.AsyncActionHandler[telemetryrouter.TelemetryRouterResponse] { + waitConfig := wait.WaiterHelper[telemetryrouter.TelemetryRouterResponse, string]{ + FetchInstance: a.GetTelemetryRouter(ctx, projectId, regionId, instanceId).Execute, + GetState: func(d *telemetryrouter.TelemetryRouterResponse) (string, error) { + if d == nil { + return "", errors.New("empty response") + } + return d.Status, nil + }, + ActiveState: []string{TELEMETRYROUTER_ACTIVE}, + ErrorState: []string{TELEMETRYROUTER_FAILED}, + } + + handler := wait.New(waitConfig.Wait()) + handler.SetTimeout(10 * time.Minute) + return handler +} + +// UpdateTelemetryRouterWaitHandler will wait for TelemetryRouter update +func UpdateTelemetryRouterWaitHandler(ctx context.Context, a telemetryrouter.DefaultAPI, projectId, regionId, instanceId string) *wait.AsyncActionHandler[telemetryrouter.TelemetryRouterResponse] { + waitConfig := wait.WaiterHelper[telemetryrouter.TelemetryRouterResponse, string]{ + FetchInstance: a.GetTelemetryRouter(ctx, projectId, regionId, instanceId).Execute, + GetState: func(d *telemetryrouter.TelemetryRouterResponse) (string, error) { + if d == nil { + return "", errors.New("empty response") + } + return d.Status, nil + }, + ActiveState: []string{TELEMETRYROUTER_ACTIVE}, + ErrorState: []string{TELEMETRYROUTER_FAILED}, + } + + handler := wait.New(waitConfig.Wait()) + handler.SetTimeout(10 * time.Minute) + return handler +} + +// DeleteTelemetryRouterWaitHandler will wait for TelemetryRouter deletion +func DeleteTelemetryRouterWaitHandler(ctx context.Context, a telemetryrouter.DefaultAPI, projectId, regionId, instanceId string) *wait.AsyncActionHandler[telemetryrouter.TelemetryRouterResponse] { + waitConfig := wait.WaiterHelper[telemetryrouter.TelemetryRouterResponse, string]{ + FetchInstance: a.GetTelemetryRouter(ctx, projectId, regionId, instanceId).Execute, + GetState: func(d *telemetryrouter.TelemetryRouterResponse) (string, error) { + if d == nil { + return "", errors.New("empty response") + } + return d.Status, nil + }, + ActiveState: []string{TELEMETRYROUTER_DELETED}, + ErrorState: []string{TELEMETRYROUTER_FAILED}, + DeleteHttpErrorStatusCodes: []int{http.StatusNotFound}, + } + + handler := wait.New(waitConfig.Wait()) + handler.SetTimeout(10 * time.Minute) + return handler +} + +// CreateDestinationWaitHandler will wait for Destination creation +func CreateDestinationWaitHandler(ctx context.Context, a telemetryrouter.DefaultAPI, projectId, regionId, instanceId, destinationId string) *wait.AsyncActionHandler[telemetryrouter.DestinationResponse] { + waitConfig := wait.WaiterHelper[telemetryrouter.DestinationResponse, string]{ + FetchInstance: a.GetDestination(ctx, projectId, regionId, instanceId, destinationId).Execute, + GetState: func(d *telemetryrouter.DestinationResponse) (string, error) { + if d == nil { + return "", errors.New("empty response") + } + return d.Status, nil + }, + ActiveState: []string{DESTINATION_ACTIVE}, + ErrorState: []string{DESTINATION_FAILED}, + } + + handler := wait.New(waitConfig.Wait()) + handler.SetTimeout(10 * time.Minute) + return handler +} + +// UpdateDestinationWaitHandler will wait for Destination update +func UpdateDestinationWaitHandler(ctx context.Context, a telemetryrouter.DefaultAPI, projectId, regionId, instanceId, destinationId string) *wait.AsyncActionHandler[telemetryrouter.DestinationResponse] { + waitConfig := wait.WaiterHelper[telemetryrouter.DestinationResponse, string]{ + FetchInstance: a.GetDestination(ctx, projectId, regionId, instanceId, destinationId).Execute, + GetState: func(d *telemetryrouter.DestinationResponse) (string, error) { + if d == nil { + return "", errors.New("empty response") + } + return d.Status, nil + }, + ActiveState: []string{DESTINATION_ACTIVE}, + ErrorState: []string{DESTINATION_FAILED}, + } + + handler := wait.New(waitConfig.Wait()) + handler.SetTimeout(10 * time.Minute) + return handler +} + +// DeleteDestinationWaitHandler will wait for Destination deletion +func DeleteDestinationWaitHandler(ctx context.Context, a telemetryrouter.DefaultAPI, projectId, regionId, instanceId, destinationId string) *wait.AsyncActionHandler[telemetryrouter.DestinationResponse] { + waitConfig := wait.WaiterHelper[telemetryrouter.DestinationResponse, string]{ + FetchInstance: a.GetDestination(ctx, projectId, regionId, instanceId, destinationId).Execute, + GetState: func(d *telemetryrouter.DestinationResponse) (string, error) { + if d == nil { + return "", errors.New("empty response") + } + return d.Status, nil + }, + ActiveState: []string{DESTINATION_DELETED}, + ErrorState: []string{DESTINATION_FAILED}, + DeleteHttpErrorStatusCodes: []int{http.StatusNotFound}, + } + + handler := wait.New(waitConfig.Wait()) + handler.SetTimeout(10 * time.Minute) + return handler +} + +// CreateAccessTokenWaitHandler will wait for AccessToken creation +func CreateAccessTokenWaitHandler(ctx context.Context, a telemetryrouter.DefaultAPI, projectId, regionId, instanceId, accessTokenId string) *wait.AsyncActionHandler[telemetryrouter.GetAccessTokenResponse] { + waitConfig := wait.WaiterHelper[telemetryrouter.GetAccessTokenResponse, string]{ + FetchInstance: a.GetAccessToken(ctx, projectId, regionId, instanceId, accessTokenId).Execute, + GetState: func(d *telemetryrouter.GetAccessTokenResponse) (string, error) { + if d == nil { + return "", errors.New("empty response") + } + return d.Status, nil + }, + ActiveState: []string{ACCESSTOKEN_ACTIVE}, + ErrorState: []string{ACCESSTOKEN_FAILED}, + } + + handler := wait.New(waitConfig.Wait()) + handler.SetTimeout(10 * time.Minute) + return handler +} + +// UpdateAccessTokenWaitHandler will wait for AccessToken update +func UpdateAccessTokenWaitHandler(ctx context.Context, a telemetryrouter.DefaultAPI, projectId, regionId, instanceId, accessTokenId string) *wait.AsyncActionHandler[telemetryrouter.GetAccessTokenResponse] { + waitConfig := wait.WaiterHelper[telemetryrouter.GetAccessTokenResponse, string]{ + FetchInstance: a.GetAccessToken(ctx, projectId, regionId, instanceId, accessTokenId).Execute, + GetState: func(d *telemetryrouter.GetAccessTokenResponse) (string, error) { + if d == nil { + return "", errors.New("empty response") + } + return d.Status, nil + }, + ActiveState: []string{ACCESSTOKEN_ACTIVE}, + ErrorState: []string{ACCESSTOKEN_FAILED}, + } + + handler := wait.New(waitConfig.Wait()) + handler.SetTimeout(10 * time.Minute) + return handler +} + +// DeleteAccessTokenWaitHandler will wait for AccessToken deletion +func DeleteAccessTokenWaitHandler(ctx context.Context, a telemetryrouter.DefaultAPI, projectId, regionId, instanceId, accessTokenId string) *wait.AsyncActionHandler[telemetryrouter.GetAccessTokenResponse] { + waitConfig := wait.WaiterHelper[telemetryrouter.GetAccessTokenResponse, string]{ + FetchInstance: a.GetAccessToken(ctx, projectId, regionId, instanceId, accessTokenId).Execute, + GetState: func(d *telemetryrouter.GetAccessTokenResponse) (string, error) { + if d == nil { + return "", errors.New("empty response") + } + return d.Status, nil + }, + ActiveState: []string{ACCESSTOKEN_DELETED}, + ErrorState: []string{ACCESSTOKEN_FAILED}, + DeleteHttpErrorStatusCodes: []int{http.StatusNotFound}, + } + + handler := wait.New(waitConfig.Wait()) + handler.SetTimeout(10 * time.Minute) + return handler +} diff --git a/services/telemetryrouter/v1betaapi/wait/wait_test.go b/services/telemetryrouter/v1betaapi/wait/wait_test.go new file mode 100644 index 000000000..87c0cb898 --- /dev/null +++ b/services/telemetryrouter/v1betaapi/wait/wait_test.go @@ -0,0 +1,707 @@ +package wait + +import ( + "context" + "testing" + "testing/synctest" + "time" + + "github.com/google/go-cmp/cmp" + + "github.com/stackitcloud/stackit-sdk-go/core/oapierror" + "github.com/stackitcloud/stackit-sdk-go/core/utils" + telemetryrouter "github.com/stackitcloud/stackit-sdk-go/services/telemetryrouter/v1betaapi" +) + +type mockSettings struct { + getFails bool + resourceState string +} + +func newAPIMock(settings mockSettings) telemetryrouter.DefaultAPI { + return &telemetryrouter.DefaultAPIServiceMock{ + GetTelemetryRouterExecuteMock: utils.Ptr(func(_ telemetryrouter.ApiGetTelemetryRouterRequest) (*telemetryrouter.TelemetryRouterResponse, error) { + if settings.getFails { + return nil, &oapierror.GenericOpenAPIError{ + StatusCode: 500, + } + } + + return &telemetryrouter.TelemetryRouterResponse{ + Id: "trid", + Status: settings.resourceState, + }, nil + }), + GetDestinationExecuteMock: utils.Ptr(func(_ telemetryrouter.ApiGetDestinationRequest) (*telemetryrouter.DestinationResponse, error) { + if settings.getFails { + return nil, &oapierror.GenericOpenAPIError{ + StatusCode: 500, + } + } + + return &telemetryrouter.DestinationResponse{ + Id: "did", + Status: settings.resourceState, + }, nil + }), + GetAccessTokenExecuteMock: utils.Ptr(func(_ telemetryrouter.ApiGetAccessTokenRequest) (*telemetryrouter.GetAccessTokenResponse, error) { + if settings.getFails { + return nil, &oapierror.GenericOpenAPIError{ + StatusCode: 500, + } + } + + return &telemetryrouter.GetAccessTokenResponse{ + Id: "atid", + ExpirationTime: telemetryrouter.NullableTime{}, + Status: settings.resourceState, + }, nil + }), + } +} + +func TestCreateTelemetryRouterWaitHandler(t *testing.T) { + tests := []struct { + desc string + getFails bool + resourceState string + wantErr bool + wantResp bool + }{ + { + desc: "create_succeeded", + getFails: false, + resourceState: TELEMETRYROUTER_ACTIVE, + wantErr: false, + wantResp: true, + }, + { + desc: "create_failed", + getFails: false, + resourceState: TELEMETRYROUTER_FAILED, + wantErr: true, + wantResp: true, + }, + { + desc: "get_fails", + getFails: true, + resourceState: "", + wantErr: true, + wantResp: false, + }, + { + desc: "timeout", + getFails: false, + resourceState: "ANOTHER STATE", + wantErr: true, + wantResp: false, + }, + } + for _, tt := range tests { + t.Run(tt.desc, func(t *testing.T) { + synctest.Test(t, func(t *testing.T) { + apiClient := newAPIMock(mockSettings{ + getFails: tt.getFails, + resourceState: tt.resourceState, + }) + + var wantRes *telemetryrouter.TelemetryRouterResponse + if tt.wantResp { + wantRes = &telemetryrouter.TelemetryRouterResponse{ + Status: tt.resourceState, + Id: "trid", + } + } + + handler := CreateTelemetryRouterWaitHandler(context.Background(), apiClient, "pid", "eu01", "trid") + + gotRes, err := handler.SetTimeout(10 * time.Millisecond).WaitWithContext(context.Background()) + + if (err != nil) != tt.wantErr { + t.Fatalf("handler error = %v, wantErr %v", err, tt.wantErr) + } + if !cmp.Equal(gotRes, wantRes) { + t.Fatalf("handler gotRes = %v, want %v", gotRes, wantRes) + } + }) + }) + } +} + +func TestUpdateTelemetryRouterWaitHandler(t *testing.T) { + tests := []struct { + desc string + getFails bool + resourceState string + wantErr bool + wantResp bool + }{ + { + desc: "update_succeeded", + getFails: false, + resourceState: TELEMETRYROUTER_ACTIVE, + wantErr: false, + wantResp: true, + }, + { + desc: "update_failed", + getFails: false, + resourceState: TELEMETRYROUTER_FAILED, + wantErr: true, + wantResp: true, + }, + { + desc: "get_fails", + getFails: true, + resourceState: "", + wantErr: true, + wantResp: false, + }, + { + desc: "timeout", + getFails: false, + resourceState: "ANOTHER STATE", + wantErr: true, + wantResp: false, + }, + } + for _, tt := range tests { + t.Run(tt.desc, func(t *testing.T) { + synctest.Test(t, func(t *testing.T) { + apiClient := newAPIMock(mockSettings{ + getFails: tt.getFails, + resourceState: tt.resourceState, + }) + + var wantRes *telemetryrouter.TelemetryRouterResponse + if tt.wantResp { + wantRes = &telemetryrouter.TelemetryRouterResponse{ + Status: tt.resourceState, + Id: "trid", + } + } + + handler := UpdateTelemetryRouterWaitHandler(context.Background(), apiClient, "pid", "eu01", "trid") + + gotRes, err := handler.SetTimeout(10 * time.Millisecond).WaitWithContext(context.Background()) + + if (err != nil) != tt.wantErr { + t.Fatalf("handler error = %v, wantErr %v", err, tt.wantErr) + } + if !cmp.Equal(gotRes, wantRes) { + t.Fatalf("handler gotRes = %v, want %v", gotRes, wantRes) + } + }) + }) + } +} + +func TestDeleteTelemetryRouterWaitHandler(t *testing.T) { + tests := []struct { + desc string + getFails bool + resourceState string + wantErr bool + wantResp bool + }{ + { + desc: "delete_succeeded", + getFails: false, + resourceState: TELEMETRYROUTER_DELETED, + wantErr: false, + wantResp: true, + }, + { + desc: "delete_failed", + getFails: false, + resourceState: TELEMETRYROUTER_FAILED, + wantErr: true, + wantResp: true, + }, + { + desc: "get_fails", + getFails: true, + resourceState: "", + wantErr: true, + wantResp: false, + }, + { + desc: "timeout", + getFails: false, + resourceState: "ANOTHER STATE", + wantErr: true, + wantResp: false, + }, + } + for _, tt := range tests { + t.Run(tt.desc, func(t *testing.T) { + synctest.Test(t, func(t *testing.T) { + apiClient := newAPIMock(mockSettings{ + getFails: tt.getFails, + resourceState: string(tt.resourceState), + }) + + var wantRes *telemetryrouter.TelemetryRouterResponse + if tt.wantResp { + wantRes = &telemetryrouter.TelemetryRouterResponse{ + Status: tt.resourceState, + Id: "trid", + } + } else { + wantRes = nil + } + + handler := DeleteTelemetryRouterWaitHandler(context.Background(), apiClient, "pid", "zid", "trid") + + gotRes, err := handler.SetTimeout(10 * time.Millisecond).WaitWithContext(context.Background()) + + if (err != nil) != tt.wantErr { + t.Fatalf("handler error = %v, wantErr %v", err, tt.wantErr) + } + if wantRes == nil && gotRes != nil { + t.Fatalf("handler gotRes = %v, want %v", gotRes, wantRes) + } + if wantRes != nil && !cmp.Equal(gotRes, wantRes) { + t.Fatalf("handler gotRes = %v, want %v", gotRes, wantRes) + } + }) + }) + } +} + +func TestCreateDestinationWaitHandler(t *testing.T) { + tests := []struct { + desc string + getFails bool + resourceState string + wantErr bool + wantResp bool + }{ + { + desc: "create_succeeded", + getFails: false, + resourceState: DESTINATION_ACTIVE, + wantErr: false, + wantResp: true, + }, + { + desc: "create_failed", + getFails: false, + resourceState: DESTINATION_FAILED, + wantErr: true, + wantResp: true, + }, + { + desc: "get_fails", + getFails: true, + resourceState: "", + wantErr: true, + wantResp: false, + }, + { + desc: "timeout", + getFails: false, + resourceState: "ANOTHER STATE", + wantErr: true, + wantResp: false, + }, + } + for _, tt := range tests { + t.Run(tt.desc, func(t *testing.T) { + synctest.Test(t, func(t *testing.T) { + apiClient := newAPIMock(mockSettings{ + getFails: tt.getFails, + resourceState: tt.resourceState, + }) + + var wantRes *telemetryrouter.DestinationResponse + if tt.wantResp { + wantRes = &telemetryrouter.DestinationResponse{ + Status: tt.resourceState, + Id: "did", + } + } + + handler := CreateDestinationWaitHandler(context.Background(), apiClient, "pid", "eu01", "trid", "did") + + gotRes, err := handler.SetTimeout(10 * time.Millisecond).WaitWithContext(context.Background()) + + if (err != nil) != tt.wantErr { + t.Fatalf("handler error = %v, wantErr %v", err, tt.wantErr) + } + if !cmp.Equal(gotRes, wantRes) { + t.Fatalf("handler gotRes = %v, want %v", gotRes, wantRes) + } + }) + }) + } +} + +func TestUpdateDestinationWaitHandler(t *testing.T) { + tests := []struct { + desc string + getFails bool + resourceState string + wantErr bool + wantResp bool + }{ + { + desc: "update_succeeded", + getFails: false, + resourceState: DESTINATION_ACTIVE, + wantErr: false, + wantResp: true, + }, + { + desc: "update_failed", + getFails: false, + resourceState: DESTINATION_FAILED, + wantErr: true, + wantResp: true, + }, + { + desc: "get_fails", + getFails: true, + resourceState: "", + wantErr: true, + wantResp: false, + }, + { + desc: "timeout", + getFails: false, + resourceState: "ANOTHER STATE", + wantErr: true, + wantResp: false, + }, + } + for _, tt := range tests { + t.Run(tt.desc, func(t *testing.T) { + synctest.Test(t, func(t *testing.T) { + apiClient := newAPIMock(mockSettings{ + getFails: tt.getFails, + resourceState: tt.resourceState, + }) + + var wantRes *telemetryrouter.DestinationResponse + if tt.wantResp { + wantRes = &telemetryrouter.DestinationResponse{ + Status: tt.resourceState, + Id: "did", + } + } + + handler := UpdateDestinationWaitHandler(context.Background(), apiClient, "pid", "eu01", "trid", "did") + + gotRes, err := handler.SetTimeout(10 * time.Millisecond).WaitWithContext(context.Background()) + + if (err != nil) != tt.wantErr { + t.Fatalf("handler error = %v, wantErr %v", err, tt.wantErr) + } + if !cmp.Equal(gotRes, wantRes) { + t.Fatalf("handler gotRes = %v, want %v", gotRes, wantRes) + } + }) + }) + } +} + +func TestDeleteDestinationWaitHandler(t *testing.T) { + tests := []struct { + desc string + getFails bool + resourceState string + wantErr bool + wantResp bool + }{ + { + desc: "delete_succeeded", + getFails: false, + resourceState: DESTINATION_DELETED, + wantErr: false, + wantResp: true, + }, + { + desc: "delete_failed", + getFails: false, + resourceState: DESTINATION_FAILED, + wantErr: true, + wantResp: true, + }, + { + desc: "get_fails", + getFails: true, + resourceState: "", + wantErr: true, + wantResp: false, + }, + { + desc: "timeout", + getFails: false, + resourceState: "ANOTHER STATE", + wantErr: true, + wantResp: false, + }, + } + for _, tt := range tests { + t.Run(tt.desc, func(t *testing.T) { + synctest.Test(t, func(t *testing.T) { + apiClient := newAPIMock(mockSettings{ + getFails: tt.getFails, + resourceState: string(tt.resourceState), + }) + + var wantRes *telemetryrouter.DestinationResponse + if tt.wantResp { + wantRes = &telemetryrouter.DestinationResponse{ + Status: tt.resourceState, + Id: "did", + } + } else { + wantRes = nil + } + + handler := DeleteDestinationWaitHandler(context.Background(), apiClient, "pid", "zid", "trid", "did") + + gotRes, err := handler.SetTimeout(10 * time.Millisecond).WaitWithContext(context.Background()) + + if (err != nil) != tt.wantErr { + t.Fatalf("handler error = %v, wantErr %v", err, tt.wantErr) + } + if wantRes == nil && gotRes != nil { + t.Fatalf("handler gotRes = %v, want %v", gotRes, wantRes) + } + if wantRes != nil && !cmp.Equal(gotRes, wantRes) { + t.Fatalf("handler gotRes = %v, want %v", gotRes, wantRes) + } + }) + }) + } +} + +func TestCreateAccessTokenWaitHandler(t *testing.T) { + tests := []struct { + desc string + getFails bool + resourceState string + wantErr bool + wantResp bool + }{ + { + desc: "create_succeeded", + getFails: false, + resourceState: ACCESSTOKEN_ACTIVE, + wantErr: false, + wantResp: true, + }, + { + desc: "create_failed", + getFails: false, + resourceState: ACCESSTOKEN_FAILED, + wantErr: true, + wantResp: true, + }, + { + desc: "get_fails", + getFails: true, + resourceState: "", + wantErr: true, + wantResp: false, + }, + { + desc: "timeout", + getFails: false, + resourceState: "ANOTHER STATE", + wantErr: true, + wantResp: false, + }, + } + for _, tt := range tests { + t.Run(tt.desc, func(t *testing.T) { + synctest.Test(t, func(t *testing.T) { + apiClient := newAPIMock(mockSettings{ + getFails: tt.getFails, + resourceState: tt.resourceState, + }) + + var wantRes *telemetryrouter.GetAccessTokenResponse + if tt.wantResp { + wantRes = &telemetryrouter.GetAccessTokenResponse{ + Status: tt.resourceState, + Id: "atid", + } + } + + handler := CreateAccessTokenWaitHandler(context.Background(), apiClient, "pid", "eu01", "trid", "atid") + + gotRes, err := handler.SetTimeout(10 * time.Millisecond).WaitWithContext(context.Background()) + + if (err != nil) != tt.wantErr { + t.Fatalf("handler error = %v, wantErr %v", err, tt.wantErr) + } + if !cmp.Equal(gotRes, wantRes, cmp.Comparer(compareNullableTime)) { + t.Fatalf("handler gotRes = %v, want %v", gotRes, wantRes) + } + }) + }) + } +} + +func TestUpdateAccessTokenWaitHandler(t *testing.T) { + tests := []struct { + desc string + getFails bool + resourceState string + wantErr bool + wantResp bool + }{ + { + desc: "update_succeeded", + getFails: false, + resourceState: ACCESSTOKEN_ACTIVE, + wantErr: false, + wantResp: true, + }, + { + desc: "update_failed", + getFails: false, + resourceState: ACCESSTOKEN_FAILED, + wantErr: true, + wantResp: true, + }, + { + desc: "get_fails", + getFails: true, + resourceState: "", + wantErr: true, + wantResp: false, + }, + { + desc: "timeout", + getFails: false, + resourceState: "ANOTHER STATE", + wantErr: true, + wantResp: false, + }, + } + for _, tt := range tests { + t.Run(tt.desc, func(t *testing.T) { + synctest.Test(t, func(t *testing.T) { + apiClient := newAPIMock(mockSettings{ + getFails: tt.getFails, + resourceState: tt.resourceState, + }) + + var wantRes *telemetryrouter.GetAccessTokenResponse + if tt.wantResp { + wantRes = &telemetryrouter.GetAccessTokenResponse{ + Status: tt.resourceState, + Id: "atid", + } + } + + handler := UpdateAccessTokenWaitHandler(context.Background(), apiClient, "pid", "eu01", "trid", "atid") + + gotRes, err := handler.SetTimeout(10 * time.Millisecond).WaitWithContext(context.Background()) + + if (err != nil) != tt.wantErr { + t.Fatalf("handler error = %v, wantErr %v", err, tt.wantErr) + } + if !cmp.Equal(gotRes, wantRes, cmp.Comparer(compareNullableTime)) { + t.Fatalf("handler gotRes = %v, want %v", gotRes, wantRes) + } + }) + }) + } +} + +func TestDeleteAccessTokenWaitHandler(t *testing.T) { + tests := []struct { + desc string + getFails bool + resourceState string + wantErr bool + wantResp bool + }{ + { + desc: "delete_succeeded", + getFails: false, + resourceState: ACCESSTOKEN_DELETED, + wantErr: false, + wantResp: true, + }, + { + desc: "delete_failed", + getFails: false, + resourceState: ACCESSTOKEN_FAILED, + wantErr: true, + wantResp: true, + }, + { + desc: "get_fails", + getFails: true, + resourceState: "", + wantErr: true, + wantResp: false, + }, + { + desc: "timeout", + getFails: false, + resourceState: "ANOTHER STATE", + wantErr: true, + wantResp: false, + }, + } + for _, tt := range tests { + t.Run(tt.desc, func(t *testing.T) { + synctest.Test(t, func(t *testing.T) { + apiClient := newAPIMock(mockSettings{ + getFails: tt.getFails, + resourceState: tt.resourceState, + }) + + var wantRes *telemetryrouter.GetAccessTokenResponse + if tt.wantResp { + wantRes = &telemetryrouter.GetAccessTokenResponse{ + Status: tt.resourceState, + Id: "atid", + } + } else { + wantRes = nil + } + + handler := DeleteAccessTokenWaitHandler(context.Background(), apiClient, "pid", "zid", "trid", "atid") + + gotRes, err := handler.SetTimeout(10 * time.Millisecond).WaitWithContext(context.Background()) + + if (err != nil) != tt.wantErr { + t.Fatalf("handler error = %v, wantErr %v", err, tt.wantErr) + } + if wantRes == nil && gotRes != nil { + t.Fatalf("handler gotRes = %v, want %v", gotRes, wantRes) + } + if wantRes != nil && !cmp.Equal(gotRes, wantRes, cmp.Comparer(compareNullableTime)) { + t.Fatalf("handler gotRes = %v, want %v", gotRes, wantRes) + } + }) + }) + } +} + +func compareNullableTime(x, y telemetryrouter.NullableTime) bool { + if x.IsSet() != y.IsSet() { + return false + } + + if !x.IsSet() && !y.IsSet() { + return true + } + + valX := x.Get() + valY := y.Get() + + if valX == nil || valY == nil { + return valX == valY + } + + return *valX == *valY +} From 2db9ca179945cade1b1ad40590f7a578d82a59b4 Mon Sep 17 00:00:00 2001 From: Oleksandr Zanichkovskyi Date: Tue, 28 Apr 2026 21:33:49 +0200 Subject: [PATCH 02/11] chore: updated changelog and version --- CHANGELOG.md | 2 ++ services/telemetryrouter/CHANGELOG.md | 3 +++ services/telemetryrouter/VERSION | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index decaedcba..ea212af5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -391,6 +391,8 @@ - **New**: API for STACKIT Telemetry Router - [v0.1.1](services/telemetryrouter/CHANGELOG.md#v011) - **Dependencies:** Bump STACKIT SDK core module from `v0.25.0` to `v0.26.0` + - [v0.1.2](services/telemetryrouter/CHANGELOG.md#v012) + - **Improvement**: Use new `WaiterHandler` struct in the DNS WaitHandler - `vpn`: - [v0.4.2](services/vpn/CHANGELOG.md#v042) - **Dependencies:** Bump STACKIT SDK core module from `v0.24.0` to `v0.24.1` diff --git a/services/telemetryrouter/CHANGELOG.md b/services/telemetryrouter/CHANGELOG.md index 72fb92c20..b45b557eb 100644 --- a/services/telemetryrouter/CHANGELOG.md +++ b/services/telemetryrouter/CHANGELOG.md @@ -1,3 +1,6 @@ +## v0.1.2 +- **Improvement**: Use new `WaiterHandler` struct in the DNS WaitHandler + ## v0.1.1 - **Dependencies:** Bump STACKIT SDK core module from `v0.25.0` to `v0.26.0` diff --git a/services/telemetryrouter/VERSION b/services/telemetryrouter/VERSION index a1c2c6a9f..f4cacccee 100644 --- a/services/telemetryrouter/VERSION +++ b/services/telemetryrouter/VERSION @@ -1 +1 @@ -v0.1.1 \ No newline at end of file +v0.1.2 \ No newline at end of file From a23483e39f9600b4e02ef35425a3dbd0b7447884 Mon Sep 17 00:00:00 2001 From: Oleksandr Zanichkovskyi Date: Tue, 28 Apr 2026 21:34:36 +0200 Subject: [PATCH 03/11] chore: update telemetryrouter examples version --- examples/telemetryrouter/go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/telemetryrouter/go.mod b/examples/telemetryrouter/go.mod index 8b5f0ac9a..15b3d2c81 100644 --- a/examples/telemetryrouter/go.mod +++ b/examples/telemetryrouter/go.mod @@ -7,7 +7,7 @@ replace github.com/stackitcloud/stackit-sdk-go/services/telemetryrouter => ../.. require ( github.com/stackitcloud/stackit-sdk-go/core v0.26.0 - github.com/stackitcloud/stackit-sdk-go/services/telemetryrouter v0.1.0 + github.com/stackitcloud/stackit-sdk-go/services/telemetryrouter v0.1.2 ) require ( From 3e124c98bd32e0e595c0b0843b6a40f400d80df5 Mon Sep 17 00:00:00 2001 From: Oleksandr Zanichkovskyi Date: Wed, 29 Apr 2026 12:09:04 +0200 Subject: [PATCH 04/11] chore: changes according to review comments --- examples/telemetryrouter/telemetryrouter.go | 127 ++++++++++++++++++ .../telemetryrouter/v1betaapi/wait/wait.go | 26 +--- .../v1betaapi/wait/wait_test.go | 84 ------------ 3 files changed, 130 insertions(+), 107 deletions(-) diff --git a/examples/telemetryrouter/telemetryrouter.go b/examples/telemetryrouter/telemetryrouter.go index 56f2a156f..3c2116f0b 100644 --- a/examples/telemetryrouter/telemetryrouter.go +++ b/examples/telemetryrouter/telemetryrouter.go @@ -6,6 +6,7 @@ import ( "github.com/stackitcloud/stackit-sdk-go/core/utils" telemetryrouter "github.com/stackitcloud/stackit-sdk-go/services/telemetryrouter/v1betaapi" + "github.com/stackitcloud/stackit-sdk-go/services/telemetryrouter/v1betaapi/wait" ) func main() { @@ -33,6 +34,13 @@ func main() { log.Printf("[TelemetryRouter API] Created TelemetryRouter Instance with ID \"%s\".\n", createResp.Id) createdInstance = createResp.Id + // Wait for the Telemetry Router Instance to be ready + _, err = wait.CreateTelemetryRouterWaitHandler(ctx, client.DefaultAPI, projectId, regionId, createdInstance).WaitWithContext(context.Background()) + if err != nil { + log.Fatalf("[TelemetryRouter API] Error when waiting for creation: %v\n", err) + } + log.Printf("[TelemetryRouter API] TelemetryRouter Instance %q has been successfully created.\n", createdInstance) + // List Telemetry Router Instances listResp, err := client.DefaultAPI.ListTelemetryRouters(ctx, projectId, regionId).Execute() if err != nil { @@ -69,6 +77,13 @@ func main() { } log.Printf("[Telemetry Router API] Updated Telemetry Router Instance with ID \"%s\" to Display Name \"%s\".\n", updateResp.Id, updateResp.DisplayName) + // Wait for the Telemetry Router Instance to be updated + _, err = wait.UpdateTelemetryRouterWaitHandler(ctx, client.DefaultAPI, projectId, regionId, createdInstance).WaitWithContext(context.Background()) + if err != nil { + log.Fatalf("[Telemetry Router API] Error when waiting for update: %v\n", err) + } + log.Printf("[Telemetry Router API] TelemetryRouter Instance %q has been successfully updated.\n", createdInstance) + // Create an Access Token createTokenPayload := telemetryrouter.CreateAccessTokenPayload{ DisplayName: "my-access-token", @@ -81,6 +96,27 @@ func main() { } log.Printf("[Telemetry Router API] Created Access Token with ID \"%s\".\n", createTokenResp.Id) + // Wait for the Access Token to be created + _, err = wait.CreateAccessTokenWaitHandler(ctx, client.DefaultAPI, projectId, regionId, createdInstance, createTokenResp.Id).WaitWithContext(context.Background()) + if err != nil { + log.Fatalf("[Telemetry Router API] Error when waiting for creation: %v\n", err) + } + log.Printf("[Telemetry Router API] Access Token %q has been successfully created.\n", createTokenResp.Id) + + // Get the created Access Token + getTokenResp, err := client.DefaultAPI.GetAccessToken(ctx, projectId, regionId, createdInstance, createTokenResp.Id).Execute() + if err != nil { + log.Fatalf("[Telemetry Router API] Error when calling `GetAccessToken`: %v\n", err) + } + log.Printf("[Telemetry Router API] Retrieved Access Token with ID \"%s\" and Display Name \"%s\".\n", getTokenResp.Id, getTokenResp.DisplayName) + + // List Access Tokens + listTokenResp, err := client.DefaultAPI.ListAccessTokens(ctx, projectId, regionId, createdInstance).Execute() + if err != nil { + log.Fatalf("[Telemetry Router API] Error when calling `ListAccessTokens`: %v\n", err) + } + log.Printf("[Telemetry Router API] Retrieved %d Access Tokens.\n", len(listTokenResp.AccessTokens)) + newDisplayName := "my-updated-acc-token" newDisplayNameNS := telemetryrouter.NullableString{} newDisplayNameNS.Set(&newDisplayName) @@ -96,6 +132,13 @@ func main() { } log.Printf("[Telemetry Router API] Updated Access Token with ID \"%s\" to Display Name \"%s\".\n.\n", updateTokenResp.Id, updateTokenResp.DisplayName) + // Wait for the Access Token to be updated + _, err = wait.UpdateAccessTokenWaitHandler(ctx, client.DefaultAPI, projectId, regionId, createdInstance, updateTokenResp.Id).WaitWithContext(context.Background()) + if err != nil { + log.Fatalf("[Telemetry Router API] Error when waiting for update: %v\n", err) + } + log.Printf("[Telemetry Router API] Access Token %q has been successfully updated.\n", updateTokenResp.Id) + // Delete Access Token err = client.DefaultAPI.DeleteAccessToken(ctx, projectId, regionId, createdInstance, updateTokenResp.Id).Execute() if err != nil { @@ -103,6 +146,13 @@ func main() { } log.Printf("[Telemetry Router API] Deleted Access Tokens.\n") + // Wait for the Access Token to be deleted + _, err = wait.DeleteAccessTokenWaitHandler(ctx, client.DefaultAPI, projectId, regionId, createdInstance, updateTokenResp.Id).WaitWithContext(context.Background()) + if err != nil { + log.Fatalf("[Telemetry Router API] Error when waiting for deletion: %v\n", err) + } + log.Printf("[Telemetry Router API] Access Token %q has been successfully deleted.\n", updateTokenResp.Id) + // Create S3 Destination createS3DestinationPayload := telemetryrouter.CreateDestinationPayload{ DisplayName: "s3-destination", @@ -125,6 +175,27 @@ func main() { } log.Printf("[Telemetry Router API] Created Destination with ID \"%s\".\n", createS3DestinationResp.Id) + // Wait for the S3 Destination to be created + _, err = wait.CreateDestinationWaitHandler(ctx, client.DefaultAPI, projectId, regionId, createdInstance, createS3DestinationResp.Id).WaitWithContext(context.Background()) + if err != nil { + log.Fatalf("[Telemetry Router API] Error when waiting for creation: %v\n", err) + } + log.Printf("[Telemetry Router API] Destination %q has been successfully created.\n", createS3DestinationResp.Id) + + // Get the created S3 Destination + getS3DestinationResp, err := client.DefaultAPI.GetDestination(ctx, projectId, regionId, createdInstance, createS3DestinationResp.Id).Execute() + if err != nil { + log.Fatalf("[Telemetry Router API] Error when calling `GetDestination`: %v\n", err) + } + log.Printf("[Telemetry Router API] Retrieved Destination with ID \"%s\" and Display Name \"%s\".\n", getS3DestinationResp.Id, getS3DestinationResp.DisplayName) + + // List Destinations + listDestinationResp, err := client.DefaultAPI.ListDestinations(ctx, projectId, regionId, createdInstance).Execute() + if err != nil { + log.Fatalf("[Telemetry Router API] Error when calling `ListDestinations`: %v\n", err) + } + log.Printf("[Telemetry Router API] Retrieved %d Destinations.\n", len(listDestinationResp.Destinations)) + // Update S3 Destination newS3DestinationDisplayName := "updated-s3-destination" updateS3DestinationPayload := telemetryrouter.UpdateDestinationPayload{ @@ -158,6 +229,13 @@ func main() { } log.Printf("[Telemetry Router API] Updated Destination with ID \"%s\".\n", updateS3DestinationResp.Id) + // Wait for the S3 Destination to be updated + _, err = wait.UpdateDestinationWaitHandler(ctx, client.DefaultAPI, projectId, regionId, createdInstance, updateS3DestinationResp.Id).WaitWithContext(context.Background()) + if err != nil { + log.Fatalf("[Telemetry Router API] Error when waiting for update: %v\n", err) + } + log.Printf("[Telemetry Router API] Destination %q has been successfully updated.\n", updateS3DestinationResp.Id) + // Delete S3 Destination err = client.DefaultAPI.DeleteDestination(ctx, projectId, regionId, createdInstance, updateS3DestinationResp.Id).Execute() if err != nil { @@ -165,6 +243,13 @@ func main() { } log.Printf("[Telemetry Router API] Deleted Destination with ID \"%s\".\n", updateS3DestinationResp.Id) + // Wait for the S3 Destination to be deleted + _, err = wait.DeleteDestinationWaitHandler(ctx, client.DefaultAPI, projectId, regionId, createdInstance, updateS3DestinationResp.Id).WaitWithContext(context.Background()) + if err != nil { + log.Fatalf("[Telemetry Router API] Error when waiting for deletion: %v\n", err) + } + log.Printf("[Telemetry Router API] Destination %q has been successfully deleted.\n", updateS3DestinationResp.Id) + // Create OpenTelemetry Destination createOpenTelemetryDestinationPayload := telemetryrouter.CreateDestinationPayload{ DisplayName: "otlp-destination", @@ -186,6 +271,27 @@ func main() { } log.Printf("[Telemetry Router API] Created Destination with ID \"%s\".\n", createOpenTelemetryDestinationResp.Id) + // Wait for the OpenTelemetry Destination to be created + _, err = wait.CreateDestinationWaitHandler(ctx, client.DefaultAPI, projectId, regionId, createdInstance, createOpenTelemetryDestinationResp.Id).WaitWithContext(context.Background()) + if err != nil { + log.Fatalf("[Telemetry Router API] Error when waiting for creation: %v\n", err) + } + log.Printf("[Telemetry Router API] Destination %q has been successfully created.\n", createOpenTelemetryDestinationResp.Id) + + // Get the created OpenTelemetry Destination + getOpenTelemetryDestinationResp, err := client.DefaultAPI.GetDestination(ctx, projectId, regionId, createdInstance, createOpenTelemetryDestinationResp.Id).Execute() + if err != nil { + log.Fatalf("[Telemetry Router API] Error when calling `GetDestination`: %v\n", err) + } + log.Printf("[Telemetry Router API] Received Destination with ID \"%s\".\n", getOpenTelemetryDestinationResp.Id) + + // List Destinations + listDestinationsResp, err := client.DefaultAPI.ListDestinations(ctx, projectId, regionId, createdInstance).Execute() + if err != nil { + log.Fatalf("[Telemetry Router API] Error when calling `ListDestinations`: %v\n", err) + } + log.Printf("[Telemetry Router API] Received %d Destinations.\n", len(listDestinationsResp.Destinations)) + // Update S3 Destination newOTLPDestinationDisplayName := "updated-otlp-destination" updateOTLPDestinationPayload := telemetryrouter.UpdateDestinationPayload{ @@ -218,6 +324,13 @@ func main() { } log.Printf("[Telemetry Router API] Updated Destination with ID \"%s\".\n", updateOTLPDestinationResp.Id) + // Wait for the OpenTelemetry Destination to be updated + _, err = wait.UpdateDestinationWaitHandler(ctx, client.DefaultAPI, projectId, regionId, createdInstance, updateOTLPDestinationResp.Id).WaitWithContext(context.Background()) + if err != nil { + log.Fatalf("[Telemetry Router API] Error when waiting for update: %v\n", err) + } + log.Printf("[Telemetry Router API] Destination %q has been successfully updated.\n", updateOTLPDestinationResp.Id) + // Delete OpenTelemetry Destination err = client.DefaultAPI.DeleteDestination(ctx, projectId, regionId, createdInstance, updateOTLPDestinationResp.Id).Execute() if err != nil { @@ -225,10 +338,24 @@ func main() { } log.Printf("[Telemetry Router API] Deleted Destination with ID \"%s\".\n", updateOTLPDestinationResp.Id) + // Wait for the OpenTelemetry Destination to be deleted + _, err = wait.DeleteDestinationWaitHandler(ctx, client.DefaultAPI, projectId, regionId, createdInstance, updateOTLPDestinationResp.Id).WaitWithContext(context.Background()) + if err != nil { + log.Fatalf("[Telemetry Router API] Error when waiting for deletion: %v\n", err) + } + log.Printf("[Telemetry Router API] Destination %q has been successfully deleted.\n", updateOTLPDestinationResp.Id) + // Delete the created TelemetryRouter Instance err = client.DefaultAPI.DeleteTelemetryRouter(ctx, projectId, regionId, createdInstance).Execute() if err != nil { log.Fatalf("[Telemetry Router API] Error when calling `DeleteTelemetryRouter`: %v\n", err) } log.Printf("[Telemetry Router API] Deleted Telemetry Router Instance with ID \"%s\".\n", createdInstance) + + // Wait for the TelemetryRouter Instance to be deleted + _, err = wait.DeleteTelemetryRouterWaitHandler(ctx, client.DefaultAPI, projectId, regionId, createdInstance).WaitWithContext(context.Background()) + if err != nil { + log.Fatalf("[Telemetry Router API] Error when waiting for deletion: %v\n", err) + } + log.Printf("[Telemetry Router API] Telemetry Router Instance %q has been successfully deleted.\n", createdInstance) } diff --git a/services/telemetryrouter/v1betaapi/wait/wait.go b/services/telemetryrouter/v1betaapi/wait/wait.go index a8a0ab703..9eb5861f6 100644 --- a/services/telemetryrouter/v1betaapi/wait/wait.go +++ b/services/telemetryrouter/v1betaapi/wait/wait.go @@ -11,17 +11,9 @@ import ( ) const ( - TELEMETRYROUTER_ACTIVE = "active" - TELEMETRYROUTER_DELETED = "deleted" - TELEMETRYROUTER_FAILED = "failed" - - DESTINATION_ACTIVE = "active" - DESTINATION_DELETED = "deleted" - DESTINATION_FAILED = "failed" - - ACCESSTOKEN_ACTIVE = "active" - ACCESSTOKEN_DELETED = "deleted" - ACCESSTOKEN_FAILED = "failed" + TELEMETRYROUTER_ACTIVE = "active" + DESTINATION_ACTIVE = "active" + ACCESSTOKEN_ACTIVE = "active" ) // CreateTelemetryRouterWaitHandler will wait for TelemetryRouter creation @@ -35,7 +27,6 @@ func CreateTelemetryRouterWaitHandler(ctx context.Context, a telemetryrouter.Def return d.Status, nil }, ActiveState: []string{TELEMETRYROUTER_ACTIVE}, - ErrorState: []string{TELEMETRYROUTER_FAILED}, } handler := wait.New(waitConfig.Wait()) @@ -54,7 +45,6 @@ func UpdateTelemetryRouterWaitHandler(ctx context.Context, a telemetryrouter.Def return d.Status, nil }, ActiveState: []string{TELEMETRYROUTER_ACTIVE}, - ErrorState: []string{TELEMETRYROUTER_FAILED}, } handler := wait.New(waitConfig.Wait()) @@ -72,8 +62,6 @@ func DeleteTelemetryRouterWaitHandler(ctx context.Context, a telemetryrouter.Def } return d.Status, nil }, - ActiveState: []string{TELEMETRYROUTER_DELETED}, - ErrorState: []string{TELEMETRYROUTER_FAILED}, DeleteHttpErrorStatusCodes: []int{http.StatusNotFound}, } @@ -93,7 +81,6 @@ func CreateDestinationWaitHandler(ctx context.Context, a telemetryrouter.Default return d.Status, nil }, ActiveState: []string{DESTINATION_ACTIVE}, - ErrorState: []string{DESTINATION_FAILED}, } handler := wait.New(waitConfig.Wait()) @@ -112,7 +99,6 @@ func UpdateDestinationWaitHandler(ctx context.Context, a telemetryrouter.Default return d.Status, nil }, ActiveState: []string{DESTINATION_ACTIVE}, - ErrorState: []string{DESTINATION_FAILED}, } handler := wait.New(waitConfig.Wait()) @@ -130,8 +116,6 @@ func DeleteDestinationWaitHandler(ctx context.Context, a telemetryrouter.Default } return d.Status, nil }, - ActiveState: []string{DESTINATION_DELETED}, - ErrorState: []string{DESTINATION_FAILED}, DeleteHttpErrorStatusCodes: []int{http.StatusNotFound}, } @@ -151,7 +135,6 @@ func CreateAccessTokenWaitHandler(ctx context.Context, a telemetryrouter.Default return d.Status, nil }, ActiveState: []string{ACCESSTOKEN_ACTIVE}, - ErrorState: []string{ACCESSTOKEN_FAILED}, } handler := wait.New(waitConfig.Wait()) @@ -170,7 +153,6 @@ func UpdateAccessTokenWaitHandler(ctx context.Context, a telemetryrouter.Default return d.Status, nil }, ActiveState: []string{ACCESSTOKEN_ACTIVE}, - ErrorState: []string{ACCESSTOKEN_FAILED}, } handler := wait.New(waitConfig.Wait()) @@ -188,8 +170,6 @@ func DeleteAccessTokenWaitHandler(ctx context.Context, a telemetryrouter.Default } return d.Status, nil }, - ActiveState: []string{ACCESSTOKEN_DELETED}, - ErrorState: []string{ACCESSTOKEN_FAILED}, DeleteHttpErrorStatusCodes: []int{http.StatusNotFound}, } diff --git a/services/telemetryrouter/v1betaapi/wait/wait_test.go b/services/telemetryrouter/v1betaapi/wait/wait_test.go index 87c0cb898..02e1d578f 100644 --- a/services/telemetryrouter/v1betaapi/wait/wait_test.go +++ b/services/telemetryrouter/v1betaapi/wait/wait_test.go @@ -75,13 +75,6 @@ func TestCreateTelemetryRouterWaitHandler(t *testing.T) { wantErr: false, wantResp: true, }, - { - desc: "create_failed", - getFails: false, - resourceState: TELEMETRYROUTER_FAILED, - wantErr: true, - wantResp: true, - }, { desc: "get_fails", getFails: true, @@ -143,13 +136,6 @@ func TestUpdateTelemetryRouterWaitHandler(t *testing.T) { wantErr: false, wantResp: true, }, - { - desc: "update_failed", - getFails: false, - resourceState: TELEMETRYROUTER_FAILED, - wantErr: true, - wantResp: true, - }, { desc: "get_fails", getFails: true, @@ -204,20 +190,6 @@ func TestDeleteTelemetryRouterWaitHandler(t *testing.T) { wantErr bool wantResp bool }{ - { - desc: "delete_succeeded", - getFails: false, - resourceState: TELEMETRYROUTER_DELETED, - wantErr: false, - wantResp: true, - }, - { - desc: "delete_failed", - getFails: false, - resourceState: TELEMETRYROUTER_FAILED, - wantErr: true, - wantResp: true, - }, { desc: "get_fails", getFails: true, @@ -284,13 +256,6 @@ func TestCreateDestinationWaitHandler(t *testing.T) { wantErr: false, wantResp: true, }, - { - desc: "create_failed", - getFails: false, - resourceState: DESTINATION_FAILED, - wantErr: true, - wantResp: true, - }, { desc: "get_fails", getFails: true, @@ -352,13 +317,6 @@ func TestUpdateDestinationWaitHandler(t *testing.T) { wantErr: false, wantResp: true, }, - { - desc: "update_failed", - getFails: false, - resourceState: DESTINATION_FAILED, - wantErr: true, - wantResp: true, - }, { desc: "get_fails", getFails: true, @@ -413,20 +371,6 @@ func TestDeleteDestinationWaitHandler(t *testing.T) { wantErr bool wantResp bool }{ - { - desc: "delete_succeeded", - getFails: false, - resourceState: DESTINATION_DELETED, - wantErr: false, - wantResp: true, - }, - { - desc: "delete_failed", - getFails: false, - resourceState: DESTINATION_FAILED, - wantErr: true, - wantResp: true, - }, { desc: "get_fails", getFails: true, @@ -493,13 +437,6 @@ func TestCreateAccessTokenWaitHandler(t *testing.T) { wantErr: false, wantResp: true, }, - { - desc: "create_failed", - getFails: false, - resourceState: ACCESSTOKEN_FAILED, - wantErr: true, - wantResp: true, - }, { desc: "get_fails", getFails: true, @@ -561,13 +498,6 @@ func TestUpdateAccessTokenWaitHandler(t *testing.T) { wantErr: false, wantResp: true, }, - { - desc: "update_failed", - getFails: false, - resourceState: ACCESSTOKEN_FAILED, - wantErr: true, - wantResp: true, - }, { desc: "get_fails", getFails: true, @@ -622,20 +552,6 @@ func TestDeleteAccessTokenWaitHandler(t *testing.T) { wantErr bool wantResp bool }{ - { - desc: "delete_succeeded", - getFails: false, - resourceState: ACCESSTOKEN_DELETED, - wantErr: false, - wantResp: true, - }, - { - desc: "delete_failed", - getFails: false, - resourceState: ACCESSTOKEN_FAILED, - wantErr: true, - wantResp: true, - }, { desc: "get_fails", getFails: true, From c53a00f4cf24d1992dd2997739c7b3b12e58f1c0 Mon Sep 17 00:00:00 2001 From: Oleksandr Zanichkovskyi Date: Wed, 29 Apr 2026 16:36:32 +0200 Subject: [PATCH 05/11] chore: using utils.Ptr --- examples/telemetryrouter/telemetryrouter.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/examples/telemetryrouter/telemetryrouter.go b/examples/telemetryrouter/telemetryrouter.go index 3c2116f0b..41efd70b8 100644 --- a/examples/telemetryrouter/telemetryrouter.go +++ b/examples/telemetryrouter/telemetryrouter.go @@ -117,9 +117,8 @@ func main() { } log.Printf("[Telemetry Router API] Retrieved %d Access Tokens.\n", len(listTokenResp.AccessTokens)) - newDisplayName := "my-updated-acc-token" newDisplayNameNS := telemetryrouter.NullableString{} - newDisplayNameNS.Set(&newDisplayName) + newDisplayNameNS.Set(utils.Ptr("my-updated-acc-token")) updateTokenPayload := telemetryrouter.UpdateAccessTokenPayload{ DisplayName: newDisplayNameNS, } @@ -197,9 +196,8 @@ func main() { log.Printf("[Telemetry Router API] Retrieved %d Destinations.\n", len(listDestinationResp.Destinations)) // Update S3 Destination - newS3DestinationDisplayName := "updated-s3-destination" updateS3DestinationPayload := telemetryrouter.UpdateDestinationPayload{ - DisplayName: &newS3DestinationDisplayName, + DisplayName: utils.Ptr("updated-s3-destination"), Config: &telemetryrouter.DestinationConfig{ ConfigType: "S3", S3: &telemetryrouter.DestinationConfigS3{ @@ -293,9 +291,8 @@ func main() { log.Printf("[Telemetry Router API] Received %d Destinations.\n", len(listDestinationsResp.Destinations)) // Update S3 Destination - newOTLPDestinationDisplayName := "updated-otlp-destination" updateOTLPDestinationPayload := telemetryrouter.UpdateDestinationPayload{ - DisplayName: &newOTLPDestinationDisplayName, + DisplayName: utils.Ptr("updated-otlp-destination"), Config: &telemetryrouter.DestinationConfig{ ConfigType: "OpenTelemetry", OpenTelemetry: &telemetryrouter.DestinationConfigOpenTelemetry{ From 68e683b9413e65680c883fffc43143981fae5f0a Mon Sep 17 00:00:00 2001 From: Oleksandr Zanichkovskyi Date: Mon, 4 May 2026 15:15:51 +0200 Subject: [PATCH 06/11] chore: updated telemetryrouter endpoints to be resolvable --- examples/telemetryrouter/telemetryrouter.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/telemetryrouter/telemetryrouter.go b/examples/telemetryrouter/telemetryrouter.go index 41efd70b8..53d97e9bd 100644 --- a/examples/telemetryrouter/telemetryrouter.go +++ b/examples/telemetryrouter/telemetryrouter.go @@ -163,7 +163,7 @@ func main() { Secret: "secret", }, Bucket: "bucket", - Endpoint: "https://bucket.endpoint.com", + Endpoint: "https://portal.stackit.cloud/", }, }, } @@ -206,7 +206,7 @@ func main() { Secret: "secret", }, Bucket: "bucket", - Endpoint: "https://bucket.endpoint.com", + Endpoint: "https://portal.stackit.cloud/", }, Filter: &telemetryrouter.ConfigFilter{ Attributes: []telemetryrouter.ConfigFilterAttributes{ @@ -258,7 +258,7 @@ func main() { Password: "password", Username: "user", }, - Uri: "https://otlp.endpoint.com/v1/logs", + Uri: "https://portal.stackit.cloud/v1/logs", }, }, } @@ -300,7 +300,7 @@ func main() { Username: "user1", Password: "pass", }, - Uri: "https://otlp.endpoint.com/v1/logs", + Uri: "https://portal.stackit.cloud/v1/logs", }, Filter: &telemetryrouter.ConfigFilter{ Attributes: []telemetryrouter.ConfigFilterAttributes{ From dcc9f955885283b8fc23a8707aac5a4efae7c106 Mon Sep 17 00:00:00 2001 From: Oleksandr Zanichkovskyi Date: Tue, 5 May 2026 13:09:07 +0200 Subject: [PATCH 07/11] chore: fixed failing update destination example --- examples/telemetryrouter/telemetryrouter.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/telemetryrouter/telemetryrouter.go b/examples/telemetryrouter/telemetryrouter.go index 53d97e9bd..c08af1128 100644 --- a/examples/telemetryrouter/telemetryrouter.go +++ b/examples/telemetryrouter/telemetryrouter.go @@ -314,7 +314,7 @@ func main() { }, }, } - updateOTLPDestinationResp, err := client.DefaultAPI.UpdateDestination(ctx, projectId, regionId, createdInstance, createS3DestinationResp.Id). + updateOTLPDestinationResp, err := client.DefaultAPI.UpdateDestination(ctx, projectId, regionId, createdInstance, createOpenTelemetryDestinationResp.Id). UpdateDestinationPayload(updateOTLPDestinationPayload).Execute() if err != nil { log.Fatalf("[Telemetry Router API] Error when calling `UpdateDestination`: %v\n", err) From 16d5bd2f74c6143afb1bd8f8462ebcb7fa0de8cd Mon Sep 17 00:00:00 2001 From: Oleksandr Zanichkovskyi Date: Tue, 5 May 2026 13:12:01 +0200 Subject: [PATCH 08/11] chore: Update CHANGELOG.md Co-authored-by: Alexander Dahmen --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a828d2bd..e09995699 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -424,7 +424,7 @@ - **Dependencies:** Bump STACKIT SDK core module from `v0.25.0` to `v0.26.0` - [v0.2.0](services/telemetryrouter/CHANGELOG.md#v020) - **Feature:** Added `_UNKNOWN_DEFAULT_OPEN_API` fallback value to all enums to handle unknown API values gracefully. - - [v0.2.1](services/telemetryrouter/CHANGELOG.md#v012) + - [v0.2.1](services/telemetryrouter/CHANGELOG.md#v021) - **Improvement**: Use new `WaiterHandler` struct in the DNS WaitHandler - `vpn`: - [v0.4.2](services/vpn/CHANGELOG.md#v042) From 2f94378ec5d93935c50eb019d60046dc31bf3b7a Mon Sep 17 00:00:00 2001 From: Oleksandr Zanichkovskyi Date: Tue, 5 May 2026 13:12:25 +0200 Subject: [PATCH 09/11] chore: Update examples/telemetryrouter/telemetryrouter.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Gökce Gök Klingel <161626272+GokceGK@users.noreply.github.com> --- examples/telemetryrouter/telemetryrouter.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/telemetryrouter/telemetryrouter.go b/examples/telemetryrouter/telemetryrouter.go index c08af1128..4ffde82e9 100644 --- a/examples/telemetryrouter/telemetryrouter.go +++ b/examples/telemetryrouter/telemetryrouter.go @@ -46,7 +46,7 @@ func main() { if err != nil { log.Fatalf("[Telemetry Router API] Error when calling `ListTelemetryRouters`: %v\n", err) } - log.Printf("[Telemetry Router API] Retrieved %d Logs Instances.\n", len(listResp.TelemetryRouters)) + log.Printf("[Telemetry Router API] Retrieved %d Telemetry Router Instances.\n", len(listResp.TelemetryRouters)) // Get the created Telemetry Router Instance getResp, err := client.DefaultAPI.GetTelemetryRouter(ctx, projectId, regionId, createdInstance).Execute() From 3efdd73ac0b1e519d4038a130047851b499d5d32 Mon Sep 17 00:00:00 2001 From: Oleksandr Zanichkovskyi Date: Tue, 5 May 2026 13:12:39 +0200 Subject: [PATCH 10/11] chore: Update examples/telemetryrouter/go.mod MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Gökce Gök Klingel <161626272+GokceGK@users.noreply.github.com> --- examples/telemetryrouter/go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/telemetryrouter/go.mod b/examples/telemetryrouter/go.mod index 15b3d2c81..3c40071c5 100644 --- a/examples/telemetryrouter/go.mod +++ b/examples/telemetryrouter/go.mod @@ -7,7 +7,7 @@ replace github.com/stackitcloud/stackit-sdk-go/services/telemetryrouter => ../.. require ( github.com/stackitcloud/stackit-sdk-go/core v0.26.0 - github.com/stackitcloud/stackit-sdk-go/services/telemetryrouter v0.1.2 + github.com/stackitcloud/stackit-sdk-go/services/telemetryrouter v0.2.1 ) require ( From 3679f7ea0db443f21e4a2504c666aa510577bd25 Mon Sep 17 00:00:00 2001 From: Oleksandr Zanichkovskyi Date: Tue, 5 May 2026 14:13:48 +0200 Subject: [PATCH 11/11] chore: more detailed logging --- examples/telemetryrouter/telemetryrouter.go | 58 ++++++++++++++++----- 1 file changed, 45 insertions(+), 13 deletions(-) diff --git a/examples/telemetryrouter/telemetryrouter.go b/examples/telemetryrouter/telemetryrouter.go index 4ffde82e9..14d5cfcf6 100644 --- a/examples/telemetryrouter/telemetryrouter.go +++ b/examples/telemetryrouter/telemetryrouter.go @@ -21,6 +21,7 @@ func main() { } // Create a Telemetry Router Instance + log.Printf("[TelemetryRouter API] Creating TelemetryRouter Instance.\n") var createdInstance string createInstancePayload := telemetryrouter.CreateTelemetryRouterPayload{ DisplayName: "my-tlmr-instance", @@ -35,13 +36,15 @@ func main() { createdInstance = createResp.Id // Wait for the Telemetry Router Instance to be ready + log.Printf("[TelemetryRouter API] Waiting for TelemetryRouter Instance to be created.\n") _, err = wait.CreateTelemetryRouterWaitHandler(ctx, client.DefaultAPI, projectId, regionId, createdInstance).WaitWithContext(context.Background()) if err != nil { log.Fatalf("[TelemetryRouter API] Error when waiting for creation: %v\n", err) } - log.Printf("[TelemetryRouter API] TelemetryRouter Instance %q has been successfully created.\n", createdInstance) + log.Printf("[TelemetryRouter API] TelemetryRouter Instance \"%s\" has been successfully created.\n", createdInstance) // List Telemetry Router Instances + log.Printf("[TelemetryRouter API] Retrieving TelemetryRouter Instances.\n") listResp, err := client.DefaultAPI.ListTelemetryRouters(ctx, projectId, regionId).Execute() if err != nil { log.Fatalf("[Telemetry Router API] Error when calling `ListTelemetryRouters`: %v\n", err) @@ -49,6 +52,7 @@ func main() { log.Printf("[Telemetry Router API] Retrieved %d Telemetry Router Instances.\n", len(listResp.TelemetryRouters)) // Get the created Telemetry Router Instance + log.Printf("[TelemetryRouter API] Getting TelemetryRouter Instance with ID \"%s\".\n", createResp.Id) getResp, err := client.DefaultAPI.GetTelemetryRouter(ctx, projectId, regionId, createdInstance).Execute() if err != nil { log.Fatalf("[Telemetry Router API] Error when calling `GetTelemetryRouter`: %v\n", err) @@ -56,6 +60,7 @@ func main() { log.Printf("[Telemetry Router API] Retrieved TelemetryRouter Instance with ID \"%s\" and Display Name \"%s\".\n", getResp.Id, getResp.DisplayName) // Update the created Telemetry Router Instance + log.Printf("[TelemetryRouter API] Updating TelemetryRouter Instance with ID \"%s\".\n", createResp.Id) updatePayload := telemetryrouter.UpdateTelemetryRouterPayload{ DisplayName: utils.Ptr("my-updated-tlmr-instance"), Filter: &telemetryrouter.ConfigFilter{ @@ -78,13 +83,15 @@ func main() { log.Printf("[Telemetry Router API] Updated Telemetry Router Instance with ID \"%s\" to Display Name \"%s\".\n", updateResp.Id, updateResp.DisplayName) // Wait for the Telemetry Router Instance to be updated + log.Printf("[TelemetryRouter API] Waiting for TelemetryRouter Instance with ID \"%s\" to be updated.\n", createResp.Id) _, err = wait.UpdateTelemetryRouterWaitHandler(ctx, client.DefaultAPI, projectId, regionId, createdInstance).WaitWithContext(context.Background()) if err != nil { log.Fatalf("[Telemetry Router API] Error when waiting for update: %v\n", err) } - log.Printf("[Telemetry Router API] TelemetryRouter Instance %q has been successfully updated.\n", createdInstance) + log.Printf("[Telemetry Router API] TelemetryRouter Instance \"%s\" has been successfully updated.\n", createdInstance) // Create an Access Token + log.Printf("[TelemetryRouter API] Creating AccessToken for TelemetryRouter Instance with ID \"%s\".\n", createResp.Id) createTokenPayload := telemetryrouter.CreateAccessTokenPayload{ DisplayName: "my-access-token", } @@ -97,13 +104,15 @@ func main() { log.Printf("[Telemetry Router API] Created Access Token with ID \"%s\".\n", createTokenResp.Id) // Wait for the Access Token to be created + log.Printf("[TelemetryRouter API] Waiting for AccessToken for TelemetryRouter Instance with ID \"%s\" to be created.\n", createResp.Id) _, err = wait.CreateAccessTokenWaitHandler(ctx, client.DefaultAPI, projectId, regionId, createdInstance, createTokenResp.Id).WaitWithContext(context.Background()) if err != nil { log.Fatalf("[Telemetry Router API] Error when waiting for creation: %v\n", err) } - log.Printf("[Telemetry Router API] Access Token %q has been successfully created.\n", createTokenResp.Id) + log.Printf("[Telemetry Router API] Access Token \"%s\" has been successfully created.\n", createTokenResp.Id) // Get the created Access Token + log.Printf("[TelemetryRouter API] Retrieving the AccessToken with ID \"%s\".\n", createTokenResp.Id) getTokenResp, err := client.DefaultAPI.GetAccessToken(ctx, projectId, regionId, createdInstance, createTokenResp.Id).Execute() if err != nil { log.Fatalf("[Telemetry Router API] Error when calling `GetAccessToken`: %v\n", err) @@ -111,18 +120,20 @@ func main() { log.Printf("[Telemetry Router API] Retrieved Access Token with ID \"%s\" and Display Name \"%s\".\n", getTokenResp.Id, getTokenResp.DisplayName) // List Access Tokens + log.Printf("[TelemetryRouter API] Listing AccessTokens.\n") listTokenResp, err := client.DefaultAPI.ListAccessTokens(ctx, projectId, regionId, createdInstance).Execute() if err != nil { log.Fatalf("[Telemetry Router API] Error when calling `ListAccessTokens`: %v\n", err) } log.Printf("[Telemetry Router API] Retrieved %d Access Tokens.\n", len(listTokenResp.AccessTokens)) + // Update an Access Token + log.Printf("[Telemetry Router API] Updating the Access Token with ID \"%s\".\n", createTokenResp.Id) newDisplayNameNS := telemetryrouter.NullableString{} newDisplayNameNS.Set(utils.Ptr("my-updated-acc-token")) updateTokenPayload := telemetryrouter.UpdateAccessTokenPayload{ DisplayName: newDisplayNameNS, } - // Update an Access Token updateTokenResp, err := client.DefaultAPI.UpdateAccessToken(ctx, projectId, regionId, createdInstance, createTokenResp.Id). UpdateAccessTokenPayload(updateTokenPayload). Execute() @@ -132,13 +143,15 @@ func main() { log.Printf("[Telemetry Router API] Updated Access Token with ID \"%s\" to Display Name \"%s\".\n.\n", updateTokenResp.Id, updateTokenResp.DisplayName) // Wait for the Access Token to be updated + log.Printf("[Telemetry Router API] Waiting for the Access Token with ID \"%s\" to be updated.\n", createTokenResp.Id) _, err = wait.UpdateAccessTokenWaitHandler(ctx, client.DefaultAPI, projectId, regionId, createdInstance, updateTokenResp.Id).WaitWithContext(context.Background()) if err != nil { log.Fatalf("[Telemetry Router API] Error when waiting for update: %v\n", err) } - log.Printf("[Telemetry Router API] Access Token %q has been successfully updated.\n", updateTokenResp.Id) + log.Printf("[Telemetry Router API] Access Token \"%s\" has been successfully updated.\n", updateTokenResp.Id) // Delete Access Token + log.Printf("[Telemetry Router API] Deleting for the Access Token with ID \"%s\".\n", createTokenResp.Id) err = client.DefaultAPI.DeleteAccessToken(ctx, projectId, regionId, createdInstance, updateTokenResp.Id).Execute() if err != nil { log.Fatalf("[Telemetry Router API] Error when calling `DeleteAccessToken`: %v\n", err) @@ -146,13 +159,15 @@ func main() { log.Printf("[Telemetry Router API] Deleted Access Tokens.\n") // Wait for the Access Token to be deleted + log.Printf("[Telemetry Router API] Waiting for the Access Token with ID \"%s\" to be deleted.\n", createTokenResp.Id) _, err = wait.DeleteAccessTokenWaitHandler(ctx, client.DefaultAPI, projectId, regionId, createdInstance, updateTokenResp.Id).WaitWithContext(context.Background()) if err != nil { log.Fatalf("[Telemetry Router API] Error when waiting for deletion: %v\n", err) } - log.Printf("[Telemetry Router API] Access Token %q has been successfully deleted.\n", updateTokenResp.Id) + log.Printf("[Telemetry Router API] Access Token \"%s\" has been successfully deleted.\n", updateTokenResp.Id) // Create S3 Destination + log.Printf("[Telemetry Router API] Creating Destination.\n") createS3DestinationPayload := telemetryrouter.CreateDestinationPayload{ DisplayName: "s3-destination", Config: telemetryrouter.DestinationConfig{ @@ -175,13 +190,15 @@ func main() { log.Printf("[Telemetry Router API] Created Destination with ID \"%s\".\n", createS3DestinationResp.Id) // Wait for the S3 Destination to be created + log.Printf("[Telemetry Router API] Waiting for a Destination to be created.\n") _, err = wait.CreateDestinationWaitHandler(ctx, client.DefaultAPI, projectId, regionId, createdInstance, createS3DestinationResp.Id).WaitWithContext(context.Background()) if err != nil { log.Fatalf("[Telemetry Router API] Error when waiting for creation: %v\n", err) } - log.Printf("[Telemetry Router API] Destination %q has been successfully created.\n", createS3DestinationResp.Id) + log.Printf("[Telemetry Router API] Destination \"%s\" has been successfully created.\n", createS3DestinationResp.Id) // Get the created S3 Destination + log.Printf("[Telemetry Router API] Retrieving Destination with ID \"%s\".\n", createS3DestinationResp.Id) getS3DestinationResp, err := client.DefaultAPI.GetDestination(ctx, projectId, regionId, createdInstance, createS3DestinationResp.Id).Execute() if err != nil { log.Fatalf("[Telemetry Router API] Error when calling `GetDestination`: %v\n", err) @@ -189,6 +206,7 @@ func main() { log.Printf("[Telemetry Router API] Retrieved Destination with ID \"%s\" and Display Name \"%s\".\n", getS3DestinationResp.Id, getS3DestinationResp.DisplayName) // List Destinations + log.Printf("[Telemetry Router API] Listing Destinations.\n") listDestinationResp, err := client.DefaultAPI.ListDestinations(ctx, projectId, regionId, createdInstance).Execute() if err != nil { log.Fatalf("[Telemetry Router API] Error when calling `ListDestinations`: %v\n", err) @@ -196,6 +214,7 @@ func main() { log.Printf("[Telemetry Router API] Retrieved %d Destinations.\n", len(listDestinationResp.Destinations)) // Update S3 Destination + log.Printf("[Telemetry Router API] Updating Destination with ID \"%s\".\n", createS3DestinationResp.Id) updateS3DestinationPayload := telemetryrouter.UpdateDestinationPayload{ DisplayName: utils.Ptr("updated-s3-destination"), Config: &telemetryrouter.DestinationConfig{ @@ -228,13 +247,15 @@ func main() { log.Printf("[Telemetry Router API] Updated Destination with ID \"%s\".\n", updateS3DestinationResp.Id) // Wait for the S3 Destination to be updated + log.Printf("[Telemetry Router API] Waiting for the Destination with ID \"%s\" to be updated.\n", createS3DestinationResp.Id) _, err = wait.UpdateDestinationWaitHandler(ctx, client.DefaultAPI, projectId, regionId, createdInstance, updateS3DestinationResp.Id).WaitWithContext(context.Background()) if err != nil { log.Fatalf("[Telemetry Router API] Error when waiting for update: %v\n", err) } - log.Printf("[Telemetry Router API] Destination %q has been successfully updated.\n", updateS3DestinationResp.Id) + log.Printf("[Telemetry Router API] Destination \"%s\" has been successfully updated.\n", updateS3DestinationResp.Id) // Delete S3 Destination + log.Printf("[Telemetry Router API] Deleting Destination with ID \"%s\".\n", updateS3DestinationResp.Id) err = client.DefaultAPI.DeleteDestination(ctx, projectId, regionId, createdInstance, updateS3DestinationResp.Id).Execute() if err != nil { log.Fatalf("[Telemetry Router API] Error when calling `DeleteDestination`: %v\n", err) @@ -242,13 +263,15 @@ func main() { log.Printf("[Telemetry Router API] Deleted Destination with ID \"%s\".\n", updateS3DestinationResp.Id) // Wait for the S3 Destination to be deleted + log.Printf("[Telemetry Router API] Waiting for Destination with ID \"%s\" to be deleted.\n", updateS3DestinationResp.Id) _, err = wait.DeleteDestinationWaitHandler(ctx, client.DefaultAPI, projectId, regionId, createdInstance, updateS3DestinationResp.Id).WaitWithContext(context.Background()) if err != nil { log.Fatalf("[Telemetry Router API] Error when waiting for deletion: %v\n", err) } - log.Printf("[Telemetry Router API] Destination %q has been successfully deleted.\n", updateS3DestinationResp.Id) + log.Printf("[Telemetry Router API] Destination \"%s\" has been successfully deleted.\n", updateS3DestinationResp.Id) // Create OpenTelemetry Destination + log.Printf("[Telemetry Router API] Creating Destination.\n") createOpenTelemetryDestinationPayload := telemetryrouter.CreateDestinationPayload{ DisplayName: "otlp-destination", Config: telemetryrouter.DestinationConfig{ @@ -270,13 +293,15 @@ func main() { log.Printf("[Telemetry Router API] Created Destination with ID \"%s\".\n", createOpenTelemetryDestinationResp.Id) // Wait for the OpenTelemetry Destination to be created + log.Printf("[Telemetry Router API] Waiting for Destination to be created.\n") _, err = wait.CreateDestinationWaitHandler(ctx, client.DefaultAPI, projectId, regionId, createdInstance, createOpenTelemetryDestinationResp.Id).WaitWithContext(context.Background()) if err != nil { log.Fatalf("[Telemetry Router API] Error when waiting for creation: %v\n", err) } - log.Printf("[Telemetry Router API] Destination %q has been successfully created.\n", createOpenTelemetryDestinationResp.Id) + log.Printf("[Telemetry Router API] Destination \"%s\" has been successfully created.\n", createOpenTelemetryDestinationResp.Id) // Get the created OpenTelemetry Destination + log.Printf("[Telemetry Router API] Receiving Destination with ID \"%s\".\n", createOpenTelemetryDestinationResp.Id) getOpenTelemetryDestinationResp, err := client.DefaultAPI.GetDestination(ctx, projectId, regionId, createdInstance, createOpenTelemetryDestinationResp.Id).Execute() if err != nil { log.Fatalf("[Telemetry Router API] Error when calling `GetDestination`: %v\n", err) @@ -284,6 +309,7 @@ func main() { log.Printf("[Telemetry Router API] Received Destination with ID \"%s\".\n", getOpenTelemetryDestinationResp.Id) // List Destinations + log.Printf("[Telemetry Router API] Listing Destinations.\n") listDestinationsResp, err := client.DefaultAPI.ListDestinations(ctx, projectId, regionId, createdInstance).Execute() if err != nil { log.Fatalf("[Telemetry Router API] Error when calling `ListDestinations`: %v\n", err) @@ -291,6 +317,7 @@ func main() { log.Printf("[Telemetry Router API] Received %d Destinations.\n", len(listDestinationsResp.Destinations)) // Update S3 Destination + log.Printf("[Telemetry Router API] Updating Destination with ID \"%s\".\n", createOpenTelemetryDestinationResp.Id) updateOTLPDestinationPayload := telemetryrouter.UpdateDestinationPayload{ DisplayName: utils.Ptr("updated-otlp-destination"), Config: &telemetryrouter.DestinationConfig{ @@ -322,13 +349,15 @@ func main() { log.Printf("[Telemetry Router API] Updated Destination with ID \"%s\".\n", updateOTLPDestinationResp.Id) // Wait for the OpenTelemetry Destination to be updated + log.Printf("[Telemetry Router API] Waiting for Destination \"%s\" to be updated.\n", createOpenTelemetryDestinationResp.Id) _, err = wait.UpdateDestinationWaitHandler(ctx, client.DefaultAPI, projectId, regionId, createdInstance, updateOTLPDestinationResp.Id).WaitWithContext(context.Background()) if err != nil { log.Fatalf("[Telemetry Router API] Error when waiting for update: %v\n", err) } - log.Printf("[Telemetry Router API] Destination %q has been successfully updated.\n", updateOTLPDestinationResp.Id) + log.Printf("[Telemetry Router API] Destination \"%s\" has been successfully updated.\n", updateOTLPDestinationResp.Id) // Delete OpenTelemetry Destination + log.Printf("[Telemetry Router API] Deleting Destination with ID \"%s\".\n", updateOTLPDestinationResp.Id) err = client.DefaultAPI.DeleteDestination(ctx, projectId, regionId, createdInstance, updateOTLPDestinationResp.Id).Execute() if err != nil { log.Fatalf("[Telemetry Router API] Error when calling `DeleteDestination`: %v\n", err) @@ -336,13 +365,15 @@ func main() { log.Printf("[Telemetry Router API] Deleted Destination with ID \"%s\".\n", updateOTLPDestinationResp.Id) // Wait for the OpenTelemetry Destination to be deleted + log.Printf("[Telemetry Router API] Waiting for Destination \"%s\" to be deleted.\n", updateOTLPDestinationResp.Id) _, err = wait.DeleteDestinationWaitHandler(ctx, client.DefaultAPI, projectId, regionId, createdInstance, updateOTLPDestinationResp.Id).WaitWithContext(context.Background()) if err != nil { log.Fatalf("[Telemetry Router API] Error when waiting for deletion: %v\n", err) } - log.Printf("[Telemetry Router API] Destination %q has been successfully deleted.\n", updateOTLPDestinationResp.Id) + log.Printf("[Telemetry Router API] Destination \"%s\" has been successfully deleted.\n", updateOTLPDestinationResp.Id) // Delete the created TelemetryRouter Instance + log.Printf("[Telemetry Router API] Deleting Telemetry Router Instance with ID \"%s\".\n", createdInstance) err = client.DefaultAPI.DeleteTelemetryRouter(ctx, projectId, regionId, createdInstance).Execute() if err != nil { log.Fatalf("[Telemetry Router API] Error when calling `DeleteTelemetryRouter`: %v\n", err) @@ -350,9 +381,10 @@ func main() { log.Printf("[Telemetry Router API] Deleted Telemetry Router Instance with ID \"%s\".\n", createdInstance) // Wait for the TelemetryRouter Instance to be deleted + log.Printf("[Telemetry Router API] Waiting for Telemetry Router Instance with ID \"%s\" to be deleted.\n", createdInstance) _, err = wait.DeleteTelemetryRouterWaitHandler(ctx, client.DefaultAPI, projectId, regionId, createdInstance).WaitWithContext(context.Background()) if err != nil { log.Fatalf("[Telemetry Router API] Error when waiting for deletion: %v\n", err) } - log.Printf("[Telemetry Router API] Telemetry Router Instance %q has been successfully deleted.\n", createdInstance) + log.Printf("[Telemetry Router API] Telemetry Router Instance \"%s\" has been successfully deleted.\n", createdInstance) }