mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Revert "Plugins: Add logs for plugin proto client retrieval" (#93617)
Revert "Plugins: Add logs for plugin proto client retrieval (#93527)"
This reverts commit ccf6fbebfa
.
This commit is contained in:
parent
eee7270b07
commit
7cd546238b
@ -15,7 +15,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errClientNotAvailable = errors.New("plugin client is not available")
|
errClientNotStarted = errors.New("plugin client has not been started")
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ ProtoClient = (*protoClient)(nil)
|
var _ ProtoClient = (*protoClient)(nil)
|
||||||
@ -36,6 +36,7 @@ type ProtoClient interface {
|
|||||||
Logger() log.Logger
|
Logger() log.Logger
|
||||||
Start(context.Context) error
|
Start(context.Context) error
|
||||||
Stop(context.Context) error
|
Stop(context.Context) error
|
||||||
|
Running(context.Context) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type protoClient struct {
|
type protoClient struct {
|
||||||
@ -43,20 +44,9 @@ type protoClient struct {
|
|||||||
pluginVersion string
|
pluginVersion string
|
||||||
pluginJSON plugins.JSONData
|
pluginJSON plugins.JSONData
|
||||||
|
|
||||||
state pluginState
|
|
||||||
|
|
||||||
mu sync.RWMutex
|
mu sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
type pluginState int
|
|
||||||
|
|
||||||
const (
|
|
||||||
pluginStateNotStarted pluginState = iota
|
|
||||||
pluginStateStartSuccess
|
|
||||||
pluginStateStartFail
|
|
||||||
pluginStateStopped
|
|
||||||
)
|
|
||||||
|
|
||||||
type ProtoClientOpts struct {
|
type ProtoClientOpts struct {
|
||||||
PluginJSON plugins.JSONData
|
PluginJSON plugins.JSONData
|
||||||
ExecutablePath string
|
ExecutablePath string
|
||||||
@ -78,12 +68,12 @@ func NewProtoClient(opts ProtoClientOpts) (ProtoClient, error) {
|
|||||||
func() []string { return opts.Env },
|
func() []string { return opts.Env },
|
||||||
)
|
)
|
||||||
|
|
||||||
return &protoClient{plugin: p, pluginVersion: opts.PluginJSON.Info.Version, pluginJSON: opts.PluginJSON, state: pluginStateNotStarted}, nil
|
return &protoClient{plugin: p, pluginVersion: opts.PluginJSON.Info.Version, pluginJSON: opts.PluginJSON}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *protoClient) PID(ctx context.Context) (string, error) {
|
func (r *protoClient) PID(ctx context.Context) (string, error) {
|
||||||
if _, exists := r.client(ctx); !exists {
|
if _, exists := r.client(ctx); !exists {
|
||||||
return "", errClientNotAvailable
|
return "", errClientNotStarted
|
||||||
}
|
}
|
||||||
return r.plugin.client.ID(), nil
|
return r.plugin.client.ID(), nil
|
||||||
}
|
}
|
||||||
@ -111,60 +101,40 @@ func (r *protoClient) Logger() log.Logger {
|
|||||||
func (r *protoClient) Start(ctx context.Context) error {
|
func (r *protoClient) Start(ctx context.Context) error {
|
||||||
r.mu.Lock()
|
r.mu.Lock()
|
||||||
defer r.mu.Unlock()
|
defer r.mu.Unlock()
|
||||||
|
return r.plugin.Start(ctx)
|
||||||
err := r.plugin.Start(ctx)
|
|
||||||
if err != nil {
|
|
||||||
r.state = pluginStateStartFail
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
r.state = pluginStateStartSuccess
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *protoClient) Stop(ctx context.Context) error {
|
func (r *protoClient) Stop(ctx context.Context) error {
|
||||||
r.mu.Lock()
|
r.mu.Lock()
|
||||||
defer r.mu.Unlock()
|
defer r.mu.Unlock()
|
||||||
r.state = pluginStateStopped
|
|
||||||
return r.plugin.Stop(ctx)
|
return r.plugin.Stop(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *protoClient) client(ctx context.Context) (*ClientV2, bool) {
|
func (r *protoClient) Running(_ context.Context) bool {
|
||||||
r.mu.RLock()
|
r.mu.RLock()
|
||||||
defer r.mu.RUnlock()
|
defer r.mu.RUnlock()
|
||||||
|
return !r.plugin.Exited()
|
||||||
|
}
|
||||||
|
|
||||||
logger := r.Logger().FromContext(ctx)
|
func (r *protoClient) client(ctx context.Context) (*ClientV2, bool) {
|
||||||
if r.state == pluginStateNotStarted {
|
if !r.Running(ctx) {
|
||||||
logger.Debug("Plugin client has not been started yet")
|
|
||||||
return nil, false
|
|
||||||
}
|
|
||||||
|
|
||||||
if r.state == pluginStateStartFail {
|
|
||||||
logger.Debug("Plugin client failed to start")
|
|
||||||
return nil, false
|
|
||||||
}
|
|
||||||
|
|
||||||
if r.state == pluginStateStopped {
|
|
||||||
logger.Debug("Plugin client has stopped")
|
|
||||||
return nil, false
|
|
||||||
}
|
|
||||||
|
|
||||||
if r.plugin.Exited() {
|
|
||||||
logger.Debug("Plugin client has exited")
|
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
r.mu.RLock()
|
||||||
if r.plugin.pluginClient == nil {
|
if r.plugin.pluginClient == nil {
|
||||||
|
r.mu.RUnlock()
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
pc := r.plugin.pluginClient
|
pc := r.plugin.pluginClient
|
||||||
|
r.mu.RUnlock()
|
||||||
return pc, true
|
return pc, true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *protoClient) QueryData(ctx context.Context, in *pluginv2.QueryDataRequest, opts ...grpc.CallOption) (*pluginv2.QueryDataResponse, error) {
|
func (r *protoClient) QueryData(ctx context.Context, in *pluginv2.QueryDataRequest, opts ...grpc.CallOption) (*pluginv2.QueryDataResponse, error) {
|
||||||
c, exists := r.client(ctx)
|
c, exists := r.client(ctx)
|
||||||
if !exists {
|
if !exists {
|
||||||
return nil, errClientNotAvailable
|
return nil, errClientNotStarted
|
||||||
}
|
}
|
||||||
return c.DataClient.QueryData(ctx, in, opts...)
|
return c.DataClient.QueryData(ctx, in, opts...)
|
||||||
}
|
}
|
||||||
@ -172,7 +142,7 @@ func (r *protoClient) QueryData(ctx context.Context, in *pluginv2.QueryDataReque
|
|||||||
func (r *protoClient) CallResource(ctx context.Context, in *pluginv2.CallResourceRequest, opts ...grpc.CallOption) (pluginv2.Resource_CallResourceClient, error) {
|
func (r *protoClient) CallResource(ctx context.Context, in *pluginv2.CallResourceRequest, opts ...grpc.CallOption) (pluginv2.Resource_CallResourceClient, error) {
|
||||||
c, exists := r.client(ctx)
|
c, exists := r.client(ctx)
|
||||||
if !exists {
|
if !exists {
|
||||||
return nil, errClientNotAvailable
|
return nil, errClientNotStarted
|
||||||
}
|
}
|
||||||
return c.ResourceClient.CallResource(ctx, in, opts...)
|
return c.ResourceClient.CallResource(ctx, in, opts...)
|
||||||
}
|
}
|
||||||
@ -180,7 +150,7 @@ func (r *protoClient) CallResource(ctx context.Context, in *pluginv2.CallResourc
|
|||||||
func (r *protoClient) CheckHealth(ctx context.Context, in *pluginv2.CheckHealthRequest, opts ...grpc.CallOption) (*pluginv2.CheckHealthResponse, error) {
|
func (r *protoClient) CheckHealth(ctx context.Context, in *pluginv2.CheckHealthRequest, opts ...grpc.CallOption) (*pluginv2.CheckHealthResponse, error) {
|
||||||
c, exists := r.client(ctx)
|
c, exists := r.client(ctx)
|
||||||
if !exists {
|
if !exists {
|
||||||
return nil, errClientNotAvailable
|
return nil, errClientNotStarted
|
||||||
}
|
}
|
||||||
return c.DiagnosticsClient.CheckHealth(ctx, in, opts...)
|
return c.DiagnosticsClient.CheckHealth(ctx, in, opts...)
|
||||||
}
|
}
|
||||||
@ -188,7 +158,7 @@ func (r *protoClient) CheckHealth(ctx context.Context, in *pluginv2.CheckHealthR
|
|||||||
func (r *protoClient) CollectMetrics(ctx context.Context, in *pluginv2.CollectMetricsRequest, opts ...grpc.CallOption) (*pluginv2.CollectMetricsResponse, error) {
|
func (r *protoClient) CollectMetrics(ctx context.Context, in *pluginv2.CollectMetricsRequest, opts ...grpc.CallOption) (*pluginv2.CollectMetricsResponse, error) {
|
||||||
c, exists := r.client(ctx)
|
c, exists := r.client(ctx)
|
||||||
if !exists {
|
if !exists {
|
||||||
return nil, errClientNotAvailable
|
return nil, errClientNotStarted
|
||||||
}
|
}
|
||||||
return c.DiagnosticsClient.CollectMetrics(ctx, in, opts...)
|
return c.DiagnosticsClient.CollectMetrics(ctx, in, opts...)
|
||||||
}
|
}
|
||||||
@ -196,7 +166,7 @@ func (r *protoClient) CollectMetrics(ctx context.Context, in *pluginv2.CollectMe
|
|||||||
func (r *protoClient) SubscribeStream(ctx context.Context, in *pluginv2.SubscribeStreamRequest, opts ...grpc.CallOption) (*pluginv2.SubscribeStreamResponse, error) {
|
func (r *protoClient) SubscribeStream(ctx context.Context, in *pluginv2.SubscribeStreamRequest, opts ...grpc.CallOption) (*pluginv2.SubscribeStreamResponse, error) {
|
||||||
c, exists := r.client(ctx)
|
c, exists := r.client(ctx)
|
||||||
if !exists {
|
if !exists {
|
||||||
return nil, errClientNotAvailable
|
return nil, errClientNotStarted
|
||||||
}
|
}
|
||||||
return c.StreamClient.SubscribeStream(ctx, in, opts...)
|
return c.StreamClient.SubscribeStream(ctx, in, opts...)
|
||||||
}
|
}
|
||||||
@ -204,7 +174,7 @@ func (r *protoClient) SubscribeStream(ctx context.Context, in *pluginv2.Subscrib
|
|||||||
func (r *protoClient) RunStream(ctx context.Context, in *pluginv2.RunStreamRequest, opts ...grpc.CallOption) (pluginv2.Stream_RunStreamClient, error) {
|
func (r *protoClient) RunStream(ctx context.Context, in *pluginv2.RunStreamRequest, opts ...grpc.CallOption) (pluginv2.Stream_RunStreamClient, error) {
|
||||||
c, exists := r.client(ctx)
|
c, exists := r.client(ctx)
|
||||||
if !exists {
|
if !exists {
|
||||||
return nil, errClientNotAvailable
|
return nil, errClientNotStarted
|
||||||
}
|
}
|
||||||
return c.StreamClient.RunStream(ctx, in, opts...)
|
return c.StreamClient.RunStream(ctx, in, opts...)
|
||||||
}
|
}
|
||||||
@ -212,7 +182,7 @@ func (r *protoClient) RunStream(ctx context.Context, in *pluginv2.RunStreamReque
|
|||||||
func (r *protoClient) PublishStream(ctx context.Context, in *pluginv2.PublishStreamRequest, opts ...grpc.CallOption) (*pluginv2.PublishStreamResponse, error) {
|
func (r *protoClient) PublishStream(ctx context.Context, in *pluginv2.PublishStreamRequest, opts ...grpc.CallOption) (*pluginv2.PublishStreamResponse, error) {
|
||||||
c, exists := r.client(ctx)
|
c, exists := r.client(ctx)
|
||||||
if !exists {
|
if !exists {
|
||||||
return nil, errClientNotAvailable
|
return nil, errClientNotStarted
|
||||||
}
|
}
|
||||||
return c.StreamClient.PublishStream(ctx, in, opts...)
|
return c.StreamClient.PublishStream(ctx, in, opts...)
|
||||||
}
|
}
|
||||||
@ -220,7 +190,7 @@ func (r *protoClient) PublishStream(ctx context.Context, in *pluginv2.PublishStr
|
|||||||
func (r *protoClient) ValidateAdmission(ctx context.Context, in *pluginv2.AdmissionRequest, opts ...grpc.CallOption) (*pluginv2.ValidationResponse, error) {
|
func (r *protoClient) ValidateAdmission(ctx context.Context, in *pluginv2.AdmissionRequest, opts ...grpc.CallOption) (*pluginv2.ValidationResponse, error) {
|
||||||
c, exists := r.client(ctx)
|
c, exists := r.client(ctx)
|
||||||
if !exists {
|
if !exists {
|
||||||
return nil, errClientNotAvailable
|
return nil, errClientNotStarted
|
||||||
}
|
}
|
||||||
return c.AdmissionClient.ValidateAdmission(ctx, in, opts...)
|
return c.AdmissionClient.ValidateAdmission(ctx, in, opts...)
|
||||||
}
|
}
|
||||||
@ -228,7 +198,7 @@ func (r *protoClient) ValidateAdmission(ctx context.Context, in *pluginv2.Admiss
|
|||||||
func (r *protoClient) MutateAdmission(ctx context.Context, in *pluginv2.AdmissionRequest, opts ...grpc.CallOption) (*pluginv2.MutationResponse, error) {
|
func (r *protoClient) MutateAdmission(ctx context.Context, in *pluginv2.AdmissionRequest, opts ...grpc.CallOption) (*pluginv2.MutationResponse, error) {
|
||||||
c, exists := r.client(ctx)
|
c, exists := r.client(ctx)
|
||||||
if !exists {
|
if !exists {
|
||||||
return nil, errClientNotAvailable
|
return nil, errClientNotStarted
|
||||||
}
|
}
|
||||||
return c.AdmissionClient.MutateAdmission(ctx, in, opts...)
|
return c.AdmissionClient.MutateAdmission(ctx, in, opts...)
|
||||||
}
|
}
|
||||||
@ -236,7 +206,7 @@ func (r *protoClient) MutateAdmission(ctx context.Context, in *pluginv2.Admissio
|
|||||||
func (r *protoClient) ConvertObjects(ctx context.Context, in *pluginv2.ConversionRequest, opts ...grpc.CallOption) (*pluginv2.ConversionResponse, error) {
|
func (r *protoClient) ConvertObjects(ctx context.Context, in *pluginv2.ConversionRequest, opts ...grpc.CallOption) (*pluginv2.ConversionResponse, error) {
|
||||||
c, exists := r.client(ctx)
|
c, exists := r.client(ctx)
|
||||||
if !exists {
|
if !exists {
|
||||||
return nil, errClientNotAvailable
|
return nil, errClientNotStarted
|
||||||
}
|
}
|
||||||
return c.ConversionClient.ConvertObjects(ctx, in, opts...)
|
return c.ConversionClient.ConvertObjects(ctx, in, opts...)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user