almost... but stuck on requester

This commit is contained in:
Ryan McKinley 2024-06-14 23:34:04 +03:00
parent c1b786c718
commit 2f64556cf1
5 changed files with 30 additions and 11 deletions

View File

@ -4,10 +4,11 @@ import (
"fmt"
"net"
grafanarest "github.com/grafana/grafana/pkg/apiserver/rest"
"github.com/spf13/pflag"
genericapiserver "k8s.io/apiserver/pkg/server"
"k8s.io/apiserver/pkg/server/options"
grafanarest "github.com/grafana/grafana/pkg/apiserver/rest"
)
type StorageType string
@ -18,6 +19,7 @@ const (
StorageTypeLegacy StorageType = "legacy"
StorageTypeUnified StorageType = "unified"
StorageTypeUnifiedGrpc StorageType = "unified-grpc"
StorageTypeUnifiedExp StorageType = "unified-exp"
)
type StorageOptions struct {
@ -43,10 +45,10 @@ func (o *StorageOptions) AddFlags(fs *pflag.FlagSet) {
func (o *StorageOptions) Validate() []error {
errs := []error{}
switch o.StorageType {
case StorageTypeFile, StorageTypeEtcd, StorageTypeLegacy, StorageTypeUnified, StorageTypeUnifiedGrpc:
case StorageTypeFile, StorageTypeEtcd, StorageTypeLegacy, StorageTypeUnified, StorageTypeUnifiedGrpc, StorageTypeUnifiedExp:
// no-op
default:
errs = append(errs, fmt.Errorf("--grafana-apiserver-storage-type must be one of %s, %s, %s, %s, %s", StorageTypeFile, StorageTypeEtcd, StorageTypeLegacy, StorageTypeUnified, StorageTypeUnifiedGrpc))
errs = append(errs, fmt.Errorf("--grafana-apiserver-storage-type must be one of %s, %s, %s, %s, %s, %s", StorageTypeFile, StorageTypeEtcd, StorageTypeLegacy, StorageTypeUnified, StorageTypeUnifiedGrpc, StorageTypeUnifiedExp))
}
if _, _, err := net.SplitHostPort(o.Address); err != nil {

View File

@ -44,6 +44,9 @@ import (
"github.com/grafana/grafana/pkg/services/store/entity/db/dbimpl"
"github.com/grafana/grafana/pkg/services/store/entity/sqlstash"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/storage/unified/apistore"
"github.com/grafana/grafana/pkg/storage/unified/entitybridge"
"github.com/grafana/grafana/pkg/storage/unified/resource"
)
var (
@ -253,6 +256,25 @@ func (s *service) start(ctx context.Context) error {
return err
}
case grafanaapiserveroptions.StorageTypeUnifiedExp:
if !s.features.IsEnabledGlobally(featuremgmt.FlagUnifiedStorage) {
return fmt.Errorf("unified storage requires the unifiedStorage feature flag")
}
eDB, err := dbimpl.ProvideEntityDB(s.db, s.cfg, s.features, s.tracing)
if err != nil {
return err
}
storeServer, err := entitybridge.ProvideEntityStoreResources(eDB, s.tracing)
if err != nil {
return err
}
store := resource.NewResourceStoreClientLocal(storeServer)
serverConfig.Config.RESTOptionsGetter = apistore.NewRESTOptionsGetter(s.cfg, store, o.RecommendedOptions.Etcd.StorageConfig.Codec)
case grafanaapiserveroptions.StorageTypeUnified:
if !s.features.IsEnabledGlobally(featuremgmt.FlagUnifiedStorage) {
return fmt.Errorf("unified storage requires the unifiedStorage feature flag")

View File

@ -106,11 +106,6 @@ func (s *sqlEntityServer) init() error {
return errors.New("missing db")
}
err := s.db.Init()
if err != nil {
return err
}
sqlDB, err := s.db.GetDB()
if err != nil {
return err

View File

@ -356,7 +356,7 @@ func toListRequest(ctx context.Context, opts storage.ListOptions) (*resource.Lis
}
switch opts.ResourceVersionMatch {
case metav1.ResourceVersionMatchNotOlderThan:
case "", metav1.ResourceVersionMatchNotOlderThan:
req.VersionMatch = resource.ResourceVersionMatch_NotOlderThan
case metav1.ResourceVersionMatchExact:
req.VersionMatch = resource.ResourceVersionMatch_Exact

View File

@ -1,4 +1,4 @@
package sqlstash
package entitybridge
import (
"context"
@ -13,7 +13,7 @@ import (
// Creates a ResourceServer using the existing entity tables
// NOTE: most of the field values are ignored
func ProvideEnityStoreResources(db db.EntityDBInterface, tracer tracing.Tracer) (resource.ResourceServer, error) {
func ProvideEntityStoreResources(db db.EntityDBInterface, tracer tracing.Tracer) (resource.ResourceServer, error) {
entity, err := sqlstash.ProvideSQLEntityServer(db, tracer)
if err != nil {
return nil, err