Merge branch 'V3.7' of https://github.com/goodrain/rainbond into V3.7

This commit is contained in:
zhoujunhao 2018-07-04 15:49:44 +08:00
commit 969f5218b1
7 changed files with 122 additions and 46 deletions

View File

@ -19,7 +19,6 @@
package cache
import (
"context"
"fmt"
"os"
"sync"
@ -27,9 +26,9 @@ import (
"github.com/Sirupsen/logrus"
status "github.com/goodrain/rainbond/appruntimesync/client"
"github.com/goodrain/rainbond/db"
"github.com/goodrain/rainbond/db/model"
"golang.org/x/net/context"
"github.com/goodrain/rainbond/util"
)
@ -40,16 +39,14 @@ type DiskCache struct {
Value float64
}
dbmanager db.Manager
statusManager *status.AppRuntimeSyncClient
ctx context.Context
lock sync.Mutex
}
//CreatDiskCache 创建
func CreatDiskCache(ctx context.Context, statusManager *status.AppRuntimeSyncClient) *DiskCache {
func CreatDiskCache(ctx context.Context) *DiskCache {
return &DiskCache{
dbmanager: db.GetManager(),
statusManager: statusManager,
ctx: ctx,
}
}

View File

@ -161,6 +161,19 @@ func (a *AppRuntimeSyncClient) GetStatus(serviceID string) string {
return status.Status[serviceID]
}
//GetAllStatus get all status
func (a *AppRuntimeSyncClient) GetAppDisk() map[string]float64 {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
status, err := a.AppRuntimeSyncClient.GetAppDisk(ctx, &pb.StatusRequest{
ServiceIds: "",
})
if err != nil {
return nil
}
return status.Disks
}
//GetStatuss get multiple app status
func (a *AppRuntimeSyncClient) GetStatuss(serviceIDs string) map[string]string {
ctx, cancel := context.WithCancel(context.Background())

View File

@ -5,13 +5,14 @@
Package pb is a generated protocol buffer package.
It is generated from these files:
app_runtime_sync.proto
app_runtime_sync.proto
It has these top-level messages:
Ignore
StatusRequest
StatusMessage
ErrorMessage
Ignore
StatusRequest
StatusMessage
DiskMessage
ErrorMessage
*/
package pb
@ -83,6 +84,22 @@ func (m *StatusMessage) GetStatus() map[string]string {
return nil
}
type DiskMessage struct {
Disks map[string]float64 `protobuf:"bytes,1,rep,name=disks" json:"disks,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"fixed64,2,opt,name=value"`
}
func (m *DiskMessage) Reset() { *m = DiskMessage{} }
func (m *DiskMessage) String() string { return proto.CompactTextString(m) }
func (*DiskMessage) ProtoMessage() {}
func (*DiskMessage) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} }
func (m *DiskMessage) GetDisks() map[string]float64 {
if m != nil {
return m.Disks
}
return nil
}
type ErrorMessage struct {
Message string `protobuf:"bytes,1,opt,name=message" json:"message,omitempty"`
}
@ -90,7 +107,7 @@ type ErrorMessage struct {
func (m *ErrorMessage) Reset() { *m = ErrorMessage{} }
func (m *ErrorMessage) String() string { return proto.CompactTextString(m) }
func (*ErrorMessage) ProtoMessage() {}
func (*ErrorMessage) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} }
func (*ErrorMessage) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{4} }
func (m *ErrorMessage) GetMessage() string {
if m != nil {
@ -103,6 +120,7 @@ func init() {
proto.RegisterType((*Ignore)(nil), "pb.Ignore")
proto.RegisterType((*StatusRequest)(nil), "pb.StatusRequest")
proto.RegisterType((*StatusMessage)(nil), "pb.StatusMessage")
proto.RegisterType((*DiskMessage)(nil), "pb.DiskMessage")
proto.RegisterType((*ErrorMessage)(nil), "pb.ErrorMessage")
}
@ -118,6 +136,7 @@ const _ = grpc.SupportPackageIsVersion4
type AppRuntimeSyncClient interface {
GetAppStatus(ctx context.Context, in *StatusRequest, opts ...grpc.CallOption) (*StatusMessage, error)
GetAppDisk(ctx context.Context, in *StatusRequest, opts ...grpc.CallOption) (*DiskMessage, error)
SetAppStatus(ctx context.Context, in *StatusMessage, opts ...grpc.CallOption) (*ErrorMessage, error)
CheckAppStatus(ctx context.Context, in *StatusRequest, opts ...grpc.CallOption) (*ErrorMessage, error)
IgnoreDeleteEvent(ctx context.Context, in *Ignore, opts ...grpc.CallOption) (*ErrorMessage, error)
@ -141,6 +160,15 @@ func (c *appRuntimeSyncClient) GetAppStatus(ctx context.Context, in *StatusReque
return out, nil
}
func (c *appRuntimeSyncClient) GetAppDisk(ctx context.Context, in *StatusRequest, opts ...grpc.CallOption) (*DiskMessage, error) {
out := new(DiskMessage)
err := grpc.Invoke(ctx, "/pb.AppRuntimeSync/GetAppDisk", in, out, c.cc, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *appRuntimeSyncClient) SetAppStatus(ctx context.Context, in *StatusMessage, opts ...grpc.CallOption) (*ErrorMessage, error) {
out := new(ErrorMessage)
err := grpc.Invoke(ctx, "/pb.AppRuntimeSync/SetAppStatus", in, out, c.cc, opts...)
@ -181,6 +209,7 @@ func (c *appRuntimeSyncClient) RmIgnoreDeleteEvent(ctx context.Context, in *Igno
type AppRuntimeSyncServer interface {
GetAppStatus(context.Context, *StatusRequest) (*StatusMessage, error)
GetAppDisk(context.Context, *StatusRequest) (*DiskMessage, error)
SetAppStatus(context.Context, *StatusMessage) (*ErrorMessage, error)
CheckAppStatus(context.Context, *StatusRequest) (*ErrorMessage, error)
IgnoreDeleteEvent(context.Context, *Ignore) (*ErrorMessage, error)
@ -209,6 +238,24 @@ func _AppRuntimeSync_GetAppStatus_Handler(srv interface{}, ctx context.Context,
return interceptor(ctx, in, info, handler)
}
func _AppRuntimeSync_GetAppDisk_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(StatusRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(AppRuntimeSyncServer).GetAppDisk(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/pb.AppRuntimeSync/GetAppDisk",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(AppRuntimeSyncServer).GetAppDisk(ctx, req.(*StatusRequest))
}
return interceptor(ctx, in, info, handler)
}
func _AppRuntimeSync_SetAppStatus_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(StatusMessage)
if err := dec(in); err != nil {
@ -289,6 +336,10 @@ var _AppRuntimeSync_serviceDesc = grpc.ServiceDesc{
MethodName: "GetAppStatus",
Handler: _AppRuntimeSync_GetAppStatus_Handler,
},
{
MethodName: "GetAppDisk",
Handler: _AppRuntimeSync_GetAppDisk_Handler,
},
{
MethodName: "SetAppStatus",
Handler: _AppRuntimeSync_SetAppStatus_Handler,
@ -313,25 +364,28 @@ var _AppRuntimeSync_serviceDesc = grpc.ServiceDesc{
func init() { proto.RegisterFile("app_runtime_sync.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{
// 314 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x92, 0xcf, 0x4e, 0xc2, 0x40,
0x10, 0x87, 0x69, 0x51, 0x8c, 0x03, 0x12, 0x18, 0x8d, 0x69, 0x88, 0x46, 0xb2, 0x27, 0x4e, 0xc4,
0x40, 0xf0, 0xdf, 0x8d, 0x28, 0x31, 0x1c, 0xbc, 0x94, 0x07, 0x20, 0xa5, 0x4c, 0x90, 0x40, 0xb7,
0xeb, 0xee, 0xb6, 0x49, 0x8f, 0xbe, 0x8b, 0x0f, 0x6a, 0xda, 0xdd, 0x46, 0x8c, 0x68, 0xe2, 0x6d,
0xe6, 0xcb, 0xef, 0xcb, 0x4c, 0xa7, 0x0b, 0xe7, 0x81, 0x10, 0x73, 0x99, 0x70, 0xbd, 0x8e, 0x68,
0xae, 0x32, 0x1e, 0xf6, 0x85, 0x8c, 0x75, 0x8c, 0xae, 0x58, 0xb0, 0x0b, 0xa8, 0x4d, 0x57, 0x3c,
0x96, 0x84, 0x08, 0x07, 0x3c, 0x88, 0xc8, 0x73, 0xba, 0x4e, 0xef, 0xd8, 0x2f, 0x6a, 0x76, 0x0d,
0x27, 0x33, 0x1d, 0xe8, 0x44, 0xf9, 0xf4, 0x96, 0x90, 0xd2, 0x78, 0x05, 0x75, 0x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 0x02, 0x00, 0x00,
}
// 361 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x92, 0xc1, 0x4e, 0xc2, 0x40,
0x10, 0x86, 0x69, 0x11, 0x8c, 0x53, 0x44, 0x58, 0x8d, 0x69, 0x1a, 0x8d, 0xa4, 0x27, 0x4e, 0x84,
0x40, 0x50, 0xf4, 0x46, 0x84, 0x18, 0x0e, 0x5e, 0xca, 0x03, 0x90, 0x52, 0x26, 0xd8, 0x94, 0xb6,
0xeb, 0xee, 0x96, 0xa4, 0x47, 0xdf, 0xd2, 0xc7, 0x31, 0xed, 0x6e, 0x43, 0x55, 0xd4, 0x78, 0x9b,
0xf9, 0xfb, 0xff, 0xf9, 0x66, 0xa6, 0x0b, 0x97, 0x2e, 0xa5, 0x4b, 0x96, 0x44, 0xc2, 0x0f, 0x71,
0xc9, 0xd3, 0xc8, 0xeb, 0x51, 0x16, 0x8b, 0x98, 0xe8, 0x74, 0x65, 0x5f, 0x41, 0x7d, 0xbe, 0x89,
0x62, 0x86, 0x84, 0xc0, 0x51, 0xe4, 0x86, 0x68, 0x6a, 0x1d, 0xad, 0x7b, 0xe2, 0xe4, 0xb5, 0xdd,
0x87, 0xd3, 0x85, 0x70, 0x45, 0xc2, 0x1d, 0x7c, 0x4d, 0x90, 0x0b, 0x72, 0x03, 0x06, 0x47, 0xb6,
0xf3, 0x3d, 0x5c, 0xfa, 0x6b, 0xae, 0xbc, 0xa0, 0xa4, 0xf9, 0x9a, 0xdb, 0x6f, 0x5a, 0x11, 0x79,
0x46, 0xce, 0xdd, 0x0d, 0x92, 0x11, 0xd4, 0x79, 0x2e, 0x98, 0x5a, 0xa7, 0xda, 0x35, 0x06, 0xd7,
0x3d, 0xba, 0xea, 0x7d, 0xb2, 0xa8, 0x6e, 0x16, 0x09, 0x96, 0x3a, 0xca, 0x6c, 0xdd, 0x83, 0x51,
0x92, 0x49, 0x0b, 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 -3,10 +3,11 @@ package pb;
service AppRuntimeSync {
rpc GetAppStatus (StatusRequest) returns (StatusMessage) {}
rpc GetAppDisk (StatusRequest) returns (DiskMessage) {}
rpc SetAppStatus (StatusMessage) returns (ErrorMessage) {}
rpc CheckAppStatus (StatusRequest) returns (ErrorMessage) {}
rpc IgnoreDeleteEvent (Ignore) returns (ErrorMessage) {}
rpc RmIgnoreDeleteEvent (Ignore) returns (ErrorMessage) {}
rpc IgnoreDeleteEvent (Ignore) returns (ErrorMessage) {}
rpc RmIgnoreDeleteEvent (Ignore) returns (ErrorMessage) {}
}
message Ignore {
@ -21,6 +22,10 @@ message StatusMessage {
map<string, string> status = 1;
}
message DiskMessage {
map<string, double> disks = 1;
}
message ErrorMessage {
string message = 1;
}

View File

@ -32,6 +32,7 @@ import (
"golang.org/x/net/context"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
"github.com/goodrain/rainbond/appruntimesync/cache"
)
//AppRuntimeSyncServer AppRuntimeSyncServer
@ -44,6 +45,7 @@ type AppRuntimeSyncServer struct {
ClientSet *kubernetes.Clientset
podCache *pod.CacheManager
clean *clean.Manager
cache *cache.DiskCache
}
//NewAppRuntimeSyncServer create app runtime sync server
@ -68,6 +70,10 @@ func NewAppRuntimeSyncServer(conf option.Config) *AppRuntimeSyncServer {
if err != nil {
logrus.Error(err)
}
// disk used info collector
c := cache.CreatDiskCache(ctx)
arss := &AppRuntimeSyncServer{
c: conf,
Ctx: ctx,
@ -76,6 +82,7 @@ func NewAppRuntimeSyncServer(conf option.Config) *AppRuntimeSyncServer {
ClientSet: clientset,
podCache: podCache,
clean: Clean,
cache: c,
}
arss.StatusManager = statusManager
return arss
@ -100,6 +107,13 @@ func (a *AppRuntimeSyncServer) GetAppStatus(ctx context.Context, sr *pb.StatusRe
return &re, nil
}
//GetDiskStatus get app disk information
func (a *AppRuntimeSyncServer) GetAppDisk(ctx context.Context, sr *pb.StatusRequest) (*pb.DiskMessage, error) {
var re pb.DiskMessage
re.Disks = a.cache.Get()
return &re, nil
}
//SetAppStatus set app status
func (a *AppRuntimeSyncServer) SetAppStatus(ctx context.Context, ps *pb.StatusMessage) (*pb.ErrorMessage, error) {
if ps.Status != nil {
@ -147,6 +161,7 @@ func (a *AppRuntimeSyncServer) Start() error {
)
a.podCache.Start()
a.clean.Start()
go a.cache.Start()
logrus.Info("app runtime sync server started...")
return nil
}

View File

@ -24,7 +24,6 @@ import (
"time"
"github.com/goodrain/rainbond/db/model"
"github.com/goodrain/rainbond/worker/monitor/cache"
"github.com/Sirupsen/logrus"
status "github.com/goodrain/rainbond/appruntimesync/client"
@ -43,7 +42,6 @@ type Exporter struct {
workerUp prometheus.Gauge
dbmanager db.Manager
statusManager *status.AppRuntimeSyncClient
cache *cache.DiskCache
}
var scrapeDurationDesc = prometheus.NewDesc(
@ -113,7 +111,7 @@ func (e *Exporter) scrape(ch chan<- prometheus.Metric) {
}
ch <- prometheus.MustNewConstMetric(scrapeDurationDesc, prometheus.GaugeValue, time.Since(scrapeTime).Seconds(), "collect.memory")
scrapeTime = time.Now()
diskcache := e.cache.Get()
diskcache := e.statusManager.GetAppDisk()
for k, v := range diskcache {
key := strings.Split(k, "_")
if len(key) == 2 {
@ -126,7 +124,7 @@ func (e *Exporter) scrape(ch chan<- prometheus.Metric) {
var namespace = "app_resource"
//New 创建一个收集器
func New(statusManager *status.AppRuntimeSyncClient, cache *cache.DiskCache) *Exporter {
func New(statusManager *status.AppRuntimeSyncClient) *Exporter {
return &Exporter{
totalScrapes: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: namespace,
@ -163,6 +161,5 @@ func New(statusManager *status.AppRuntimeSyncClient, cache *cache.DiskCache) *Ex
}, []string{"tenant_id", "service_id", "volume_type"}),
dbmanager: db.GetManager(),
statusManager: statusManager,
cache: cache,
}
}

View File

@ -25,7 +25,6 @@ import (
"github.com/Sirupsen/logrus"
"github.com/goodrain/rainbond/cmd/worker/option"
status "github.com/goodrain/rainbond/appruntimesync/client"
"github.com/goodrain/rainbond/worker/monitor/cache"
"github.com/goodrain/rainbond/worker/monitor/collector"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
@ -39,25 +38,22 @@ type ExporterManager struct {
config option.Config
stopChan chan struct{}
statusManager *status.AppRuntimeSyncClient
cache *cache.DiskCache
}
//NewManager return *NewManager
func NewManager(c option.Config, statusManager *status.AppRuntimeSyncClient) *ExporterManager {
ctx, cancel := context.WithCancel(context.Background())
cache := cache.CreatDiskCache(ctx, statusManager)
return &ExporterManager{
ctx: ctx,
cancel: cancel,
config: c,
stopChan: make(chan struct{}),
statusManager: statusManager,
cache: cache,
}
}
func (t *ExporterManager) handler(w http.ResponseWriter, r *http.Request) {
registry := prometheus.NewRegistry()
registry.MustRegister(collector.New(t.statusManager, t.cache))
registry.MustRegister(collector.New(t.statusManager))
gatherers := prometheus.Gatherers{
prometheus.DefaultGatherer,
@ -81,7 +77,6 @@ func (t *ExporterManager) Start() error {
</html>
`))
})
go t.cache.Start()
log.Infoln("Listening on", t.config.Listen)
go func() {
log.Fatal(http.ListenAndServe(t.config.Listen, nil))