|
1 | 1 | package promote
|
2 | 2 |
|
3 | 3 | import (
|
4 |
| - monitoring "cloud.google.com/go/monitoring/apiv3/v2" |
5 |
| - "cloud.google.com/go/monitoring/apiv3/v2/monitoringpb" |
6 | 4 | "context"
|
7 | 5 | "errors"
|
8 | 6 | "fmt"
|
| 7 | + "time" |
| 8 | + |
| 9 | + monitoring "cloud.google.com/go/monitoring/apiv3/v2" |
| 10 | + "cloud.google.com/go/monitoring/apiv3/v2/monitoringpb" |
9 | 11 | "github.com/nais/cloudsql-migrator/internal/pkg/common_main"
|
10 | 12 | "github.com/nais/cloudsql-migrator/internal/pkg/instance"
|
11 | 13 | "github.com/nais/cloudsql-migrator/internal/pkg/resolved"
|
12 | 14 | "google.golang.org/api/datamigration/v1"
|
13 |
| - "google.golang.org/api/googleapi" |
14 | 15 | "google.golang.org/api/iterator"
|
15 |
| - "net/http" |
16 |
| - "time" |
17 | 16 | )
|
18 | 17 |
|
19 | 18 | const MigrationJobRetries = 3
|
@@ -50,10 +49,8 @@ func CheckReadyForPromotion(ctx context.Context, source, target *resolved.Instan
|
50 | 49 | func getMigrationJobWithRetry(ctx context.Context, migrationName string, gcpProject *resolved.GcpProject, mgr *common_main.Manager, retries int) (*datamigration.MigrationJob, error) {
|
51 | 50 | migrationJob, err := mgr.DatamigrationService.Projects.Locations.MigrationJobs.Get(gcpProject.GcpComponentURI("migrationJobs", migrationName)).Context(ctx).Do()
|
52 | 51 | if err != nil {
|
53 |
| - var ae *googleapi.Error |
54 |
| - ok := errors.As(err, &ae) |
55 |
| - if ok && ae.Code == http.StatusForbidden { |
56 |
| - mgr.Logger.Warn("Forbidden from getting migration job, retrying in case permissions are not yet propagated") |
| 52 | + if retries > 0 { |
| 53 | + mgr.Logger.Warn("Failed to get migration job, retrying in case permissions are not yet propagated") |
57 | 54 | time.Sleep(20 * time.Second)
|
58 | 55 | return getMigrationJobWithRetry(ctx, migrationName, gcpProject, mgr, retries-1)
|
59 | 56 | }
|
@@ -106,14 +103,14 @@ func waitForReplicationLagToReachZero(ctx context.Context, target *resolved.Inst
|
106 | 103 | req := &monitoringpb.QueryTimeSeriesRequest{
|
107 | 104 | Name: gcpProject.GcpParentURI(),
|
108 | 105 | Query: "fetch cloudsql_database\n" +
|
109 |
| - "| metric\n" + |
110 |
| - " 'cloudsql.googleapis.com/database/postgresql/external_sync/max_replica_byte_lag'\n" + |
111 |
| - "| filter\n" + |
112 |
| - " resource.region == 'europe-north1' && \n" + |
113 |
| - fmt.Sprintf(" resource.project_id == '%s' &&\n", gcpProject.Id) + |
114 |
| - fmt.Sprintf(" resource.database_id == '%s:%s'\n", gcpProject.Id, target.Name) + |
115 |
| - "| group_by [], mean(val())\n" + |
116 |
| - "| within 5m\n", |
| 106 | + "| metric\n" + |
| 107 | + " 'cloudsql.googleapis.com/database/postgresql/external_sync/max_replica_byte_lag'\n" + |
| 108 | + "| filter\n" + |
| 109 | + " resource.region == 'europe-north1' && \n" + |
| 110 | + fmt.Sprintf(" resource.project_id == '%s' &&\n", gcpProject.Id) + |
| 111 | + fmt.Sprintf(" resource.database_id == '%s:%s'\n", gcpProject.Id, target.Name) + |
| 112 | + "| group_by [], mean(val())\n" + |
| 113 | + "| within 5m\n", |
117 | 114 | }
|
118 | 115 |
|
119 | 116 | for {
|
|
0 commit comments