Compare commits

...
3 changed files with 35 additions and 15 deletions
+15 -2
View File
@@ -168,8 +168,21 @@ func (s *gPRCServerService) Run(ctx context.Context) error {
return err
case <-ctx.Done():
}
s.logger.Warn("GRPC server: shutting down")
s.server.Stop()
s.logger.Warn("GRPC server: initiating graceful shutdown")
gracefulStopDone := make(chan struct{})
go func() {
s.server.GracefulStop()
close(gracefulStopDone)
}()
select {
case <-gracefulStopDone:
s.logger.Info("GRPC server: graceful shutdown complete")
case <-time.After(s.cfg.GracefulShutdownTimeout):
s.logger.Warn("GRPC server: graceful shutdown timed out, forcing stop")
s.server.Stop()
}
return ctx.Err()
}
+10 -7
View File
@@ -13,13 +13,14 @@ import (
)
type GRPCServerSettings struct {
Enabled bool
Network string
Address string // with flags, call Process to fill this field defaults
TLSConfig *tls.Config // with flags, call Process to fill this field
EnableLogging bool // log request and response of each unary gRPC call
MaxRecvMsgSize int
MaxSendMsgSize int
Enabled bool
Network string
Address string // with flags, call Process to fill this field defaults
TLSConfig *tls.Config // with flags, call Process to fill this field
EnableLogging bool // log request and response of each unary gRPC call
MaxRecvMsgSize int
MaxSendMsgSize int
GracefulShutdownTimeout time.Duration
MaxConnectionAge time.Duration
MaxConnectionAgeGrace time.Duration
@@ -125,6 +126,7 @@ func readGRPCServerSettings(cfg *Cfg, iniFile *ini.File) error {
cfg.GRPCServer.EnableLogging = server.Key("enable_logging").MustBool(false)
cfg.GRPCServer.MaxRecvMsgSize = server.Key("max_recv_msg_size").MustInt(0)
cfg.GRPCServer.MaxSendMsgSize = server.Key("max_send_msg_size").MustInt(0)
cfg.GRPCServer.GracefulShutdownTimeout = server.Key("graceful_shutdown_timeout").MustDuration(10 * time.Second)
// Read connection management options from INI file
cfg.GRPCServer.MaxConnectionAge = server.Key("max_connection_age").MustDuration(0)
@@ -144,6 +146,7 @@ func (c *GRPCServerSettings) AddFlags(fs *pflag.FlagSet) {
fs.BoolVar(&c.EnableLogging, "grpc-server-enable-logging", false, "Enable logging of gRPC requests and responses")
fs.IntVar(&c.MaxRecvMsgSize, "grpc-server-max-recv-msg-size", 0, "Maximum size of a gRPC request message in bytes")
fs.IntVar(&c.MaxSendMsgSize, "grpc-server-max-send-msg-size", 0, "Maximum size of a gRPC response message in bytes")
fs.DurationVar(&c.GracefulShutdownTimeout, "grpc-server-graceful-shutdown-timeout", 10*time.Second, "Duration to wait for graceful gRPC server shutdown")
// Internal flags, we need to call ProcessTLSConfig
fs.BoolVar(&c.useTLS, "grpc-server-use-tls", false, "Enable TLS for the gRPC server")
+10 -6
View File
@@ -1,6 +1,9 @@
import { isEmpty } from 'lodash';
import { BASE_URL as v0alphaBaseURL } from '@grafana/api-clients/rtkq/dashboard/v0alpha1';
import {
API_GROUP as DASHBOARD_API_GROUP,
BASE_URL as v0alphaBaseURL,
} from '@grafana/api-clients/rtkq/dashboard/v0alpha1';
import { generatedAPI as legacyUserAPI } from '@grafana/api-clients/rtkq/legacy/user';
import { DataFrame, DataFrameView, getDisplayProcessor, SelectableValue, toDataFrame } from '@grafana/data';
import { t } from '@grafana/i18n';
@@ -85,10 +88,11 @@ export class UnifiedSearcher implements GrafanaSearcher {
fieldSelector: `metadata.name=${name}`,
})
);
starsIds =
result.data.items?.[0].spec.resource.find(
(info) => info.group === 'dashboard.grafana.app' && info.kind === 'Dashboard'
)?.names || [];
const items = result.data.items;
starsIds = items?.length
? items[0].spec.resource.find(({ group, kind }) => group === DASHBOARD_API_GROUP && kind === 'Dashboard')
?.names || []
: [];
} else {
starsIds = await dispatch(legacyUserAPI.endpoints.getStars.initiate()).unwrap();
}
@@ -331,7 +335,7 @@ export class UnifiedSearcher implements GrafanaSearcher {
}
if (query.deleted) {
uri = `${getAPIBaseURL('dashboard.grafana.app', 'v1beta1')}/dashboards/?labelSelector=grafana.app/get-trash=true`;
uri = `${getAPIBaseURL(DASHBOARD_API_GROUP, 'v1beta1')}/dashboards/?labelSelector=grafana.app/get-trash=true`;
}
return uri;
}