mirror of https://github.com/grafana/grafana.git
				
				
				
			Remove dependency from OSS to enterprise packages by moving Spanner functions to xorm. (#102692)
* Remove dependency from OSS to enterprise packages by moving Spanner functions to xorm.
This commit is contained in:
		
							parent
							
								
									d4a4aac8d1
								
							
						
					
					
						commit
						00db0cf6e6
					
				
							
								
								
									
										2
									
								
								go.mod
								
								
								
								
							
							
						
						
									
										2
									
								
								go.mod
								
								
								
								
							| 
						 | 
					@ -560,12 +560,12 @@ require (
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
require (
 | 
					require (
 | 
				
			||||||
 | 
						github.com/1NCE-GmbH/grpc-go-pool v0.0.0-20231117122434-2a5bb974daa2 // @grafana/grafana-search-and-storage
 | 
				
			||||||
	github.com/open-feature/go-sdk v1.14.1 // @grafana/grafana-backend-group
 | 
						github.com/open-feature/go-sdk v1.14.1 // @grafana/grafana-backend-group
 | 
				
			||||||
	github.com/open-feature/go-sdk-contrib/providers/go-feature-flag v0.2.3 // @grafana/grafana-backend-group
 | 
						github.com/open-feature/go-sdk-contrib/providers/go-feature-flag v0.2.3 // @grafana/grafana-backend-group
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
require (
 | 
					require (
 | 
				
			||||||
	github.com/1NCE-GmbH/grpc-go-pool v0.0.0-20231117122434-2a5bb974daa2 // indirect
 | 
					 | 
				
			||||||
	github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.49.0 // indirect
 | 
						github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.49.0 // indirect
 | 
				
			||||||
	github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.49.0 // indirect
 | 
						github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.49.0 // indirect
 | 
				
			||||||
	github.com/RoaringBitmap/roaring/v2 v2.4.5 // indirect
 | 
						github.com/RoaringBitmap/roaring/v2 v2.4.5 // indirect
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -17,7 +17,6 @@ import (
 | 
				
			||||||
	"google.golang.org/grpc/codes"
 | 
						"google.golang.org/grpc/codes"
 | 
				
			||||||
	"xorm.io/core"
 | 
						"xorm.io/core"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	spannerext "github.com/grafana/grafana/pkg/extensions/spanner"
 | 
					 | 
				
			||||||
	"xorm.io/xorm"
 | 
						"xorm.io/xorm"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	_ "embed"
 | 
						_ "embed"
 | 
				
			||||||
| 
						 | 
					@ -291,7 +290,7 @@ func (s *SpannerDialect) executeDDLStatements(ctx context.Context, engine *xorm.
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	opts := spannerext.SpannerConnectorConfigToClientOptions(cfg)
 | 
						opts := xorm.SpannerConnectorConfigToClientOptions(cfg)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	databaseAdminClient, err := database.NewDatabaseAdminClient(ctx, opts...)
 | 
						databaseAdminClient, err := database.NewDatabaseAdminClient(ctx, opts...)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -10,9 +10,10 @@ import (
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	_ "github.com/googleapis/go-sql-spanner"
 | 
						_ "github.com/googleapis/go-sql-spanner"
 | 
				
			||||||
	spannerdriver "github.com/googleapis/go-sql-spanner"
 | 
						spannerdriver "github.com/googleapis/go-sql-spanner"
 | 
				
			||||||
 | 
						"google.golang.org/api/option"
 | 
				
			||||||
 | 
						"google.golang.org/grpc"
 | 
				
			||||||
 | 
						"google.golang.org/grpc/credentials/insecure"
 | 
				
			||||||
	"xorm.io/core"
 | 
						"xorm.io/core"
 | 
				
			||||||
 | 
					 | 
				
			||||||
	spannerext "github.com/grafana/grafana/pkg/extensions/spanner"
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func init() {
 | 
					func init() {
 | 
				
			||||||
| 
						 | 
					@ -381,7 +382,7 @@ func (s *spanner) CreateSequenceGenerator(db *sql.DB) (SequenceGenerator, error)
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if spannerext.UsePlainText(connectorConfig) {
 | 
						if UsePlainText(connectorConfig) {
 | 
				
			||||||
		// Plain-text means we're either using spannertest or Spanner emulator.
 | 
							// Plain-text means we're either using spannertest or Spanner emulator.
 | 
				
			||||||
		// Switch to fake in-memory sequence number generator in that case.
 | 
							// Switch to fake in-memory sequence number generator in that case.
 | 
				
			||||||
		//
 | 
							//
 | 
				
			||||||
| 
						 | 
					@ -393,3 +394,32 @@ func (s *spanner) CreateSequenceGenerator(db *sql.DB) (SequenceGenerator, error)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return newSequenceGenerator(db), nil
 | 
						return newSequenceGenerator(db), nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func UsePlainText(connectorConfig spannerdriver.ConnectorConfig) bool {
 | 
				
			||||||
 | 
						if strval, ok := connectorConfig.Params["useplaintext"]; ok {
 | 
				
			||||||
 | 
							if val, err := strconv.ParseBool(strval); err == nil {
 | 
				
			||||||
 | 
								return val
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return false
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// SpannerConnectorConfigToClientOptions is adapted from https://github.com/googleapis/go-sql-spanner/blob/main/driver.go#L341-L477, from version 1.11.1.
 | 
				
			||||||
 | 
					func SpannerConnectorConfigToClientOptions(connectorConfig spannerdriver.ConnectorConfig) []option.ClientOption {
 | 
				
			||||||
 | 
						var opts []option.ClientOption
 | 
				
			||||||
 | 
						if connectorConfig.Host != "" {
 | 
				
			||||||
 | 
							opts = append(opts, option.WithEndpoint(connectorConfig.Host))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if strval, ok := connectorConfig.Params["credentials"]; ok {
 | 
				
			||||||
 | 
							opts = append(opts, option.WithCredentialsFile(strval))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if strval, ok := connectorConfig.Params["credentialsjson"]; ok {
 | 
				
			||||||
 | 
							opts = append(opts, option.WithCredentialsJSON([]byte(strval)))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if UsePlainText(connectorConfig) {
 | 
				
			||||||
 | 
							opts = append(opts,
 | 
				
			||||||
 | 
								option.WithGRPCDialOption(grpc.WithTransportCredentials(insecure.NewCredentials())),
 | 
				
			||||||
 | 
								option.WithoutAuthentication())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return opts
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,6 +7,8 @@ require (
 | 
				
			||||||
	github.com/googleapis/go-sql-spanner v1.11.1
 | 
						github.com/googleapis/go-sql-spanner v1.11.1
 | 
				
			||||||
	github.com/mattn/go-sqlite3 v1.14.22
 | 
						github.com/mattn/go-sqlite3 v1.14.22
 | 
				
			||||||
	github.com/stretchr/testify v1.10.0
 | 
						github.com/stretchr/testify v1.10.0
 | 
				
			||||||
 | 
						google.golang.org/api v0.220.0
 | 
				
			||||||
 | 
						google.golang.org/grpc v1.70.0
 | 
				
			||||||
	xorm.io/builder v0.3.6
 | 
						xorm.io/builder v0.3.6
 | 
				
			||||||
	xorm.io/core v0.7.3
 | 
						xorm.io/core v0.7.3
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
| 
						 | 
					@ -55,11 +57,9 @@ require (
 | 
				
			||||||
	golang.org/x/sys v0.30.0 // indirect
 | 
						golang.org/x/sys v0.30.0 // indirect
 | 
				
			||||||
	golang.org/x/text v0.22.0 // indirect
 | 
						golang.org/x/text v0.22.0 // indirect
 | 
				
			||||||
	golang.org/x/time v0.9.0 // indirect
 | 
						golang.org/x/time v0.9.0 // indirect
 | 
				
			||||||
	google.golang.org/api v0.220.0 // indirect
 | 
					 | 
				
			||||||
	google.golang.org/genproto v0.0.0-20250122153221-138b5a5a4fd4 // indirect
 | 
						google.golang.org/genproto v0.0.0-20250122153221-138b5a5a4fd4 // indirect
 | 
				
			||||||
	google.golang.org/genproto/googleapis/api v0.0.0-20250204164813-702378808489 // indirect
 | 
						google.golang.org/genproto/googleapis/api v0.0.0-20250204164813-702378808489 // indirect
 | 
				
			||||||
	google.golang.org/genproto/googleapis/rpc v0.0.0-20250207221924-e9438ea467c6 // indirect
 | 
						google.golang.org/genproto/googleapis/rpc v0.0.0-20250207221924-e9438ea467c6 // indirect
 | 
				
			||||||
	google.golang.org/grpc v1.70.0 // indirect
 | 
					 | 
				
			||||||
	google.golang.org/protobuf v1.36.5 // indirect
 | 
						google.golang.org/protobuf v1.36.5 // indirect
 | 
				
			||||||
	gopkg.in/yaml.v3 v3.0.1 // indirect
 | 
						gopkg.in/yaml.v3 v3.0.1 // indirect
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue