2024-02-01 16:27:30 -06:00
|
|
|
package apiserver
|
2023-07-14 14:22:10 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-10-06 13:55:22 -05:00
|
|
|
"fmt"
|
|
|
|
"net/http"
|
2023-10-31 12:26:39 -05:00
|
|
|
"net/http/httptest"
|
2023-07-14 14:22:10 -05:00
|
|
|
"path"
|
|
|
|
|
|
|
|
"github.com/grafana/dskit/services"
|
Storage: Unified Storage based on Entity API (#71977)
* first round of entityapi updates
- quote column names and clean up insert/update queries
- replace grn with guid
- streamline table structure
fixes
streamline entity history
move EntitySummary into proto
remove EntitySummary
add guid to json
fix tests
change DB_Uuid to DB_NVarchar
fix folder test
convert interface to any
more cleanup
start entity store under grafana-apiserver dskit target
CRUD working, kind of
rough cut of wiring entity api to kube-apiserver
fake grafana user in context
add key to entity
list working
revert unnecessary changes
move entity storage files to their own package, clean up
use accessor to read/write grafana annotations
implement separate Create and Update functions
* go mod tidy
* switch from Kind to resource
* basic grpc storage server
* basic support for grpc entity store
* don't connect to database unless it's needed, pass user identity over grpc
* support getting user from k8s context, fix some mysql issues
* assign owner to snowflake dependency
* switch from ulid to uuid for guids
* cleanup, rename Search to List
* remove entityListResult
* EntityAPI: remove extra user abstraction (#79033)
* remove extra user abstraction
* add test stub (but
* move grpc context setup into client wrapper, fix lint issue
* remove unused constants
* remove custom json stuff
* basic list filtering, add todo
* change target to storage-server, allow entityStore flag in prod mode
* fix issue with Update
* EntityAPI: make test work, need to resolve expected differences (#79123)
* make test work, need to resolve expected differences
* remove the fields not supported by legacy
* sanitize out the bits legacy does not support
* sanitize out the bits legacy does not support
---------
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
* update feature toggle generated files
* remove unused http headers
* update feature flag strategy
* devmode
* update readme
* spelling
* readme
---------
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
2023-12-06 14:21:21 -06:00
|
|
|
"google.golang.org/grpc"
|
|
|
|
"google.golang.org/grpc/credentials/insecure"
|
2023-09-22 13:17:53 -05:00
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
"k8s.io/apimachinery/pkg/runtime"
|
|
|
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
|
|
|
"k8s.io/apimachinery/pkg/runtime/serializer"
|
2023-09-25 17:31:58 -05:00
|
|
|
"k8s.io/apiserver/pkg/endpoints/responsewriter"
|
2023-07-14 14:22:10 -05:00
|
|
|
genericapiserver "k8s.io/apiserver/pkg/server"
|
2023-09-22 13:17:53 -05:00
|
|
|
clientrest "k8s.io/client-go/rest"
|
2023-07-14 14:22:10 -05:00
|
|
|
"k8s.io/client-go/tools/clientcmd"
|
2023-12-05 16:31:49 -06:00
|
|
|
|
2023-09-25 17:31:58 -05:00
|
|
|
"github.com/grafana/grafana/pkg/api/routing"
|
|
|
|
"github.com/grafana/grafana/pkg/infra/appcontext"
|
Storage: Unified Storage based on Entity API (#71977)
* first round of entityapi updates
- quote column names and clean up insert/update queries
- replace grn with guid
- streamline table structure
fixes
streamline entity history
move EntitySummary into proto
remove EntitySummary
add guid to json
fix tests
change DB_Uuid to DB_NVarchar
fix folder test
convert interface to any
more cleanup
start entity store under grafana-apiserver dskit target
CRUD working, kind of
rough cut of wiring entity api to kube-apiserver
fake grafana user in context
add key to entity
list working
revert unnecessary changes
move entity storage files to their own package, clean up
use accessor to read/write grafana annotations
implement separate Create and Update functions
* go mod tidy
* switch from Kind to resource
* basic grpc storage server
* basic support for grpc entity store
* don't connect to database unless it's needed, pass user identity over grpc
* support getting user from k8s context, fix some mysql issues
* assign owner to snowflake dependency
* switch from ulid to uuid for guids
* cleanup, rename Search to List
* remove entityListResult
* EntityAPI: remove extra user abstraction (#79033)
* remove extra user abstraction
* add test stub (but
* move grpc context setup into client wrapper, fix lint issue
* remove unused constants
* remove custom json stuff
* basic list filtering, add todo
* change target to storage-server, allow entityStore flag in prod mode
* fix issue with Update
* EntityAPI: make test work, need to resolve expected differences (#79123)
* make test work, need to resolve expected differences
* remove the fields not supported by legacy
* sanitize out the bits legacy does not support
* sanitize out the bits legacy does not support
---------
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
* update feature toggle generated files
* remove unused http headers
* update feature flag strategy
* devmode
* update readme
* spelling
* readme
---------
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
2023-12-06 14:21:21 -06:00
|
|
|
"github.com/grafana/grafana/pkg/infra/db"
|
2023-10-25 14:19:44 -05:00
|
|
|
"github.com/grafana/grafana/pkg/infra/tracing"
|
2023-09-25 17:31:58 -05:00
|
|
|
"github.com/grafana/grafana/pkg/middleware"
|
2023-09-08 09:12:12 -05:00
|
|
|
"github.com/grafana/grafana/pkg/modules"
|
2023-09-25 17:31:58 -05:00
|
|
|
"github.com/grafana/grafana/pkg/registry"
|
2024-02-01 16:27:30 -06:00
|
|
|
"github.com/grafana/grafana/pkg/services/apiserver/auth/authorizer"
|
|
|
|
"github.com/grafana/grafana/pkg/services/apiserver/builder"
|
|
|
|
grafanaapiserveroptions "github.com/grafana/grafana/pkg/services/apiserver/options"
|
|
|
|
entitystorage "github.com/grafana/grafana/pkg/services/apiserver/storage/entity"
|
|
|
|
filestorage "github.com/grafana/grafana/pkg/services/apiserver/storage/file"
|
|
|
|
"github.com/grafana/grafana/pkg/services/apiserver/utils"
|
2023-09-25 17:31:58 -05:00
|
|
|
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
2023-11-13 13:39:01 -06:00
|
|
|
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
2024-02-01 16:27:30 -06:00
|
|
|
"github.com/grafana/grafana/pkg/services/org"
|
Storage: Unified Storage based on Entity API (#71977)
* first round of entityapi updates
- quote column names and clean up insert/update queries
- replace grn with guid
- streamline table structure
fixes
streamline entity history
move EntitySummary into proto
remove EntitySummary
add guid to json
fix tests
change DB_Uuid to DB_NVarchar
fix folder test
convert interface to any
more cleanup
start entity store under grafana-apiserver dskit target
CRUD working, kind of
rough cut of wiring entity api to kube-apiserver
fake grafana user in context
add key to entity
list working
revert unnecessary changes
move entity storage files to their own package, clean up
use accessor to read/write grafana annotations
implement separate Create and Update functions
* go mod tidy
* switch from Kind to resource
* basic grpc storage server
* basic support for grpc entity store
* don't connect to database unless it's needed, pass user identity over grpc
* support getting user from k8s context, fix some mysql issues
* assign owner to snowflake dependency
* switch from ulid to uuid for guids
* cleanup, rename Search to List
* remove entityListResult
* EntityAPI: remove extra user abstraction (#79033)
* remove extra user abstraction
* add test stub (but
* move grpc context setup into client wrapper, fix lint issue
* remove unused constants
* remove custom json stuff
* basic list filtering, add todo
* change target to storage-server, allow entityStore flag in prod mode
* fix issue with Update
* EntityAPI: make test work, need to resolve expected differences (#79123)
* make test work, need to resolve expected differences
* remove the fields not supported by legacy
* sanitize out the bits legacy does not support
* sanitize out the bits legacy does not support
---------
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
* update feature toggle generated files
* remove unused http headers
* update feature flag strategy
* devmode
* update readme
* spelling
* readme
---------
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
2023-12-06 14:21:21 -06:00
|
|
|
"github.com/grafana/grafana/pkg/services/store/entity"
|
2024-01-30 07:15:12 -06:00
|
|
|
"github.com/grafana/grafana/pkg/services/store/entity/db/dbimpl"
|
Storage: Unified Storage based on Entity API (#71977)
* first round of entityapi updates
- quote column names and clean up insert/update queries
- replace grn with guid
- streamline table structure
fixes
streamline entity history
move EntitySummary into proto
remove EntitySummary
add guid to json
fix tests
change DB_Uuid to DB_NVarchar
fix folder test
convert interface to any
more cleanup
start entity store under grafana-apiserver dskit target
CRUD working, kind of
rough cut of wiring entity api to kube-apiserver
fake grafana user in context
add key to entity
list working
revert unnecessary changes
move entity storage files to their own package, clean up
use accessor to read/write grafana annotations
implement separate Create and Update functions
* go mod tidy
* switch from Kind to resource
* basic grpc storage server
* basic support for grpc entity store
* don't connect to database unless it's needed, pass user identity over grpc
* support getting user from k8s context, fix some mysql issues
* assign owner to snowflake dependency
* switch from ulid to uuid for guids
* cleanup, rename Search to List
* remove entityListResult
* EntityAPI: remove extra user abstraction (#79033)
* remove extra user abstraction
* add test stub (but
* move grpc context setup into client wrapper, fix lint issue
* remove unused constants
* remove custom json stuff
* basic list filtering, add todo
* change target to storage-server, allow entityStore flag in prod mode
* fix issue with Update
* EntityAPI: make test work, need to resolve expected differences (#79123)
* make test work, need to resolve expected differences
* remove the fields not supported by legacy
* sanitize out the bits legacy does not support
* sanitize out the bits legacy does not support
---------
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
* update feature toggle generated files
* remove unused http headers
* update feature flag strategy
* devmode
* update readme
* spelling
* readme
---------
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
2023-12-06 14:21:21 -06:00
|
|
|
"github.com/grafana/grafana/pkg/services/store/entity/sqlstash"
|
2023-09-25 17:31:58 -05:00
|
|
|
"github.com/grafana/grafana/pkg/setting"
|
2023-07-14 14:22:10 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2023-09-25 17:31:58 -05:00
|
|
|
_ Service = (*service)(nil)
|
|
|
|
_ RestConfigProvider = (*service)(nil)
|
|
|
|
_ registry.BackgroundService = (*service)(nil)
|
|
|
|
_ registry.CanBeDisabled = (*service)(nil)
|
2023-07-14 14:22:10 -05:00
|
|
|
|
2023-09-22 13:17:53 -05:00
|
|
|
Scheme = runtime.NewScheme()
|
|
|
|
Codecs = serializer.NewCodecFactory(Scheme)
|
|
|
|
|
|
|
|
unversionedVersion = schema.GroupVersion{Group: "", Version: "v1"}
|
|
|
|
unversionedTypes = []runtime.Object{
|
|
|
|
&metav1.Status{},
|
|
|
|
&metav1.WatchEvent{},
|
|
|
|
&metav1.APIVersions{},
|
|
|
|
&metav1.APIGroupList{},
|
|
|
|
&metav1.APIGroup{},
|
|
|
|
&metav1.APIResourceList{},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
// we need to add the options to empty v1
|
|
|
|
metav1.AddToGroupVersion(Scheme, schema.GroupVersion{Group: "", Version: "v1"})
|
|
|
|
Scheme.AddUnversionedTypes(unversionedVersion, unversionedTypes...)
|
|
|
|
}
|
|
|
|
|
2023-07-14 14:22:10 -05:00
|
|
|
type Service interface {
|
|
|
|
services.NamedService
|
2023-09-25 17:31:58 -05:00
|
|
|
registry.BackgroundService
|
|
|
|
registry.CanBeDisabled
|
|
|
|
}
|
|
|
|
|
2023-07-14 14:22:10 -05:00
|
|
|
type RestConfigProvider interface {
|
2023-09-22 13:17:53 -05:00
|
|
|
GetRestConfig() *clientrest.Config
|
2023-07-14 14:22:10 -05:00
|
|
|
}
|
|
|
|
|
2023-10-31 12:26:39 -05:00
|
|
|
type DirectRestConfigProvider interface {
|
|
|
|
// GetDirectRestConfig returns a k8s client configuration that will use the same
|
|
|
|
// logged logged in user as the current request context. This is useful when
|
|
|
|
// creating clients that map legacy API handlers to k8s backed services
|
|
|
|
GetDirectRestConfig(c *contextmodel.ReqContext) *clientrest.Config
|
2024-01-31 12:36:51 -06:00
|
|
|
|
|
|
|
// This can be used to rewrite incoming requests to path now supported under /apis
|
|
|
|
DirectlyServeHTTP(w http.ResponseWriter, r *http.Request)
|
2023-10-31 12:26:39 -05:00
|
|
|
}
|
|
|
|
|
2023-07-14 14:22:10 -05:00
|
|
|
type service struct {
|
|
|
|
*services.BasicService
|
|
|
|
|
2024-02-01 16:27:30 -06:00
|
|
|
options *grafanaapiserveroptions.Options
|
2023-10-17 10:29:06 -05:00
|
|
|
restConfig *clientrest.Config
|
2023-07-14 14:22:10 -05:00
|
|
|
|
Storage: Unified Storage based on Entity API (#71977)
* first round of entityapi updates
- quote column names and clean up insert/update queries
- replace grn with guid
- streamline table structure
fixes
streamline entity history
move EntitySummary into proto
remove EntitySummary
add guid to json
fix tests
change DB_Uuid to DB_NVarchar
fix folder test
convert interface to any
more cleanup
start entity store under grafana-apiserver dskit target
CRUD working, kind of
rough cut of wiring entity api to kube-apiserver
fake grafana user in context
add key to entity
list working
revert unnecessary changes
move entity storage files to their own package, clean up
use accessor to read/write grafana annotations
implement separate Create and Update functions
* go mod tidy
* switch from Kind to resource
* basic grpc storage server
* basic support for grpc entity store
* don't connect to database unless it's needed, pass user identity over grpc
* support getting user from k8s context, fix some mysql issues
* assign owner to snowflake dependency
* switch from ulid to uuid for guids
* cleanup, rename Search to List
* remove entityListResult
* EntityAPI: remove extra user abstraction (#79033)
* remove extra user abstraction
* add test stub (but
* move grpc context setup into client wrapper, fix lint issue
* remove unused constants
* remove custom json stuff
* basic list filtering, add todo
* change target to storage-server, allow entityStore flag in prod mode
* fix issue with Update
* EntityAPI: make test work, need to resolve expected differences (#79123)
* make test work, need to resolve expected differences
* remove the fields not supported by legacy
* sanitize out the bits legacy does not support
* sanitize out the bits legacy does not support
---------
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
* update feature toggle generated files
* remove unused http headers
* update feature flag strategy
* devmode
* update readme
* spelling
* readme
---------
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
2023-12-06 14:21:21 -06:00
|
|
|
cfg *setting.Cfg
|
|
|
|
features featuremgmt.FeatureToggles
|
|
|
|
|
2023-07-14 14:22:10 -05:00
|
|
|
stopCh chan struct{}
|
|
|
|
stoppedCh chan error
|
2023-09-25 17:31:58 -05:00
|
|
|
|
Storage: Unified Storage based on Entity API (#71977)
* first round of entityapi updates
- quote column names and clean up insert/update queries
- replace grn with guid
- streamline table structure
fixes
streamline entity history
move EntitySummary into proto
remove EntitySummary
add guid to json
fix tests
change DB_Uuid to DB_NVarchar
fix folder test
convert interface to any
more cleanup
start entity store under grafana-apiserver dskit target
CRUD working, kind of
rough cut of wiring entity api to kube-apiserver
fake grafana user in context
add key to entity
list working
revert unnecessary changes
move entity storage files to their own package, clean up
use accessor to read/write grafana annotations
implement separate Create and Update functions
* go mod tidy
* switch from Kind to resource
* basic grpc storage server
* basic support for grpc entity store
* don't connect to database unless it's needed, pass user identity over grpc
* support getting user from k8s context, fix some mysql issues
* assign owner to snowflake dependency
* switch from ulid to uuid for guids
* cleanup, rename Search to List
* remove entityListResult
* EntityAPI: remove extra user abstraction (#79033)
* remove extra user abstraction
* add test stub (but
* move grpc context setup into client wrapper, fix lint issue
* remove unused constants
* remove custom json stuff
* basic list filtering, add todo
* change target to storage-server, allow entityStore flag in prod mode
* fix issue with Update
* EntityAPI: make test work, need to resolve expected differences (#79123)
* make test work, need to resolve expected differences
* remove the fields not supported by legacy
* sanitize out the bits legacy does not support
* sanitize out the bits legacy does not support
---------
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
* update feature toggle generated files
* remove unused http headers
* update feature flag strategy
* devmode
* update readme
* spelling
* readme
---------
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
2023-12-06 14:21:21 -06:00
|
|
|
db db.DB
|
2023-09-25 17:31:58 -05:00
|
|
|
rr routing.RouteRegister
|
2023-10-31 12:26:39 -05:00
|
|
|
handler http.Handler
|
2024-02-01 16:27:30 -06:00
|
|
|
builders []builder.APIGroupBuilder
|
2023-09-28 17:28:58 -05:00
|
|
|
|
2023-10-25 14:19:44 -05:00
|
|
|
tracing *tracing.TracingService
|
|
|
|
|
2023-12-19 11:12:35 -06:00
|
|
|
authorizer *authorizer.GrafanaAuthorizer
|
2023-07-14 14:22:10 -05:00
|
|
|
}
|
|
|
|
|
2023-09-26 16:15:15 -05:00
|
|
|
func ProvideService(
|
|
|
|
cfg *setting.Cfg,
|
2023-11-13 13:39:01 -06:00
|
|
|
features featuremgmt.FeatureToggles,
|
2023-09-25 17:31:58 -05:00
|
|
|
rr routing.RouteRegister,
|
2023-12-19 11:12:35 -06:00
|
|
|
orgService org.Service,
|
2023-10-25 14:19:44 -05:00
|
|
|
tracing *tracing.TracingService,
|
Storage: Unified Storage based on Entity API (#71977)
* first round of entityapi updates
- quote column names and clean up insert/update queries
- replace grn with guid
- streamline table structure
fixes
streamline entity history
move EntitySummary into proto
remove EntitySummary
add guid to json
fix tests
change DB_Uuid to DB_NVarchar
fix folder test
convert interface to any
more cleanup
start entity store under grafana-apiserver dskit target
CRUD working, kind of
rough cut of wiring entity api to kube-apiserver
fake grafana user in context
add key to entity
list working
revert unnecessary changes
move entity storage files to their own package, clean up
use accessor to read/write grafana annotations
implement separate Create and Update functions
* go mod tidy
* switch from Kind to resource
* basic grpc storage server
* basic support for grpc entity store
* don't connect to database unless it's needed, pass user identity over grpc
* support getting user from k8s context, fix some mysql issues
* assign owner to snowflake dependency
* switch from ulid to uuid for guids
* cleanup, rename Search to List
* remove entityListResult
* EntityAPI: remove extra user abstraction (#79033)
* remove extra user abstraction
* add test stub (but
* move grpc context setup into client wrapper, fix lint issue
* remove unused constants
* remove custom json stuff
* basic list filtering, add todo
* change target to storage-server, allow entityStore flag in prod mode
* fix issue with Update
* EntityAPI: make test work, need to resolve expected differences (#79123)
* make test work, need to resolve expected differences
* remove the fields not supported by legacy
* sanitize out the bits legacy does not support
* sanitize out the bits legacy does not support
---------
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
* update feature toggle generated files
* remove unused http headers
* update feature flag strategy
* devmode
* update readme
* spelling
* readme
---------
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
2023-12-06 14:21:21 -06:00
|
|
|
db db.DB,
|
2023-09-25 17:31:58 -05:00
|
|
|
) (*service, error) {
|
2023-07-14 14:22:10 -05:00
|
|
|
s := &service{
|
Storage: Unified Storage based on Entity API (#71977)
* first round of entityapi updates
- quote column names and clean up insert/update queries
- replace grn with guid
- streamline table structure
fixes
streamline entity history
move EntitySummary into proto
remove EntitySummary
add guid to json
fix tests
change DB_Uuid to DB_NVarchar
fix folder test
convert interface to any
more cleanup
start entity store under grafana-apiserver dskit target
CRUD working, kind of
rough cut of wiring entity api to kube-apiserver
fake grafana user in context
add key to entity
list working
revert unnecessary changes
move entity storage files to their own package, clean up
use accessor to read/write grafana annotations
implement separate Create and Update functions
* go mod tidy
* switch from Kind to resource
* basic grpc storage server
* basic support for grpc entity store
* don't connect to database unless it's needed, pass user identity over grpc
* support getting user from k8s context, fix some mysql issues
* assign owner to snowflake dependency
* switch from ulid to uuid for guids
* cleanup, rename Search to List
* remove entityListResult
* EntityAPI: remove extra user abstraction (#79033)
* remove extra user abstraction
* add test stub (but
* move grpc context setup into client wrapper, fix lint issue
* remove unused constants
* remove custom json stuff
* basic list filtering, add todo
* change target to storage-server, allow entityStore flag in prod mode
* fix issue with Update
* EntityAPI: make test work, need to resolve expected differences (#79123)
* make test work, need to resolve expected differences
* remove the fields not supported by legacy
* sanitize out the bits legacy does not support
* sanitize out the bits legacy does not support
---------
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
* update feature toggle generated files
* remove unused http headers
* update feature flag strategy
* devmode
* update readme
* spelling
* readme
---------
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
2023-12-06 14:21:21 -06:00
|
|
|
cfg: cfg,
|
|
|
|
features: features,
|
2023-10-17 10:29:06 -05:00
|
|
|
rr: rr,
|
|
|
|
stopCh: make(chan struct{}),
|
2024-02-01 16:27:30 -06:00
|
|
|
builders: []builder.APIGroupBuilder{},
|
2023-12-19 11:12:35 -06:00
|
|
|
authorizer: authorizer.NewGrafanaAuthorizer(cfg, orgService),
|
2023-10-27 15:39:27 -05:00
|
|
|
tracing: tracing,
|
Storage: Unified Storage based on Entity API (#71977)
* first round of entityapi updates
- quote column names and clean up insert/update queries
- replace grn with guid
- streamline table structure
fixes
streamline entity history
move EntitySummary into proto
remove EntitySummary
add guid to json
fix tests
change DB_Uuid to DB_NVarchar
fix folder test
convert interface to any
more cleanup
start entity store under grafana-apiserver dskit target
CRUD working, kind of
rough cut of wiring entity api to kube-apiserver
fake grafana user in context
add key to entity
list working
revert unnecessary changes
move entity storage files to their own package, clean up
use accessor to read/write grafana annotations
implement separate Create and Update functions
* go mod tidy
* switch from Kind to resource
* basic grpc storage server
* basic support for grpc entity store
* don't connect to database unless it's needed, pass user identity over grpc
* support getting user from k8s context, fix some mysql issues
* assign owner to snowflake dependency
* switch from ulid to uuid for guids
* cleanup, rename Search to List
* remove entityListResult
* EntityAPI: remove extra user abstraction (#79033)
* remove extra user abstraction
* add test stub (but
* move grpc context setup into client wrapper, fix lint issue
* remove unused constants
* remove custom json stuff
* basic list filtering, add todo
* change target to storage-server, allow entityStore flag in prod mode
* fix issue with Update
* EntityAPI: make test work, need to resolve expected differences (#79123)
* make test work, need to resolve expected differences
* remove the fields not supported by legacy
* sanitize out the bits legacy does not support
* sanitize out the bits legacy does not support
---------
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
* update feature toggle generated files
* remove unused http headers
* update feature flag strategy
* devmode
* update readme
* spelling
* readme
---------
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
2023-12-06 14:21:21 -06:00
|
|
|
db: db, // For Unified storage
|
2023-07-14 14:22:10 -05:00
|
|
|
}
|
|
|
|
|
2023-09-25 17:31:58 -05:00
|
|
|
// This will be used when running as a dskit service
|
2023-08-31 08:12:01 -05:00
|
|
|
s.BasicService = services.NewBasicService(s.start, s.running, nil).WithName(modules.GrafanaAPIServer)
|
2023-07-14 14:22:10 -05:00
|
|
|
|
2023-09-25 17:31:58 -05:00
|
|
|
// TODO: this is very hacky
|
|
|
|
// We need to register the routes in ProvideService to make sure
|
|
|
|
// the routes are registered before the Grafana HTTP server starts.
|
2023-10-04 13:05:50 -05:00
|
|
|
proxyHandler := func(k8sRoute routing.RouteRegister) {
|
2023-09-25 17:31:58 -05:00
|
|
|
handler := func(c *contextmodel.ReqContext) {
|
|
|
|
if s.handler == nil {
|
|
|
|
c.Resp.WriteHeader(404)
|
|
|
|
_, _ = c.Resp.Write([]byte("Not found"))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-10-31 12:26:39 -05:00
|
|
|
req := c.Req
|
|
|
|
if req.URL.Path == "" {
|
|
|
|
req.URL.Path = "/"
|
2023-09-25 17:31:58 -05:00
|
|
|
}
|
2023-10-31 12:26:39 -05:00
|
|
|
|
|
|
|
resp := responsewriter.WrapForHTTP1Or2(c.Resp)
|
|
|
|
s.handler.ServeHTTP(resp, req)
|
2023-09-25 17:31:58 -05:00
|
|
|
}
|
|
|
|
k8sRoute.Any("/", middleware.ReqSignedIn, handler)
|
|
|
|
k8sRoute.Any("/*", middleware.ReqSignedIn, handler)
|
2023-10-04 13:05:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
s.rr.Group("/apis", proxyHandler)
|
2024-02-01 16:27:30 -06:00
|
|
|
s.rr.Group("/livez", proxyHandler)
|
|
|
|
s.rr.Group("/readyz", proxyHandler)
|
|
|
|
s.rr.Group("/healthz", proxyHandler)
|
2023-10-04 13:05:50 -05:00
|
|
|
s.rr.Group("/openapi", proxyHandler)
|
2023-09-25 17:31:58 -05:00
|
|
|
|
2023-07-14 14:22:10 -05:00
|
|
|
return s, nil
|
|
|
|
}
|
|
|
|
|
2023-09-22 13:17:53 -05:00
|
|
|
func (s *service) GetRestConfig() *clientrest.Config {
|
2023-07-14 14:22:10 -05:00
|
|
|
return s.restConfig
|
|
|
|
}
|
|
|
|
|
2023-09-25 17:31:58 -05:00
|
|
|
func (s *service) IsDisabled() bool {
|
2024-02-01 16:27:30 -06:00
|
|
|
return false
|
2023-09-25 17:31:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run is an adapter for the BackgroundService interface.
|
|
|
|
func (s *service) Run(ctx context.Context) error {
|
|
|
|
if err := s.start(ctx); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return s.running(ctx)
|
|
|
|
}
|
|
|
|
|
2024-02-01 16:27:30 -06:00
|
|
|
func (s *service) RegisterAPI(b builder.APIGroupBuilder) {
|
|
|
|
s.builders = append(s.builders, b)
|
2023-09-25 17:31:58 -05:00
|
|
|
}
|
|
|
|
|
2023-07-14 14:22:10 -05:00
|
|
|
func (s *service) start(ctx context.Context) error {
|
2023-10-24 09:19:17 -05:00
|
|
|
// Get the list of groups the server will support
|
|
|
|
builders := s.builders
|
|
|
|
|
|
|
|
groupVersions := make([]schema.GroupVersion, 0, len(builders))
|
|
|
|
// Install schemas
|
|
|
|
for _, b := range builders {
|
|
|
|
groupVersions = append(groupVersions, b.GetGroupVersion())
|
|
|
|
if err := b.InstallSchema(Scheme); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-12-19 11:12:35 -06:00
|
|
|
|
|
|
|
auth := b.GetAuthorizer()
|
|
|
|
if auth != nil {
|
|
|
|
s.authorizer.Register(b.GetGroupVersion(), auth)
|
|
|
|
}
|
2023-10-24 09:19:17 -05:00
|
|
|
}
|
|
|
|
|
2024-02-01 16:27:30 -06:00
|
|
|
o := grafanaapiserveroptions.NewOptions(Codecs.LegacyCodec(groupVersions...))
|
|
|
|
applyGrafanaConfig(s.cfg, s.features, o)
|
2023-09-26 16:15:15 -05:00
|
|
|
|
2024-02-01 16:27:30 -06:00
|
|
|
if errs := o.Validate(); len(errs) != 0 {
|
|
|
|
// TODO: handle multiple errors
|
|
|
|
return errs[0]
|
|
|
|
}
|
2023-07-14 14:22:10 -05:00
|
|
|
|
2023-09-22 13:17:53 -05:00
|
|
|
serverConfig := genericapiserver.NewRecommendedConfig(Codecs)
|
2024-02-01 16:27:30 -06:00
|
|
|
if err := o.ApplyTo(serverConfig); err != nil {
|
|
|
|
return err
|
2023-07-14 14:22:10 -05:00
|
|
|
}
|
2024-02-01 16:27:30 -06:00
|
|
|
serverConfig.Authorization.Authorizer = s.authorizer
|
|
|
|
serverConfig.TracerProvider = s.tracing.GetTracerProvider()
|
2023-07-14 14:22:10 -05:00
|
|
|
|
2024-02-01 16:27:30 -06:00
|
|
|
// setup loopback transport
|
|
|
|
transport := &roundTripperFunc{ready: make(chan struct{})}
|
|
|
|
serverConfig.LoopbackClientConfig.Transport = transport
|
|
|
|
serverConfig.LoopbackClientConfig.TLSClientConfig = clientrest.TLSClientConfig{}
|
|
|
|
|
|
|
|
switch o.StorageOptions.StorageType {
|
|
|
|
case grafanaapiserveroptions.StorageTypeEtcd:
|
|
|
|
if err := o.RecommendedOptions.Etcd.Validate(); len(err) > 0 {
|
2023-10-27 15:39:27 -05:00
|
|
|
return err[0]
|
|
|
|
}
|
2024-02-01 16:27:30 -06:00
|
|
|
if err := o.RecommendedOptions.Etcd.ApplyTo(&serverConfig.Config); err != nil {
|
2023-10-23 13:42:10 -05:00
|
|
|
return err
|
|
|
|
}
|
2023-07-14 14:22:10 -05:00
|
|
|
|
2024-02-01 16:27:30 -06:00
|
|
|
case grafanaapiserveroptions.StorageTypeUnified:
|
Storage: Unified Storage based on Entity API (#71977)
* first round of entityapi updates
- quote column names and clean up insert/update queries
- replace grn with guid
- streamline table structure
fixes
streamline entity history
move EntitySummary into proto
remove EntitySummary
add guid to json
fix tests
change DB_Uuid to DB_NVarchar
fix folder test
convert interface to any
more cleanup
start entity store under grafana-apiserver dskit target
CRUD working, kind of
rough cut of wiring entity api to kube-apiserver
fake grafana user in context
add key to entity
list working
revert unnecessary changes
move entity storage files to their own package, clean up
use accessor to read/write grafana annotations
implement separate Create and Update functions
* go mod tidy
* switch from Kind to resource
* basic grpc storage server
* basic support for grpc entity store
* don't connect to database unless it's needed, pass user identity over grpc
* support getting user from k8s context, fix some mysql issues
* assign owner to snowflake dependency
* switch from ulid to uuid for guids
* cleanup, rename Search to List
* remove entityListResult
* EntityAPI: remove extra user abstraction (#79033)
* remove extra user abstraction
* add test stub (but
* move grpc context setup into client wrapper, fix lint issue
* remove unused constants
* remove custom json stuff
* basic list filtering, add todo
* change target to storage-server, allow entityStore flag in prod mode
* fix issue with Update
* EntityAPI: make test work, need to resolve expected differences (#79123)
* make test work, need to resolve expected differences
* remove the fields not supported by legacy
* sanitize out the bits legacy does not support
* sanitize out the bits legacy does not support
---------
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
* update feature toggle generated files
* remove unused http headers
* update feature flag strategy
* devmode
* update readme
* spelling
* readme
---------
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
2023-12-06 14:21:21 -06:00
|
|
|
if !s.features.IsEnabledGlobally(featuremgmt.FlagUnifiedStorage) {
|
|
|
|
return fmt.Errorf("unified storage requires the unifiedStorage feature flag (and app_mode = development)")
|
|
|
|
}
|
|
|
|
|
2024-01-30 07:15:12 -06:00
|
|
|
eDB, err := dbimpl.ProvideEntityDB(s.db, s.cfg, s.features)
|
Storage: Unified Storage based on Entity API (#71977)
* first round of entityapi updates
- quote column names and clean up insert/update queries
- replace grn with guid
- streamline table structure
fixes
streamline entity history
move EntitySummary into proto
remove EntitySummary
add guid to json
fix tests
change DB_Uuid to DB_NVarchar
fix folder test
convert interface to any
more cleanup
start entity store under grafana-apiserver dskit target
CRUD working, kind of
rough cut of wiring entity api to kube-apiserver
fake grafana user in context
add key to entity
list working
revert unnecessary changes
move entity storage files to their own package, clean up
use accessor to read/write grafana annotations
implement separate Create and Update functions
* go mod tidy
* switch from Kind to resource
* basic grpc storage server
* basic support for grpc entity store
* don't connect to database unless it's needed, pass user identity over grpc
* support getting user from k8s context, fix some mysql issues
* assign owner to snowflake dependency
* switch from ulid to uuid for guids
* cleanup, rename Search to List
* remove entityListResult
* EntityAPI: remove extra user abstraction (#79033)
* remove extra user abstraction
* add test stub (but
* move grpc context setup into client wrapper, fix lint issue
* remove unused constants
* remove custom json stuff
* basic list filtering, add todo
* change target to storage-server, allow entityStore flag in prod mode
* fix issue with Update
* EntityAPI: make test work, need to resolve expected differences (#79123)
* make test work, need to resolve expected differences
* remove the fields not supported by legacy
* sanitize out the bits legacy does not support
* sanitize out the bits legacy does not support
---------
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
* update feature toggle generated files
* remove unused http headers
* update feature flag strategy
* devmode
* update readme
* spelling
* readme
---------
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
2023-12-06 14:21:21 -06:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
store, err := sqlstash.ProvideSQLEntityServer(eDB)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-02-01 16:27:30 -06:00
|
|
|
serverConfig.Config.RESTOptionsGetter = entitystorage.NewRESTOptionsGetter(s.cfg, store, o.RecommendedOptions.Etcd.StorageConfig.Codec)
|
Storage: Unified Storage based on Entity API (#71977)
* first round of entityapi updates
- quote column names and clean up insert/update queries
- replace grn with guid
- streamline table structure
fixes
streamline entity history
move EntitySummary into proto
remove EntitySummary
add guid to json
fix tests
change DB_Uuid to DB_NVarchar
fix folder test
convert interface to any
more cleanup
start entity store under grafana-apiserver dskit target
CRUD working, kind of
rough cut of wiring entity api to kube-apiserver
fake grafana user in context
add key to entity
list working
revert unnecessary changes
move entity storage files to their own package, clean up
use accessor to read/write grafana annotations
implement separate Create and Update functions
* go mod tidy
* switch from Kind to resource
* basic grpc storage server
* basic support for grpc entity store
* don't connect to database unless it's needed, pass user identity over grpc
* support getting user from k8s context, fix some mysql issues
* assign owner to snowflake dependency
* switch from ulid to uuid for guids
* cleanup, rename Search to List
* remove entityListResult
* EntityAPI: remove extra user abstraction (#79033)
* remove extra user abstraction
* add test stub (but
* move grpc context setup into client wrapper, fix lint issue
* remove unused constants
* remove custom json stuff
* basic list filtering, add todo
* change target to storage-server, allow entityStore flag in prod mode
* fix issue with Update
* EntityAPI: make test work, need to resolve expected differences (#79123)
* make test work, need to resolve expected differences
* remove the fields not supported by legacy
* sanitize out the bits legacy does not support
* sanitize out the bits legacy does not support
---------
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
* update feature toggle generated files
* remove unused http headers
* update feature flag strategy
* devmode
* update readme
* spelling
* readme
---------
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
2023-12-06 14:21:21 -06:00
|
|
|
|
2024-02-01 16:27:30 -06:00
|
|
|
case grafanaapiserveroptions.StorageTypeUnifiedGrpc:
|
Storage: Unified Storage based on Entity API (#71977)
* first round of entityapi updates
- quote column names and clean up insert/update queries
- replace grn with guid
- streamline table structure
fixes
streamline entity history
move EntitySummary into proto
remove EntitySummary
add guid to json
fix tests
change DB_Uuid to DB_NVarchar
fix folder test
convert interface to any
more cleanup
start entity store under grafana-apiserver dskit target
CRUD working, kind of
rough cut of wiring entity api to kube-apiserver
fake grafana user in context
add key to entity
list working
revert unnecessary changes
move entity storage files to their own package, clean up
use accessor to read/write grafana annotations
implement separate Create and Update functions
* go mod tidy
* switch from Kind to resource
* basic grpc storage server
* basic support for grpc entity store
* don't connect to database unless it's needed, pass user identity over grpc
* support getting user from k8s context, fix some mysql issues
* assign owner to snowflake dependency
* switch from ulid to uuid for guids
* cleanup, rename Search to List
* remove entityListResult
* EntityAPI: remove extra user abstraction (#79033)
* remove extra user abstraction
* add test stub (but
* move grpc context setup into client wrapper, fix lint issue
* remove unused constants
* remove custom json stuff
* basic list filtering, add todo
* change target to storage-server, allow entityStore flag in prod mode
* fix issue with Update
* EntityAPI: make test work, need to resolve expected differences (#79123)
* make test work, need to resolve expected differences
* remove the fields not supported by legacy
* sanitize out the bits legacy does not support
* sanitize out the bits legacy does not support
---------
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
* update feature toggle generated files
* remove unused http headers
* update feature flag strategy
* devmode
* update readme
* spelling
* readme
---------
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
2023-12-06 14:21:21 -06:00
|
|
|
// Create a connection to the gRPC server
|
|
|
|
// TODO: support configuring the gRPC server address
|
|
|
|
conn, err := grpc.Dial("localhost:10000", grpc.WithTransportCredentials(insecure.NewCredentials()))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: determine when to close the connection, we cannot defer it here
|
|
|
|
// defer conn.Close()
|
|
|
|
|
|
|
|
// Create a client instance
|
|
|
|
store := entity.NewEntityStoreClientWrapper(conn)
|
|
|
|
|
2024-02-01 16:27:30 -06:00
|
|
|
serverConfig.Config.RESTOptionsGetter = entitystorage.NewRESTOptionsGetter(s.cfg, store, o.RecommendedOptions.Etcd.StorageConfig.Codec)
|
Storage: Unified Storage based on Entity API (#71977)
* first round of entityapi updates
- quote column names and clean up insert/update queries
- replace grn with guid
- streamline table structure
fixes
streamline entity history
move EntitySummary into proto
remove EntitySummary
add guid to json
fix tests
change DB_Uuid to DB_NVarchar
fix folder test
convert interface to any
more cleanup
start entity store under grafana-apiserver dskit target
CRUD working, kind of
rough cut of wiring entity api to kube-apiserver
fake grafana user in context
add key to entity
list working
revert unnecessary changes
move entity storage files to their own package, clean up
use accessor to read/write grafana annotations
implement separate Create and Update functions
* go mod tidy
* switch from Kind to resource
* basic grpc storage server
* basic support for grpc entity store
* don't connect to database unless it's needed, pass user identity over grpc
* support getting user from k8s context, fix some mysql issues
* assign owner to snowflake dependency
* switch from ulid to uuid for guids
* cleanup, rename Search to List
* remove entityListResult
* EntityAPI: remove extra user abstraction (#79033)
* remove extra user abstraction
* add test stub (but
* move grpc context setup into client wrapper, fix lint issue
* remove unused constants
* remove custom json stuff
* basic list filtering, add todo
* change target to storage-server, allow entityStore flag in prod mode
* fix issue with Update
* EntityAPI: make test work, need to resolve expected differences (#79123)
* make test work, need to resolve expected differences
* remove the fields not supported by legacy
* sanitize out the bits legacy does not support
* sanitize out the bits legacy does not support
---------
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
* update feature toggle generated files
* remove unused http headers
* update feature flag strategy
* devmode
* update readme
* spelling
* readme
---------
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
2023-12-06 14:21:21 -06:00
|
|
|
|
2024-02-01 16:27:30 -06:00
|
|
|
case grafanaapiserveroptions.StorageTypeLegacy:
|
|
|
|
fallthrough
|
|
|
|
case grafanaapiserveroptions.StorageTypeFile:
|
|
|
|
serverConfig.RESTOptionsGetter = filestorage.NewRESTOptionsGetter(o.StorageOptions.DataPath, o.RecommendedOptions.Etcd.StorageConfig)
|
2023-10-27 15:39:27 -05:00
|
|
|
}
|
|
|
|
|
2023-09-22 20:29:43 -05:00
|
|
|
// Add OpenAPI specs for each group+version
|
2024-02-01 16:27:30 -06:00
|
|
|
err := builder.SetupConfig(Scheme, serverConfig, builders)
|
2023-11-14 14:29:15 -06:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-10-25 14:19:44 -05:00
|
|
|
|
2024-01-16 10:30:01 -06:00
|
|
|
// support folder selection
|
|
|
|
err = entitystorage.RegisterFieldSelectorSupport(Scheme)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-09-22 20:29:43 -05:00
|
|
|
// Create the server
|
2023-09-22 13:17:53 -05:00
|
|
|
server, err := serverConfig.Complete().New("grafana-apiserver", genericapiserver.NewEmptyDelegate())
|
2023-07-14 14:22:10 -05:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-02-01 16:27:30 -06:00
|
|
|
dualWriteEnabled := o.StorageOptions.StorageType != grafanaapiserveroptions.StorageTypeLegacy
|
|
|
|
|
2023-09-22 20:29:43 -05:00
|
|
|
// Install the API Group+version
|
2024-02-01 16:27:30 -06:00
|
|
|
err = builder.InstallAPIs(Scheme, Codecs, server, serverConfig.RESTOptionsGetter, builders, dualWriteEnabled)
|
2024-01-10 09:30:16 -06:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2023-07-14 14:22:10 -05:00
|
|
|
}
|
|
|
|
|
2024-02-01 16:27:30 -06:00
|
|
|
// set the transport function and signal that it's ready
|
|
|
|
transport.fn = func(req *http.Request) (*http.Response, error) {
|
|
|
|
w := newWrappedResponseWriter()
|
|
|
|
resp := responsewriter.WrapForHTTP1Or2(w)
|
|
|
|
server.Handler.ServeHTTP(resp, req)
|
|
|
|
return w.Result(), nil
|
|
|
|
}
|
|
|
|
close(transport.ready)
|
|
|
|
|
|
|
|
// only write kubeconfig in dev mode
|
|
|
|
if o.ExtraOptions.DevMode {
|
|
|
|
if err := ensureKubeConfig(server.LoopbackClientConfig, o.StorageOptions.DataPath); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-31 12:26:39 -05:00
|
|
|
// Used by the proxy wrapper registered in ProvideService
|
|
|
|
s.handler = server.Handler
|
2023-11-13 14:51:41 -06:00
|
|
|
s.restConfig = server.LoopbackClientConfig
|
2024-02-01 16:27:30 -06:00
|
|
|
s.options = o
|
2023-10-23 13:42:10 -05:00
|
|
|
|
2023-12-06 16:06:18 -06:00
|
|
|
prepared := server.PrepareRun()
|
|
|
|
|
2023-07-14 14:22:10 -05:00
|
|
|
go func() {
|
|
|
|
s.stoppedCh <- prepared.Run(s.stopCh)
|
|
|
|
}()
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-10-31 12:26:39 -05:00
|
|
|
func (s *service) GetDirectRestConfig(c *contextmodel.ReqContext) *clientrest.Config {
|
|
|
|
return &clientrest.Config{
|
|
|
|
Transport: &roundTripperFunc{
|
|
|
|
fn: func(req *http.Request) (*http.Response, error) {
|
|
|
|
ctx := appcontext.WithUser(req.Context(), c.SignedInUser)
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
s.handler.ServeHTTP(w, req.WithContext(ctx))
|
|
|
|
return w.Result(), nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-31 12:36:51 -06:00
|
|
|
func (s *service) DirectlyServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
|
|
s.handler.ServeHTTP(w, r)
|
|
|
|
}
|
|
|
|
|
2023-07-14 14:22:10 -05:00
|
|
|
func (s *service) running(ctx context.Context) error {
|
|
|
|
select {
|
|
|
|
case err := <-s.stoppedCh:
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
case <-ctx.Done():
|
|
|
|
close(s.stopCh)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-02-01 16:27:30 -06:00
|
|
|
func ensureKubeConfig(restConfig *clientrest.Config, dir string) error {
|
2023-12-05 16:31:49 -06:00
|
|
|
return clientcmd.WriteToFile(
|
2024-02-01 16:27:30 -06:00
|
|
|
utils.FormatKubeConfig(restConfig),
|
|
|
|
path.Join(dir, "grafana.kubeconfig"),
|
2023-12-05 16:31:49 -06:00
|
|
|
)
|
2023-07-14 14:22:10 -05:00
|
|
|
}
|
2023-10-31 12:26:39 -05:00
|
|
|
|
|
|
|
type roundTripperFunc struct {
|
2024-02-01 16:27:30 -06:00
|
|
|
ready chan struct{}
|
|
|
|
fn func(req *http.Request) (*http.Response, error)
|
2023-10-31 12:26:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (f *roundTripperFunc) RoundTrip(req *http.Request) (*http.Response, error) {
|
2024-02-01 16:27:30 -06:00
|
|
|
if f.fn == nil {
|
|
|
|
<-f.ready
|
|
|
|
}
|
2023-10-31 12:26:39 -05:00
|
|
|
return f.fn(req)
|
|
|
|
}
|
2023-11-14 14:29:15 -06:00
|
|
|
|
2024-02-01 16:27:30 -06:00
|
|
|
var _ http.ResponseWriter = (*wrappedResponseWriter)(nil)
|
|
|
|
var _ responsewriter.UserProvidedDecorator = (*wrappedResponseWriter)(nil)
|
2023-11-14 14:29:15 -06:00
|
|
|
|
2024-02-01 16:27:30 -06:00
|
|
|
type wrappedResponseWriter struct {
|
|
|
|
*httptest.ResponseRecorder
|
|
|
|
}
|
2023-11-17 13:20:54 -06:00
|
|
|
|
2024-02-01 16:27:30 -06:00
|
|
|
func newWrappedResponseWriter() *wrappedResponseWriter {
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
return &wrappedResponseWriter{w}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *wrappedResponseWriter) Unwrap() http.ResponseWriter {
|
|
|
|
return w.ResponseRecorder
|
|
|
|
}
|
2023-11-14 14:29:15 -06:00
|
|
|
|
2024-02-01 16:27:30 -06:00
|
|
|
func (w *wrappedResponseWriter) CloseNotify() <-chan bool {
|
|
|
|
// TODO: this is probably not the right thing to do here
|
|
|
|
return make(<-chan bool)
|
2023-11-14 14:29:15 -06:00
|
|
|
}
|