mirror of https://github.com/helm/helm
commit
0d16a01db7
@ -0,0 +1,49 @@
|
||||
|
||||
// Copyright 2016 The Kubernetes Authors All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
syntax = "proto3";
|
||||
|
||||
package hapi.release;
|
||||
|
||||
import "google/protobuf/timestamp.proto";
|
||||
|
||||
option go_package = "release";
|
||||
|
||||
message Log {
|
||||
// Allows filtering by log event source
|
||||
enum Source {
|
||||
HOOK = 0;
|
||||
TEST = 1;
|
||||
POD = 2;
|
||||
SYSTEM = 3;
|
||||
}
|
||||
|
||||
// Syslog log levels
|
||||
enum LogLevel {
|
||||
EMERG = 0;
|
||||
ALERT = 1;
|
||||
CRIT = 2;
|
||||
ERR = 3;
|
||||
WARNING = 4;
|
||||
NOTICE = 5;
|
||||
INFO = 6;
|
||||
DEBUG = 7;
|
||||
}
|
||||
|
||||
Source source = 1;
|
||||
string release = 2;
|
||||
string log = 3;
|
||||
google.protobuf.Timestamp timestamp = 4;
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package logdistributor
|
||||
|
||||
import "fmt"
|
||||
|
||||
type Log struct {
|
||||
Log string
|
||||
}
|
||||
|
||||
type Subscription struct {
|
||||
c chan<- *Log
|
||||
}
|
||||
|
||||
type Listener struct {
|
||||
subs map[*Subscription]bool
|
||||
}
|
||||
|
||||
type Distributor struct {
|
||||
listeners map[string]*Listener
|
||||
}
|
||||
|
||||
func (l *Listener) subscribe(c chan<- *Log) *Subscription {
|
||||
sub := &Subscription{c}
|
||||
l.subs[sub] = true
|
||||
return sub
|
||||
}
|
||||
|
||||
func (d *Distributor) Subscribe() {
|
||||
|
||||
}
|
||||
|
||||
func (l *Listener) unsubscribe(sub *Subscription) {
|
||||
delete(l.subs, sub)
|
||||
}
|
||||
|
||||
func (l *Listener) writeLog(log *Log) error {
|
||||
for _, s := range l.subs {
|
||||
s.c <- log
|
||||
}
|
||||
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)
|
||||
}
|
||||
return l.writeLog(log)
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package logdistributor
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func TestDistributor_WriteLog(t *testing.T) {
|
||||
d := &Distributor{}
|
||||
l := &Log{Log: "Test log"}
|
||||
d.WriteLog(l, "testrelease")
|
||||
|
||||
if len(d.listeners) != 1 {
|
||||
t.Errorf("Invalid number of listeners present: %d (expecting 1)", len(d.listeners))
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkDistributor_WriteLog(b *testing.B) {
|
||||
}
|
||||
|
||||
func ExampleDistributor_WriteLog() {
|
||||
sub := &Subscription{}
|
||||
c := make(chan *Log)
|
||||
sub.c = c
|
||||
|
||||
go func(){
|
||||
for l := range c {
|
||||
fmt.Println(l.Log)
|
||||
}
|
||||
|
||||
for {
|
||||
select {
|
||||
case l := <-c:
|
||||
fmt.Println(l.Log)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
sub.c <- &Log{Log: "Test log!"}
|
||||
// Output: Test log!
|
||||
}
|
||||
|
Loading…
Reference in new issue