mirror of https://github.com/helm/helm
parent
0d16a01db7
commit
5a33d1f338
@ -0,0 +1,135 @@
|
||||
// Code generated by protoc-gen-go.
|
||||
// source: hapi/release/log.proto
|
||||
// DO NOT EDIT!
|
||||
|
||||
package release
|
||||
|
||||
import proto "github.com/golang/protobuf/proto"
|
||||
import fmt "fmt"
|
||||
import math "math"
|
||||
import google_protobuf "github.com/golang/protobuf/ptypes/timestamp"
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
var _ = fmt.Errorf
|
||||
var _ = math.Inf
|
||||
|
||||
// Allows filtering by log event source
|
||||
type Log_Source int32
|
||||
|
||||
const (
|
||||
Log_HOOK Log_Source = 0
|
||||
Log_TEST Log_Source = 1
|
||||
Log_POD Log_Source = 2
|
||||
Log_SYSTEM Log_Source = 3
|
||||
)
|
||||
|
||||
var Log_Source_name = map[int32]string{
|
||||
0: "HOOK",
|
||||
1: "TEST",
|
||||
2: "POD",
|
||||
3: "SYSTEM",
|
||||
}
|
||||
var Log_Source_value = map[string]int32{
|
||||
"HOOK": 0,
|
||||
"TEST": 1,
|
||||
"POD": 2,
|
||||
"SYSTEM": 3,
|
||||
}
|
||||
|
||||
func (x Log_Source) String() string {
|
||||
return proto.EnumName(Log_Source_name, int32(x))
|
||||
}
|
||||
func (Log_Source) EnumDescriptor() ([]byte, []int) { return fileDescriptor2, []int{0, 0} }
|
||||
|
||||
// Syslog log levels
|
||||
type Log_Level int32
|
||||
|
||||
const (
|
||||
Log_EMERG Log_Level = 0
|
||||
Log_ALERT Log_Level = 1
|
||||
Log_CRIT Log_Level = 2
|
||||
Log_ERR Log_Level = 3
|
||||
Log_WARNING Log_Level = 4
|
||||
Log_NOTICE Log_Level = 5
|
||||
Log_INFO Log_Level = 6
|
||||
Log_DEBUG Log_Level = 7
|
||||
)
|
||||
|
||||
var Log_Level_name = map[int32]string{
|
||||
0: "EMERG",
|
||||
1: "ALERT",
|
||||
2: "CRIT",
|
||||
3: "ERR",
|
||||
4: "WARNING",
|
||||
5: "NOTICE",
|
||||
6: "INFO",
|
||||
7: "DEBUG",
|
||||
}
|
||||
var Log_Level_value = map[string]int32{
|
||||
"EMERG": 0,
|
||||
"ALERT": 1,
|
||||
"CRIT": 2,
|
||||
"ERR": 3,
|
||||
"WARNING": 4,
|
||||
"NOTICE": 5,
|
||||
"INFO": 6,
|
||||
"DEBUG": 7,
|
||||
}
|
||||
|
||||
func (x Log_Level) String() string {
|
||||
return proto.EnumName(Log_Level_name, int32(x))
|
||||
}
|
||||
func (Log_Level) EnumDescriptor() ([]byte, []int) { return fileDescriptor2, []int{0, 1} }
|
||||
|
||||
type Log struct {
|
||||
Source Log_Source `protobuf:"varint,1,opt,name=source,enum=hapi.release.Log_Source" json:"source,omitempty"`
|
||||
Level Log_Level `protobuf:"varint,2,opt,name=level,enum=hapi.release.Log_Level" json:"level,omitempty"`
|
||||
Release string `protobuf:"bytes,3,opt,name=release" json:"release,omitempty"`
|
||||
Log string `protobuf:"bytes,4,opt,name=log" json:"log,omitempty"`
|
||||
Timestamp *google_protobuf.Timestamp `protobuf:"bytes,5,opt,name=timestamp" json:"timestamp,omitempty"`
|
||||
}
|
||||
|
||||
func (m *Log) Reset() { *m = Log{} }
|
||||
func (m *Log) String() string { return proto.CompactTextString(m) }
|
||||
func (*Log) ProtoMessage() {}
|
||||
func (*Log) Descriptor() ([]byte, []int) { return fileDescriptor2, []int{0} }
|
||||
|
||||
func (m *Log) GetTimestamp() *google_protobuf.Timestamp {
|
||||
if m != nil {
|
||||
return m.Timestamp
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterType((*Log)(nil), "hapi.release.Log")
|
||||
proto.RegisterEnum("hapi.release.Log_Source", Log_Source_name, Log_Source_value)
|
||||
proto.RegisterEnum("hapi.release.Log_Level", Log_Level_name, Log_Level_value)
|
||||
}
|
||||
|
||||
func init() { proto.RegisterFile("hapi/release/log.proto", fileDescriptor2) }
|
||||
|
||||
var fileDescriptor2 = []byte{
|
||||
// 317 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x64, 0x8f, 0x4b, 0x4b, 0xfb, 0x40,
|
||||
0x14, 0xc5, 0x9b, 0x77, 0x73, 0xfb, 0xe7, 0xcf, 0x65, 0x16, 0x3a, 0x74, 0x63, 0xe9, 0xaa, 0x1b,
|
||||
0x27, 0x5a, 0x37, 0x6e, 0xfb, 0x18, 0x6b, 0x30, 0x4d, 0x64, 0x12, 0x11, 0x5d, 0x08, 0xad, 0x8c,
|
||||
0xb1, 0x90, 0x32, 0xa5, 0x0f, 0xbf, 0xae, 0x5f, 0x45, 0x66, 0xd2, 0xa8, 0xe0, 0xee, 0xde, 0x7b,
|
||||
0x7e, 0xe7, 0x72, 0x0e, 0x9c, 0xbc, 0x2f, 0x36, 0xab, 0x68, 0x2b, 0x2b, 0xb9, 0xd8, 0xc9, 0xa8,
|
||||
0x52, 0x25, 0xdb, 0x6c, 0xd5, 0x5e, 0x91, 0x7f, 0xfa, 0xce, 0x8e, 0xf7, 0xee, 0x59, 0xa9, 0x54,
|
||||
0x59, 0xc9, 0xc8, 0x68, 0xcb, 0xc3, 0x5b, 0xb4, 0x5f, 0xad, 0xe5, 0x6e, 0xbf, 0x58, 0x6f, 0x6a,
|
||||
0xbc, 0xff, 0x69, 0x83, 0x93, 0xa8, 0x92, 0x5c, 0x80, 0xbf, 0x53, 0x87, 0xed, 0xab, 0xa4, 0x56,
|
||||
0xcf, 0x1a, 0xfc, 0x1f, 0x52, 0xf6, 0xfb, 0x0f, 0x4b, 0x54, 0xc9, 0x72, 0xa3, 0x8b, 0x23, 0x47,
|
||||
0xce, 0xc1, 0xab, 0xe4, 0x87, 0xac, 0xa8, 0x6d, 0x0c, 0xa7, 0x7f, 0x0d, 0x89, 0x96, 0x45, 0x4d,
|
||||
0x11, 0x0a, 0xc1, 0x51, 0xa3, 0x4e, 0xcf, 0x1a, 0x84, 0xa2, 0x59, 0x09, 0x82, 0x53, 0xa9, 0x92,
|
||||
0xba, 0xe6, 0xaa, 0x47, 0x72, 0x0d, 0xe1, 0x77, 0x4e, 0xea, 0xf5, 0xac, 0x41, 0x67, 0xd8, 0x65,
|
||||
0x75, 0x13, 0xd6, 0x34, 0x61, 0x45, 0x43, 0x88, 0x1f, 0xb8, 0x7f, 0x09, 0x7e, 0x1d, 0x93, 0xb4,
|
||||
0xc1, 0xbd, 0xcd, 0xb2, 0x3b, 0x6c, 0xe9, 0xa9, 0xe0, 0x79, 0x81, 0x16, 0x09, 0xc0, 0xb9, 0xcf,
|
||||
0xa6, 0x68, 0x13, 0x00, 0x3f, 0x7f, 0xca, 0x0b, 0x3e, 0x47, 0xa7, 0xff, 0x02, 0x9e, 0x09, 0x4a,
|
||||
0x42, 0xf0, 0xf8, 0x9c, 0x8b, 0x19, 0xb6, 0xf4, 0x38, 0x4a, 0xb8, 0xd0, 0x9e, 0x36, 0xb8, 0x13,
|
||||
0x11, 0x17, 0x68, 0x6b, 0x37, 0x17, 0x02, 0x1d, 0xd2, 0x81, 0xe0, 0x71, 0x24, 0xd2, 0x38, 0x9d,
|
||||
0xa1, 0xab, 0x5f, 0xa5, 0x59, 0x11, 0x4f, 0x38, 0x7a, 0x9a, 0x8d, 0xd3, 0x9b, 0x0c, 0x7d, 0xfd,
|
||||
0x60, 0xca, 0xc7, 0x0f, 0x33, 0x0c, 0xc6, 0xe1, 0x73, 0xd3, 0x74, 0xe9, 0x9b, 0xf0, 0x57, 0x5f,
|
||||
0x01, 0x00, 0x00, 0xff, 0xff, 0xe3, 0x7b, 0x56, 0xb1, 0xbc, 0x01, 0x00, 0x00,
|
||||
}
|
@ -1,48 +1,87 @@
|
||||
package logdistributor
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
rspb "k8s.io/helm/pkg/proto/hapi/release"
|
||||
)
|
||||
|
||||
type Log struct {
|
||||
Log string
|
||||
type Logsub struct {
|
||||
C chan *rspb.Log
|
||||
release string
|
||||
sources []rspb.Log_Source
|
||||
level rspb.Log_Level
|
||||
}
|
||||
|
||||
type Subscription struct {
|
||||
c chan<- *Log
|
||||
type release struct {
|
||||
name string
|
||||
sourceMappings map[rspb.Log_Source]map[*Logsub]bool
|
||||
}
|
||||
|
||||
type Listener struct {
|
||||
subs map[*Subscription]bool
|
||||
type Pubsub struct {
|
||||
releases map[string]*release
|
||||
}
|
||||
|
||||
type Distributor struct {
|
||||
listeners map[string]*Listener
|
||||
func New() *Pubsub {
|
||||
rls := make(map[string]*release)
|
||||
return &Pubsub{releases: rls}
|
||||
}
|
||||
|
||||
func (l *Listener) subscribe(c chan<- *Log) *Subscription {
|
||||
sub := &Subscription{c}
|
||||
l.subs[sub] = true
|
||||
return sub
|
||||
func newRelease(name string) *release {
|
||||
rs := &release{name: name}
|
||||
rs.sourceMappings = make(map[rspb.Log_Source]map[*Logsub]bool, len(rspb.Log_Source_name))
|
||||
return rs
|
||||
}
|
||||
|
||||
func (d *Distributor) Subscribe() {
|
||||
func (rs *release) subscribe(sub *Logsub) {
|
||||
for _, source := range sub.sources {
|
||||
log_source := rspb.Log_Source(source)
|
||||
if _, ok := rs.sourceMappings[log_source]; !ok {
|
||||
subs := make(map[*Logsub]bool, 1)
|
||||
rs.sourceMappings[log_source] = subs
|
||||
}
|
||||
rs.sourceMappings[log_source][sub] = true
|
||||
}
|
||||
}
|
||||
|
||||
func (ps *Pubsub) subscribe(sub *Logsub) {
|
||||
if _, ok := ps.releases[sub.release]; !ok {
|
||||
rs := newRelease(sub.release)
|
||||
rs.subscribe(sub)
|
||||
ps.releases[sub.release] = rs
|
||||
}
|
||||
ps.releases[sub.release].subscribe(sub)
|
||||
}
|
||||
|
||||
func (l *Listener) unsubscribe(sub *Subscription) {
|
||||
delete(l.subs, sub)
|
||||
func (ps *Pubsub) Subscribe(release string, level rspb.Log_Level, sources ...rspb.Log_Source) *Logsub {
|
||||
ch := make(chan *rspb.Log)
|
||||
ls := &Logsub{C: ch, release: release, level: level, sources: sources}
|
||||
ps.subscribe(ls)
|
||||
return ls
|
||||
}
|
||||
|
||||
func (l *Listener) writeLog(log *Log) error {
|
||||
for _, s := range l.subs {
|
||||
s.c <- log
|
||||
func (ps *Pubsub) Unsubscribe(sub *Logsub) {
|
||||
if rs, ok := ps.releases[sub.release]; ok {
|
||||
for source, subMap := range rs.sourceMappings {
|
||||
delete(subMap, sub)
|
||||
if len(subMap) == 0 {
|
||||
delete(rs.sourceMappings, source)
|
||||
}
|
||||
}
|
||||
if len(rs.sourceMappings) == 0 {
|
||||
delete(ps.releases, sub.release)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *Distributor) WriteLog(log *Log, release string) error {
|
||||
l := d.listeners[release]
|
||||
if l == nil {
|
||||
return fmt.Errorf("No listeners configured for %s", release)
|
||||
func (ps *Pubsub) PubLog(rls string, source rspb.Log_Source, level rspb.Log_Level, message string) {
|
||||
log := &rspb.Log{Release: rls, Source: source, Level: level, Log: message}
|
||||
if rls, ok := ps.releases[log.Release]; ok {
|
||||
if subs, ok := rls.sourceMappings[log.Source]; ok {
|
||||
for sub := range subs {
|
||||
if sub.level >= log.Level {
|
||||
sub.C <- log
|
||||
}
|
||||
}
|
||||
}
|
||||
return l.writeLog(log)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in new issue