admin.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. *
  3. * Copyright 2021 gRPC authors.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. // Package admin provides a convenient method for registering a collection of
  19. // administration services to a gRPC server. The services registered are:
  20. //
  21. // - Channelz: https://github.com/grpc/proposal/blob/master/A14-channelz.md
  22. //
  23. // - CSDS: https://github.com/grpc/proposal/blob/master/A40-csds-support.md
  24. //
  25. // # Experimental
  26. //
  27. // Notice: All APIs in this package are experimental and may be removed in a
  28. // later release.
  29. package admin
  30. import (
  31. "google.golang.org/grpc"
  32. channelzservice "google.golang.org/grpc/channelz/service"
  33. internaladmin "google.golang.org/grpc/internal/admin"
  34. )
  35. func init() {
  36. // Add a list of default services to admin here. Optional services, like
  37. // CSDS, will be added by other packages.
  38. internaladmin.AddService(func(registrar grpc.ServiceRegistrar) (func(), error) {
  39. channelzservice.RegisterChannelzServiceToServer(registrar)
  40. return nil, nil
  41. })
  42. }
  43. // Register registers the set of admin services to the given server.
  44. //
  45. // The returned cleanup function should be called to clean up the resources
  46. // allocated for the service handlers after the server is stopped.
  47. //
  48. // Note that if `s` is not a *grpc.Server or a *xds.GRPCServer, CSDS will not be
  49. // registered because CSDS generated code is old and doesn't support interface
  50. // `grpc.ServiceRegistrar`.
  51. // https://github.com/envoyproxy/go-control-plane/issues/403
  52. func Register(s grpc.ServiceRegistrar) (cleanup func(), _ error) {
  53. return internaladmin.Register(s)
  54. }