Merge pull request #8093 from mxpv/instrument
Extract CRI instrument into separate package
This commit is contained in:
		| @@ -14,7 +14,7 @@ | ||||
|    limitations under the License. | ||||
| */ | ||||
| 
 | ||||
| package sbserver | ||||
| package instrument | ||||
| 
 | ||||
| import ( | ||||
| 	"context" | ||||
| @@ -29,23 +29,49 @@ import ( | ||||
| 	ctrdutil "github.com/containerd/containerd/pkg/cri/util" | ||||
| ) | ||||
| 
 | ||||
| // instrumentedService wraps service with containerd namespace and logs. | ||||
| type instrumentedService struct { | ||||
| 	c *criService | ||||
| const ( | ||||
| 	// criSpanPrefix is a prefix for CRI server specific spans | ||||
| 	criSpanPrefix = "pkg.cri.server" | ||||
| ) | ||||
| 
 | ||||
| // criService is an CRI server dependency to be wrapped with instrumentation. | ||||
| type criService interface { | ||||
| 	GRPCServices | ||||
| 
 | ||||
| 	IsInitialized() bool | ||||
| 
 | ||||
| 	// AlphaVersion returns the runtime name, runtime version and runtime API version. | ||||
| 	AlphaVersion(ctx context.Context, r *runtime_alpha.VersionRequest) (*runtime_alpha.VersionResponse, error) | ||||
| } | ||||
| 
 | ||||
| func newInstrumentedService(c *criService) grpcServices { | ||||
| // GRPCServices are all the grpc services provided by cri containerd. | ||||
| type GRPCServices interface { | ||||
| 	runtime.RuntimeServiceServer | ||||
| 	runtime.ImageServiceServer | ||||
| } | ||||
| 
 | ||||
| type GRPCAlphaServices interface { | ||||
| 	runtime_alpha.RuntimeServiceServer | ||||
| 	runtime_alpha.ImageServiceServer | ||||
| } | ||||
| 
 | ||||
| // instrumentedService wraps service with containerd namespace and logs. | ||||
| type instrumentedService struct { | ||||
| 	c criService | ||||
| } | ||||
| 
 | ||||
| func NewService(c criService) GRPCServices { | ||||
| 	return &instrumentedService{c: c} | ||||
| } | ||||
| 
 | ||||
| // instrumentedAlphaService wraps service with containerd namespace and logs. | ||||
| type instrumentedAlphaService struct { | ||||
| 	c *criService | ||||
| 	c criService | ||||
| 	runtime_alpha.UnimplementedRuntimeServiceServer | ||||
| 	runtime_alpha.UnimplementedImageServiceServer | ||||
| } | ||||
| 
 | ||||
| func newInstrumentedAlphaService(c *criService) grpcAlphaServices { | ||||
| func NewAlphaService(c criService) GRPCAlphaServices { | ||||
| 	return &instrumentedAlphaService{c: c} | ||||
| } | ||||
| 
 | ||||
| @@ -54,7 +80,7 @@ func newInstrumentedAlphaService(c *criService) grpcAlphaServices { | ||||
| // initialized. | ||||
| // NOTE(random-liu): All following functions MUST check initialized at the beginning. | ||||
| func (in *instrumentedService) checkInitialized() error { | ||||
| 	if in.c.initialized.IsSet() { | ||||
| 	if in.c.IsInitialized() { | ||||
| 		return nil | ||||
| 	} | ||||
| 	return errors.New("server is not initialized yet") | ||||
| @@ -65,7 +91,7 @@ func (in *instrumentedService) checkInitialized() error { | ||||
| // initialized. | ||||
| // NOTE(random-liu): All following functions MUST check initialized at the beginning. | ||||
| func (in *instrumentedAlphaService) checkInitialized() error { | ||||
| 	if in.c.initialized.IsSet() { | ||||
| 	if in.c.IsInitialized() { | ||||
| 		return nil | ||||
| 	} | ||||
| 	return errors.New("server is not initialized yet") | ||||
| @@ -98,9 +98,6 @@ const ( | ||||
|  | ||||
| 	// runtimeRunhcsV1 is the runtime type for runhcs. | ||||
| 	runtimeRunhcsV1 = "io.containerd.runhcs.v1" | ||||
|  | ||||
| 	// name prefix for CRI sbserver specific spans | ||||
| 	criSpanPrefix = "pkg.cri.sbserver" | ||||
| ) | ||||
|  | ||||
| // makeSandboxName generates sandbox name from sandbox metadata. The name | ||||
|   | ||||
| @@ -29,6 +29,7 @@ import ( | ||||
|  | ||||
| 	"github.com/containerd/containerd" | ||||
| 	"github.com/containerd/containerd/oci" | ||||
| 	"github.com/containerd/containerd/pkg/cri/instrument" | ||||
| 	"github.com/containerd/containerd/pkg/cri/sbserver/podsandbox" | ||||
| 	"github.com/containerd/containerd/pkg/cri/streaming" | ||||
| 	"github.com/containerd/containerd/pkg/kmutex" | ||||
| @@ -56,24 +57,16 @@ import ( | ||||
| // defaultNetworkPlugin is used for the default CNI configuration | ||||
| const defaultNetworkPlugin = "default" | ||||
|  | ||||
| // grpcServices are all the grpc services provided by cri containerd. | ||||
| type grpcServices interface { | ||||
| 	runtime.RuntimeServiceServer | ||||
| 	runtime.ImageServiceServer | ||||
| } | ||||
|  | ||||
| type grpcAlphaServices interface { | ||||
| 	runtime_alpha.RuntimeServiceServer | ||||
| 	runtime_alpha.ImageServiceServer | ||||
| } | ||||
|  | ||||
| // CRIService is the interface implement CRI remote service server. | ||||
| type CRIService interface { | ||||
| 	Run() error | ||||
| 	// io.Closer is used by containerd to gracefully stop cri service. | ||||
| 	runtime.RuntimeServiceServer | ||||
| 	runtime.ImageServiceServer | ||||
| 	// Closer is used by containerd to gracefully stop cri service. | ||||
| 	io.Closer | ||||
|  | ||||
| 	Run() error | ||||
|  | ||||
| 	Register(*grpc.Server) error | ||||
| 	grpcServices | ||||
| } | ||||
|  | ||||
| // criService implements CRIService. | ||||
| @@ -329,13 +322,20 @@ func (c *criService) Close() error { | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // IsInitialized indicates whether CRI service has finished initialization. | ||||
| func (c *criService) IsInitialized() bool { | ||||
| 	return c.initialized.IsSet() | ||||
| } | ||||
|  | ||||
| func (c *criService) register(s *grpc.Server) error { | ||||
| 	instrumented := newInstrumentedService(c) | ||||
| 	instrumented := instrument.NewService(c) | ||||
| 	runtime.RegisterRuntimeServiceServer(s, instrumented) | ||||
| 	runtime.RegisterImageServiceServer(s, instrumented) | ||||
| 	instrumentedAlpha := newInstrumentedAlphaService(c) | ||||
|  | ||||
| 	instrumentedAlpha := instrument.NewAlphaService(c) | ||||
| 	runtime_alpha.RegisterRuntimeServiceServer(s, instrumentedAlpha) | ||||
| 	runtime_alpha.RegisterImageServiceServer(s, instrumentedAlpha) | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -94,9 +94,6 @@ const ( | ||||
|  | ||||
| 	// runtimeRunhcsV1 is the runtime type for runhcs. | ||||
| 	runtimeRunhcsV1 = "io.containerd.runhcs.v1" | ||||
|  | ||||
| 	// name prefix for CRI server specific spans | ||||
| 	criSpanPrefix = "pkg.cri.server" | ||||
| ) | ||||
|  | ||||
| // makeSandboxName generates sandbox name from sandbox metadata. The name | ||||
|   | ||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -28,6 +28,7 @@ import ( | ||||
|  | ||||
| 	"github.com/containerd/containerd" | ||||
| 	"github.com/containerd/containerd/oci" | ||||
| 	"github.com/containerd/containerd/pkg/cri/instrument" | ||||
| 	"github.com/containerd/containerd/pkg/cri/streaming" | ||||
| 	"github.com/containerd/containerd/pkg/kmutex" | ||||
| 	"github.com/containerd/containerd/pkg/nri" | ||||
| @@ -54,25 +55,16 @@ import ( | ||||
| // defaultNetworkPlugin is used for the default CNI configuration | ||||
| const defaultNetworkPlugin = "default" | ||||
|  | ||||
| // grpcServices are all the grpc services provided by cri containerd. | ||||
| type grpcServices interface { | ||||
| 	runtime.RuntimeServiceServer | ||||
| 	runtime.ImageServiceServer | ||||
| } | ||||
|  | ||||
| type grpcAlphaServices interface { | ||||
| 	runtime_alpha.RuntimeServiceServer | ||||
| 	runtime_alpha.ImageServiceServer | ||||
| } | ||||
|  | ||||
| // CRIService is the interface implement CRI remote service server. | ||||
| type CRIService interface { | ||||
| 	runtime.RuntimeServiceServer | ||||
| 	runtime.ImageServiceServer | ||||
| 	// Closer is used by containerd to gracefully stop cri service. | ||||
| 	io.Closer | ||||
|  | ||||
| 	Run() error | ||||
|  | ||||
| 	// io.Closer is used by containerd to gracefully stop cri service. | ||||
| 	io.Closer | ||||
| 	Register(*grpc.Server) error | ||||
| 	grpcServices | ||||
| } | ||||
|  | ||||
| // criService implements CRIService. | ||||
| @@ -319,13 +311,20 @@ func (c *criService) Close() error { | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // IsInitialized indicates whether CRI service has finished initialization. | ||||
| func (c *criService) IsInitialized() bool { | ||||
| 	return c.initialized.IsSet() | ||||
| } | ||||
|  | ||||
| func (c *criService) register(s *grpc.Server) error { | ||||
| 	instrumented := newInstrumentedService(c) | ||||
| 	instrumented := instrument.NewService(c) | ||||
| 	runtime.RegisterRuntimeServiceServer(s, instrumented) | ||||
| 	runtime.RegisterImageServiceServer(s, instrumented) | ||||
| 	instrumentedAlpha := newInstrumentedAlphaService(c) | ||||
|  | ||||
| 	instrumentedAlpha := instrument.NewAlphaService(c) | ||||
| 	runtime_alpha.RegisterRuntimeServiceServer(s, instrumentedAlpha) | ||||
| 	runtime_alpha.RegisterImageServiceServer(s, instrumentedAlpha) | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Derek McGowan
					Derek McGowan