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 (
|
||||
errClientNotAvailable = errors.New("plugin client is not available")
|
||||
errClientNotStarted = errors.New("plugin client has not been started")
|
||||
)
|
||||
|
||||
var _ ProtoClient = (*protoClient)(nil)
|
||||
@ -36,6 +36,7 @@ type ProtoClient interface {
|
||||
Logger() log.Logger
|
||||
Start(context.Context) error
|
||||
Stop(context.Context) error
|
||||
Running(context.Context) bool
|
||||
}
|
||||
|
||||
type protoClient struct {
|
||||
@ -43,20 +44,9 @@ type protoClient struct {
|
||||
pluginVersion string
|
||||
pluginJSON plugins.JSONData
|
||||
|
||||
state pluginState
|
||||
|
||||
mu sync.RWMutex
|
||||
}
|
||||
|
||||
type pluginState int
|
||||
|
||||
const (
|
||||
pluginStateNotStarted pluginState = iota
|
||||
pluginStateStartSuccess
|
||||
pluginStateStartFail
|
||||
pluginStateStopped
|
||||
)
|
||||
|
||||
type ProtoClientOpts struct {
|
||||
PluginJSON plugins.JSONData
|
||||
ExecutablePath string
|
||||
@ -78,12 +68,12 @@ func NewProtoClient(opts ProtoClientOpts) (ProtoClient, error) {
|
||||
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) {
|
||||
if _, exists := r.client(ctx); !exists {
|
||||
return "", errClientNotAvailable
|
||||
return "", errClientNotStarted
|
||||
}
|
||||
return r.plugin.client.ID(), nil
|
||||
}
|
||||
@ -111,60 +101,40 @@ func (r *protoClient) Logger() log.Logger {
|
||||
func (r *protoClient) Start(ctx context.Context) error {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
|
||||
err := r.plugin.Start(ctx)
|
||||
if err != nil {
|
||||
r.state = pluginStateStartFail
|
||||
return err
|
||||
}
|
||||
|
||||
r.state = pluginStateStartSuccess
|
||||
return nil
|
||||
return r.plugin.Start(ctx)
|
||||
}
|
||||
|
||||
func (r *protoClient) Stop(ctx context.Context) error {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
r.state = pluginStateStopped
|
||||
return r.plugin.Stop(ctx)
|
||||
}
|
||||
|
||||
func (r *protoClient) client(ctx context.Context) (*ClientV2, bool) {
|
||||
func (r *protoClient) Running(_ context.Context) bool {
|
||||
r.mu.RLock()
|
||||
defer r.mu.RUnlock()
|
||||
return !r.plugin.Exited()
|
||||
}
|
||||
|
||||
logger := r.Logger().FromContext(ctx)
|
||||
if r.state == pluginStateNotStarted {
|
||||
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")
|
||||
func (r *protoClient) client(ctx context.Context) (*ClientV2, bool) {
|
||||
if !r.Running(ctx) {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
r.mu.RLock()
|
||||
if r.plugin.pluginClient == nil {
|
||||
r.mu.RUnlock()
|
||||
return nil, false
|
||||
}
|
||||
pc := r.plugin.pluginClient
|
||||
r.mu.RUnlock()
|
||||
return pc, true
|
||||
}
|
||||
|
||||
func (r *protoClient) QueryData(ctx context.Context, in *pluginv2.QueryDataRequest, opts ...grpc.CallOption) (*pluginv2.QueryDataResponse, error) {
|
||||
c, exists := r.client(ctx)
|
||||
if !exists {
|
||||
return nil, errClientNotAvailable
|
||||
return nil, errClientNotStarted
|
||||
}
|
||||
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) {
|
||||
c, exists := r.client(ctx)
|
||||
if !exists {
|
||||
return nil, errClientNotAvailable
|
||||
return nil, errClientNotStarted
|
||||
}
|
||||
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) {
|
||||
c, exists := r.client(ctx)
|
||||
if !exists {
|
||||
return nil, errClientNotAvailable
|
||||
return nil, errClientNotStarted
|
||||
}
|
||||
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) {
|
||||
c, exists := r.client(ctx)
|
||||
if !exists {
|
||||
return nil, errClientNotAvailable
|
||||
return nil, errClientNotStarted
|
||||
}
|
||||
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) {
|
||||
c, exists := r.client(ctx)
|
||||
if !exists {
|
||||
return nil, errClientNotAvailable
|
||||
return nil, errClientNotStarted
|
||||
}
|
||||
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) {
|
||||
c, exists := r.client(ctx)
|
||||
if !exists {
|
||||
return nil, errClientNotAvailable
|
||||
return nil, errClientNotStarted
|
||||
}
|
||||
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) {
|
||||
c, exists := r.client(ctx)
|
||||
if !exists {
|
||||
return nil, errClientNotAvailable
|
||||
return nil, errClientNotStarted
|
||||
}
|
||||
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) {
|
||||
c, exists := r.client(ctx)
|
||||
if !exists {
|
||||
return nil, errClientNotAvailable
|
||||
return nil, errClientNotStarted
|
||||
}
|
||||
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) {
|
||||
c, exists := r.client(ctx)
|
||||
if !exists {
|
||||
return nil, errClientNotAvailable
|
||||
return nil, errClientNotStarted
|
||||
}
|
||||
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) {
|
||||
c, exists := r.client(ctx)
|
||||
if !exists {
|
||||
return nil, errClientNotAvailable
|
||||
return nil, errClientNotStarted
|
||||
}
|
||||
return c.ConversionClient.ConvertObjects(ctx, in, opts...)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user