This commit is contained in:
Yuqi Wang 2019-07-26 20:09:05 +08:00 коммит произвёл GitHub
Родитель 2caad5b969
Коммит 48f601bb39
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
35 изменённых файлов: 263 добавлений и 2369 удалений

18
Gopkg.lock сгенерированный
Просмотреть файл

@ -89,14 +89,6 @@
revision = "0ff49de124c6f76f8494e194af75bde0f1a49a29"
version = "v1.1.6"
[[projects]]
digest = "1:58999a98719fddbac6303cb17e8d85b945f60b72f48e3a2df6b950b97fa926f1"
name = "github.com/konsorten/go-windows-terminal-sequences"
packages = ["."]
pruneopts = "NUT"
revision = "f55edac94c9bbba5d6182a4be46d86a2c9b5b50e"
version = "v1.0.2"
[[projects]]
digest = "1:2f42fa12d6911c7b7659738758631bec870b7e9b4c6be5444f963cdcfccc191f"
name = "github.com/modern-go/concurrent"
@ -121,14 +113,6 @@
revision = "ba968bfe8b2f7e042a574c888954fccecfa385b4"
version = "v0.8.1"
[[projects]]
digest = "1:f4aaa07a6c33f2b354726d0571acbc8ca118837c75709f6353203ae1a3f8eeab"
name = "github.com/sirupsen/logrus"
packages = ["."]
pruneopts = "NUT"
revision = "839c75faf7f98a33d445d181f3018b5c3409a45e"
version = "v1.4.2"
[[projects]]
digest = "1:9d8420bbf131d1618bde6530af37c3799340d3762cc47210c1d9532a4c3a2779"
name = "github.com/spf13/pflag"
@ -622,7 +606,6 @@
analyzer-version = 1
input-imports = [
"github.com/pkg/errors",
"github.com/sirupsen/logrus",
"gopkg.in/yaml.v2",
"k8s.io/api/core/v1",
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1",
@ -655,6 +638,7 @@
"k8s.io/code-generator/cmd/defaulter-gen",
"k8s.io/code-generator/cmd/informer-gen",
"k8s.io/code-generator/cmd/lister-gen",
"k8s.io/klog",
]
solver-name = "gps-cdcl"
solver-version = 1

Просмотреть файл

@ -8,10 +8,6 @@ required = [
"k8s.io/code-generator/cmd/defaulter-gen",
]
[[constraint]]
name = "github.com/sirupsen/logrus"
version = "1.0.4"
[[constraint]]
name = "github.com/pkg/errors"
version = "v0.8.0"

Просмотреть файл

@ -30,7 +30,7 @@ BASH_DIR=$(cd $(dirname ${BASH_SOURCE}) && pwd)
cd ${BASH_DIR}
./frameworkbarrier
./frameworkbarrier "$@"
MNT_DIR=/mnt/frameworkbarrier

Просмотреть файл

@ -30,4 +30,4 @@ BASH_DIR=$(cd $(dirname ${BASH_SOURCE}) && pwd)
cd ${BASH_DIR}
./frameworkcontroller
./frameworkcontroller "$@"

Просмотреть файл

@ -25,9 +25,6 @@ package main
import (
"github.com/microsoft/frameworkcontroller/pkg/common"
"github.com/microsoft/frameworkcontroller/pkg/controller"
"os"
"os/signal"
"syscall"
)
func init() {
@ -35,13 +32,5 @@ func init() {
}
func main() {
stopCh := make(chan struct{})
defer close(stopCh)
go controller.NewFrameworkController().Run(stopCh)
sigTerm := make(chan os.Signal, 1)
signal.Notify(sigTerm, syscall.SIGTERM)
signal.Notify(sigTerm, syscall.SIGINT)
<-sigTerm
controller.NewFrameworkController().Run(common.NewStopChannel())
}

Просмотреть файл

@ -84,7 +84,7 @@ All running containers of the Framework will be stopped while the object of the
| Code | Body | Description |
|:---- |:---- |:---- |
| OK(200) | [Framework](../pkg/apis/frameworkcontroller/v1/types.go) | Return current Framework. |
| NotFound(200) | [Status](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.14/#status-v1-meta) | The specified Framework is not found. |
| NotFound(404) | [Status](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.14/#status-v1-meta) | The specified Framework is not found. |
#### <a name="DELETE_Framework">DELETE Framework</a>
**Request**
@ -119,7 +119,7 @@ Notes:
|:---- |:---- |:---- |
| OK(200) | [Framework](../pkg/apis/frameworkcontroller/v1/types.go) | The specified Framework is deleting.<br>Return current Framework. |
| OK(200) | [Status](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.14/#status-v1-meta) | The specified Framework is deleted. |
| NotFound(200) | [Status](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.14/#status-v1-meta) | The specified Framework is not found. |
| NotFound(404) | [Status](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.14/#status-v1-meta) | The specified Framework is not found. |
#### <a name="GET_Framework">GET Framework</a>
**Request**
@ -135,7 +135,7 @@ Get the specified Framework.
| Code | Body | Description |
|:---- |:---- |:---- |
| OK(200) | [Framework](../pkg/apis/frameworkcontroller/v1/types.go) | Return current Framework. |
| NotFound(200) | [Status](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.14/#status-v1-meta) | The specified Framework is not found. |
| NotFound(404) | [Status](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.14/#status-v1-meta) | The specified Framework is not found. |
#### <a name="LIST_Frameworks">LIST Frameworks</a>
**Request**
@ -171,7 +171,7 @@ Watch the change events of the specified Framework.
| Code | Body | Description |
|:---- |:---- |:---- |
| OK(200) | [WatchEvent](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.14/#watchevent-v1-meta) | Streaming the change events of the specified Framework. |
| NotFound(200) | [Status](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.14/#status-v1-meta) | The specified Framework is not found. |
| NotFound(404) | [Status](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.14/#status-v1-meta) | The specified Framework is not found. |
#### <a name="WATCH_LIST_Frameworks">WATCH_LIST Frameworks</a>
**Request**

Просмотреть файл

@ -25,10 +25,10 @@ package v1
import (
"fmt"
"github.com/microsoft/frameworkcontroller/pkg/common"
log "github.com/sirupsen/logrus"
core "k8s.io/api/core/v1"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/klog"
"strconv"
"strings"
)
@ -577,7 +577,7 @@ func (f *Framework) TransitionFrameworkState(dstState FrameworkState) {
f.Status.State = dstState
f.Status.TransitionTime = meta.Now()
log.Infof(
klog.Infof(
"[%v]: Transitioned Framework from [%v] to [%v]",
f.Key(), srcState, dstState)
}
@ -594,7 +594,7 @@ func (f *Framework) TransitionTaskState(
taskStatus.State = dstState
taskStatus.TransitionTime = meta.Now()
log.Infof(
klog.Infof(
"[%v][%v][%v]: Transitioned Task from [%v] to [%v]",
f.Key(), taskRoleName, taskIndex, srcState, dstState)
}

Просмотреть файл

@ -27,8 +27,7 @@ import (
ci "github.com/microsoft/frameworkcontroller/pkg/apis/frameworkcontroller/v1"
frameworkClient "github.com/microsoft/frameworkcontroller/pkg/client/clientset/versioned"
"github.com/microsoft/frameworkcontroller/pkg/common"
"github.com/microsoft/frameworkcontroller/pkg/util"
log "github.com/sirupsen/logrus"
"github.com/microsoft/frameworkcontroller/pkg/internal"
"io/ioutil"
apiErrors "k8s.io/apimachinery/pkg/api/errors"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
@ -36,6 +35,7 @@ import (
kubeClient "k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/klog"
"os"
"strconv"
"strings"
@ -134,7 +134,7 @@ func newConfig() *Config {
} else {
i, err := strconv.ParseInt(barrierCheckIntervalSecStr, 10, 64)
if err != nil {
log.Errorf(
klog.Errorf(
"Failed to parse ${%v}: %v",
EnvNameBarrierCheckIntervalSec, err)
exit(ci.CompletionCodeContainerPermanentFailed)
@ -148,7 +148,7 @@ func newConfig() *Config {
} else {
i, err := strconv.ParseInt(barrierCheckTimeoutSecStr, 10, 64)
if err != nil {
log.Errorf(
klog.Errorf(
"Failed to parse ${%v}: %v",
EnvNameBarrierCheckTimeoutSec, err)
exit(ci.CompletionCodeContainerPermanentFailed)
@ -159,19 +159,19 @@ func newConfig() *Config {
// Validation
errPrefix := "Validation Failed: "
if c.FrameworkName == "" {
log.Errorf(errPrefix+
klog.Errorf(errPrefix+
"${%v} should not be empty",
ci.EnvNameFrameworkName)
exit(ci.CompletionCodeContainerPermanentFailed)
}
if c.BarrierCheckIntervalSec < 5 {
log.Errorf(errPrefix+
klog.Errorf(errPrefix+
"${%v} %v should not be less than 5",
EnvNameBarrierCheckIntervalSec, c.BarrierCheckIntervalSec)
exit(ci.CompletionCodeContainerPermanentFailed)
}
if c.BarrierCheckTimeoutSec < 60 || c.BarrierCheckTimeoutSec > 20*60 {
log.Errorf(errPrefix+
klog.Errorf(errPrefix+
"${%v} %v should not be less than 60 or greater than 20 * 60",
EnvNameBarrierCheckTimeoutSec, c.BarrierCheckTimeoutSec)
exit(ci.CompletionCodeContainerPermanentFailed)
@ -195,7 +195,7 @@ func buildKubeConfig(bConfig *Config) *rest.Config {
kConfig, err := clientcmd.BuildConfigFromFlags(
bConfig.KubeApiServerAddress, bConfig.KubeConfigFilePath)
if err != nil {
log.Errorf("Failed to build KubeConfig, please ensure "+
klog.Errorf("Failed to build KubeConfig, please ensure "+
"${KUBE_APISERVER_ADDRESS} or ${KUBECONFIG} or ${HOME}/.kube/config or "+
"${KUBERNETES_SERVICE_HOST}:${KUBERNETES_SERVICE_PORT} is valid: "+
"Error: %v", err)
@ -208,12 +208,12 @@ func buildKubeConfig(bConfig *Config) *rest.Config {
// Methods
///////////////////////////////////////////////////////////////////////////////////////
func NewFrameworkBarrier() *FrameworkBarrier {
log.Infof("Initializing %v", ComponentName)
klog.Infof("Initializing %v", ComponentName)
bConfig := newConfig()
common.LogLines("With Config: \n%v", common.ToYaml(bConfig))
klog.Infof("With Config: \n%v", common.ToYaml(bConfig))
kConfig := buildKubeConfig(bConfig)
kClient, fClient := util.CreateClients(kConfig)
kClient, fClient := internal.CreateClients(kConfig)
return &FrameworkBarrier{
kConfig: kConfig,
@ -224,7 +224,7 @@ func NewFrameworkBarrier() *FrameworkBarrier {
}
func (b *FrameworkBarrier) Run() {
log.Infof("Running %v", ComponentName)
klog.Infof("Running %v", ComponentName)
var f *ci.Framework
var err error
@ -242,7 +242,7 @@ func (b *FrameworkBarrier) Run() {
isPassed = isBarrierPassed(f)
return isPassed, nil
} else {
log.Warnf("Failed to get Framework object from ApiServer: %v", err)
klog.Warningf("Failed to get Framework object from ApiServer: %v", err)
if apiErrors.IsNotFound(err) {
// Permanent Error: Early Stop
isPermanentErr = true
@ -256,18 +256,18 @@ func (b *FrameworkBarrier) Run() {
})
if isPassed {
log.Infof("BarrierPassed: " +
klog.Infof("BarrierPassed: " +
"All Tasks are ready with not nil PodIP.")
dumpFramework(f)
generateInjector(f)
exit(ci.CompletionCodeSucceeded)
} else {
if err == nil {
log.Errorf("BarrierNotPassed: " +
klog.Errorf("BarrierNotPassed: " +
"Timeout to wait all Tasks are ready with not nil PodIP.")
exit(ci.CompletionCodeContainerTransientConflictFailed)
} else {
log.Errorf("Failed to get Framework object from ApiServer: %v", err)
klog.Errorf("Failed to get Framework object from ApiServer: %v", err)
if isPermanentErr {
exit(ci.CompletionCodeContainerPermanentFailed)
} else {
@ -296,12 +296,12 @@ func isBarrierPassed(f *ci.Framework) bool {
// Wait until readyTaskCount is consistent with totalTaskCount.
if readyTaskCount == totalTaskCount {
log.Infof("BarrierPassed: "+
klog.Infof("BarrierPassed: "+
"%v/%v Tasks are ready with not nil PodIP.",
readyTaskCount, totalTaskCount)
return true
} else {
log.Warnf("BarrierNotPassed: "+
klog.Warningf("BarrierNotPassed: "+
"%v/%v Tasks are ready with not nil PodIP.",
readyTaskCount, totalTaskCount)
return false
@ -316,13 +316,13 @@ func isTaskReady(taskStatus *ci.TaskStatus) bool {
func dumpFramework(f *ci.Framework) {
err := ioutil.WriteFile(FrameworkObjectFilePath, []byte(common.ToJson(f)), 0644)
if err != nil {
log.Errorf(
klog.Errorf(
"Failed to dump the Framework object to local file: %v, %v",
FrameworkObjectFilePath, err)
exit(ci.CompletionCode(1))
}
log.Infof(
klog.Infof(
"Succeeded to dump the Framework object to local file: %v",
FrameworkObjectFilePath)
}
@ -393,13 +393,13 @@ func generateInjector(f *ci.Framework) {
err := ioutil.WriteFile(InjectorFilePath, []byte(injector.String()), 0755)
if err != nil {
log.Errorf(
klog.Errorf(
"Failed to generate the injector script to local file: %v, %v",
InjectorFilePath, err)
exit(ci.CompletionCode(1))
}
log.Infof(
klog.Infof(
"Succeeded to generate the injector script to local file: %v",
InjectorFilePath)
}
@ -407,18 +407,18 @@ func generateInjector(f *ci.Framework) {
func exit(cc ci.CompletionCode) {
logPfx := fmt.Sprintf("ExitCode: %v: Exit with ", cc)
if cc == ci.CompletionCodeSucceeded {
log.Infof(logPfx + "success.")
klog.Infof(logPfx + "success.")
} else if cc == ci.CompletionCodeContainerTransientFailed {
log.Errorf(logPfx +
klog.Errorf(logPfx +
"transient failure to tell controller to retry.")
} else if cc == ci.CompletionCodeContainerTransientConflictFailed {
log.Errorf(logPfx +
klog.Errorf(logPfx +
"transient conflict failure to tell controller to back off retry.")
} else if cc == ci.CompletionCodeContainerPermanentFailed {
log.Errorf(logPfx +
klog.Errorf(logPfx +
"permanent failure to tell controller not to retry.")
} else {
log.Errorf(logPfx +
klog.Errorf(logPfx +
"unknown failure to tell controller to retry within maxRetryCount.")
}

Просмотреть файл

@ -23,8 +23,7 @@
package common
import (
log "github.com/sirupsen/logrus"
"io"
"k8s.io/klog"
)
type Empty struct{}
@ -69,20 +68,9 @@ func (s ImmutableSet) Contains(item T) bool {
return s.set.Contains(item)
}
type LogHook struct {
LogLevels []log.Level
LogWriter io.Writer
}
type KlogWriter struct{}
func (lh *LogHook) Levels() []log.Level {
return lh.LogLevels
}
func (lh *LogHook) Fire(entry *log.Entry) error {
str, err := entry.String()
if err != nil {
return err
}
_, err = lh.LogWriter.Write([]byte(str))
return err
func (w KlogWriter) Write(data []byte) (n int, err error) {
klog.InfoDepth(1, string(data))
return len(data), nil
}

Просмотреть файл

@ -26,15 +26,16 @@ import (
"encoding/json"
"flag"
"fmt"
log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"
"io/ioutil"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/klog"
"log"
"math/rand"
"os"
"strings"
"os/signal"
"syscall"
"time"
)
@ -113,37 +114,52 @@ func InitAll() {
}
func InitLogger() {
// K8S library logs to stderr
// Defaulting
klog.InitFlags(flag.CommandLine)
flag.Set("v", "2")
// Configure klog from command line
flag.Parse()
// Only support stderr logging and not support file logging.
// To achieve file logging, user can redirect the stderr to file and rotate the
// file to avoid out of disk.
// This is because currently file logging in klog has some limitations:
// 1. klog will never remove old files even if the log_file_max_size is exceeded.
// So, the total log data size cannot be limited.
// 2. We do not have the chance to flush log to file, if a panic is called in
// an unmanaged goroutine and no one can recover it in the goroutine.
// So, even if the log about the panic itself can be lost.
flag.Set("logtostderr", "true")
flag.Set("alsologtostderr", "true")
flag.Set("stderrthreshold", "INFO")
klog.SetOutput(ioutil.Discard)
// We log to stdout
log.SetFormatter(&log.TextFormatter{
DisableColors: true,
// Always log with full timestamp, regardless of whether TTY is attached
DisableTimestamp: false,
FullTimestamp: true,
// Align with k8s.io/apimachinery/pkg/apis/meta/v1.Time
TimestampFormat: time.RFC3339,
})
log.SetLevel(log.DebugLevel)
log.SetOutput(os.Stdout)
}
func LogLines(format string, args ...interface{}) {
lines := strings.Split(fmt.Sprintf(format, args...), "\n")
for _, line := range lines {
log.Infof(line)
}
// Redirect the default golang log to klog
log.SetOutput(KlogWriter{})
log.SetFlags(0)
}
func InitRandSeed() {
rand.Seed(time.Now().UTC().UnixNano())
}
func NewStopChannel() <-chan struct{} {
stopCh := make(chan struct{})
// Stop on shutdown signal:
// Must be a buffered channel, otherwise the shutdown signal may be lost.
shutdownCh := make(chan os.Signal, 1)
signal.Notify(shutdownCh, syscall.SIGINT, syscall.SIGTERM)
go func() {
s := <-shutdownCh
klog.Warningf("Received shutdown signal: %v", s)
close(stopCh)
}()
return stopCh
}
// Rand in range [min, max]
func RandInt64(min int64, max int64) int64 {
return min + rand.Int63n(max-min+1)

Просмотреть файл

@ -29,9 +29,8 @@ import (
frameworkInformer "github.com/microsoft/frameworkcontroller/pkg/client/informers/externalversions"
frameworkLister "github.com/microsoft/frameworkcontroller/pkg/client/listers/frameworkcontroller/v1"
"github.com/microsoft/frameworkcontroller/pkg/common"
"github.com/microsoft/frameworkcontroller/pkg/util"
"github.com/microsoft/frameworkcontroller/pkg/internal"
errorWrap "github.com/pkg/errors"
log "github.com/sirupsen/logrus"
core "k8s.io/api/core/v1"
apiErrors "k8s.io/apimachinery/pkg/api/errors"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
@ -46,6 +45,7 @@ import (
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/util/retry"
"k8s.io/client-go/util/workqueue"
"k8s.io/klog"
"reflect"
"strings"
"sync"
@ -198,13 +198,13 @@ type ExpectedFrameworkStatusInfo struct {
}
func NewFrameworkController() *FrameworkController {
log.Infof("Initializing " + ci.ComponentName)
klog.Infof("Initializing " + ci.ComponentName)
cConfig := ci.NewConfig()
common.LogLines("With Config: \n%v", common.ToYaml(cConfig))
klog.Infof("With Config: \n%v", common.ToYaml(cConfig))
kConfig := ci.BuildKubeConfig(cConfig)
kClient, fClient := util.CreateClients(kConfig)
kClient, fClient := internal.CreateClients(kConfig)
// Informer resync will periodically replay the event of all objects stored in its cache.
// However, by design, Informer and Controller should not miss any event.
@ -289,25 +289,25 @@ func NewFrameworkController() *FrameworkController {
// obj could be *ci.Framework or cache.DeletedFinalStateUnknown.
func (c *FrameworkController) enqueueFrameworkObj(obj interface{}, msg string) {
key, err := util.GetKey(obj)
key, err := internal.GetKey(obj)
if err != nil {
log.Errorf("Failed to get key for obj %#v, skip to enqueue: %v", obj, err)
klog.Errorf("Failed to get key for obj %#v, skip to enqueue: %v", obj, err)
return
}
_, _, err = util.SplitKey(key)
_, _, err = internal.SplitKey(key)
if err != nil {
log.Errorf("Got invalid key %v for obj %#v, skip to enqueue: %v", key, obj, err)
klog.Errorf("Got invalid key %v for obj %#v, skip to enqueue: %v", key, obj, err)
return
}
c.fQueue.Add(key)
log.Infof("[%v]: enqueueFrameworkObj: %v", key, msg)
klog.Infof("[%v]: enqueueFrameworkObj: %v", key, msg)
}
// obj could be *core.ConfigMap or cache.DeletedFinalStateUnknown.
func (c *FrameworkController) enqueueFrameworkConfigMapObj(obj interface{}, msg string) {
if cm := util.ToConfigMap(obj); cm != nil {
if cm := internal.ToConfigMap(obj); cm != nil {
if f := c.getConfigMapOwner(cm); f != nil {
c.enqueueFrameworkObj(f, msg+": "+cm.Name)
}
@ -316,7 +316,7 @@ func (c *FrameworkController) enqueueFrameworkConfigMapObj(obj interface{}, msg
// obj could be *core.Pod or cache.DeletedFinalStateUnknown.
func (c *FrameworkController) enqueueFrameworkPodObj(obj interface{}, msg string) {
if pod := util.ToPod(obj); pod != nil {
if pod := internal.ToPod(obj); pod != nil {
if cm := c.getPodOwner(pod); cm != nil {
c.enqueueFrameworkConfigMapObj(cm, msg+": "+pod.Name)
}
@ -336,7 +336,7 @@ func (c *FrameworkController) getConfigMapOwner(cm *core.ConfigMap) *ci.Framewor
f, err := c.fLister.Frameworks(cm.Namespace).Get(cmOwner.Name)
if err != nil {
if !apiErrors.IsNotFound(err) {
log.Errorf(
klog.Errorf(
"[%v]: ConfigMapOwner %#v cannot be got from local cache: %v",
cm.Namespace+"/"+cm.Name, *cmOwner, err)
}
@ -365,7 +365,7 @@ func (c *FrameworkController) getPodOwner(pod *core.Pod) *core.ConfigMap {
cm, err := c.cmLister.ConfigMaps(pod.Namespace).Get(podOwner.Name)
if err != nil {
if !apiErrors.IsNotFound(err) {
log.Errorf(
klog.Errorf(
"[%v]: PodOwner %#v cannot be got from local cache: %v",
pod.Namespace+"/"+pod.Name, *podOwner, err)
}
@ -383,11 +383,11 @@ func (c *FrameworkController) getPodOwner(pod *core.Pod) *core.ConfigMap {
func (c *FrameworkController) Run(stopCh <-chan struct{}) {
defer c.fQueue.ShutDown()
defer log.Errorf("Stopping " + ci.ComponentName)
defer klog.Errorf("Stopping " + ci.ComponentName)
defer runtime.HandleCrash()
log.Infof("Recovering " + ci.ComponentName)
util.PutCRD(
klog.Infof("Recovering " + ci.ComponentName)
internal.PutCRD(
c.kConfig,
ci.BuildFrameworkCRD(),
c.cConfig.CRDEstablishedCheckIntervalSec,
@ -404,7 +404,7 @@ func (c *FrameworkController) Run(stopCh <-chan struct{}) {
panic(fmt.Errorf("Failed to WaitForCacheSync"))
}
log.Infof("Running %v with %v workers",
klog.Infof("Running %v with %v workers",
ci.ComponentName, *c.cConfig.WorkerNumber)
for i := int32(0); i < *c.cConfig.WorkerNumber; i++ {
@ -417,8 +417,8 @@ func (c *FrameworkController) Run(stopCh <-chan struct{}) {
}
func (c *FrameworkController) worker(id int32) {
defer log.Errorf("Stopping worker-%v", id)
log.Infof("Running worker-%v", id)
defer klog.Errorf("Stopping worker-%v", id)
klog.Infof("Running worker-%v", id)
for c.processNextWorkItem(id) {
}
@ -430,7 +430,7 @@ func (c *FrameworkController) processNextWorkItem(id int32) bool {
if quit {
return false
}
log.Infof("[%v]: Assigned to worker-%v", key, id)
klog.Infof("[%v]: Assigned to worker-%v", key, id)
// Remove the item from the current processing items to unblock getting the
// same item again.
@ -457,19 +457,19 @@ func (c *FrameworkController) processNextWorkItem(id int32) bool {
func (c *FrameworkController) syncFramework(key string) (returnedErr error) {
startTime := time.Now()
logPfx := fmt.Sprintf("[%v]: syncFramework: ", key)
log.Infof(logPfx + "Started")
klog.Infof(logPfx + "Started")
defer func() {
if returnedErr != nil {
// returnedErr is already prefixed with logPfx
log.Warnf(returnedErr.Error())
log.Warnf(logPfx +
klog.Warningf(returnedErr.Error())
klog.Warningf(logPfx +
"Failed to due to Platform Transient Error. " +
"Will enqueue it again after rate limited delay")
}
log.Infof(logPfx+"Completed: Duration %v", time.Since(startTime))
klog.Infof(logPfx+"Completed: Duration %v", time.Since(startTime))
}()
namespace, name, err := util.SplitKey(key)
namespace, name, err := internal.SplitKey(key)
if err != nil {
// Unreachable
panic(fmt.Errorf(logPfx+
@ -482,7 +482,7 @@ func (c *FrameworkController) syncFramework(key string) (returnedErr error) {
if apiErrors.IsNotFound(err) {
// GarbageCollectionController will handle the dependent object
// deletion according to the ownerReferences.
log.Infof(logPfx+
klog.Infof(logPfx+
"Skipped: Framework cannot be found in local cache: %v", err)
c.deleteExpectedFrameworkStatusInfo(key)
return nil
@ -494,7 +494,7 @@ func (c *FrameworkController) syncFramework(key string) (returnedErr error) {
if localF.DeletionTimestamp != nil {
// Skip syncFramework to avoid fighting with GarbageCollectionController,
// because GarbageCollectionController may be deleting the dependent object.
log.Infof(logPfx+
klog.Infof(logPfx+
"Skipped: Framework is deleting: Will be deleted at %v",
localF.DeletionTimestamp)
return nil
@ -549,7 +549,7 @@ func (c *FrameworkController) syncFramework(key string) (returnedErr error) {
c.updateExpectedFrameworkStatusInfo(f.Key(), f.Status, updateErr == nil)
} else {
log.Infof(logPfx +
klog.Infof(logPfx +
"Skip to update the expected and remote Framework.Status since " +
"they are unchanged")
}
@ -564,8 +564,8 @@ func (c *FrameworkController) syncFramework(key string) (returnedErr error) {
// Frameworks will be enqueued to sync.
func (c *FrameworkController) recoverFrameworkWorkItems(f *ci.Framework) {
logPfx := fmt.Sprintf("[%v]: recoverFrameworkWorkItems: ", f.Key())
log.Infof(logPfx + "Started")
defer func() { log.Infof(logPfx + "Completed") }()
klog.Infof(logPfx + "Started")
defer func() { klog.Infof(logPfx + "Completed") }()
if f.Status == nil {
return
@ -603,7 +603,7 @@ func (c *FrameworkController) enqueueFrameworkAttemptCreationTimeoutCheck(
}
c.fQueue.AddAfter(f.Key(), leftDuration)
log.Infof("[%v]: enqueueFrameworkAttemptCreationTimeoutCheck after %v",
klog.Infof("[%v]: enqueueFrameworkAttemptCreationTimeoutCheck after %v",
f.Key(), leftDuration)
return true
}
@ -624,7 +624,7 @@ func (c *FrameworkController) enqueueTaskAttemptCreationTimeoutCheck(
}
c.fQueue.AddAfter(f.Key(), leftDuration)
log.Infof("[%v][%v][%v]: enqueueTaskAttemptCreationTimeoutCheck after %v",
klog.Infof("[%v][%v][%v]: enqueueTaskAttemptCreationTimeoutCheck after %v",
f.Key(), taskRoleName, taskIndex, leftDuration)
return true
}
@ -643,7 +643,7 @@ func (c *FrameworkController) enqueueFrameworkRetryDelayTimeoutCheck(
}
c.fQueue.AddAfter(f.Key(), leftDuration)
log.Infof("[%v]: enqueueFrameworkRetryDelayTimeoutCheck after %v",
klog.Infof("[%v]: enqueueFrameworkRetryDelayTimeoutCheck after %v",
f.Key(), leftDuration)
return true
}
@ -664,20 +664,20 @@ func (c *FrameworkController) enqueueTaskRetryDelayTimeoutCheck(
}
c.fQueue.AddAfter(f.Key(), leftDuration)
log.Infof("[%v][%v][%v]: enqueueTaskRetryDelayTimeoutCheck after %v",
klog.Infof("[%v][%v][%v]: enqueueTaskRetryDelayTimeoutCheck after %v",
f.Key(), taskRoleName, taskIndex, leftDuration)
return true
}
func (c *FrameworkController) enqueueFramework(f *ci.Framework, msg string) {
c.fQueue.Add(f.Key())
log.Infof("[%v]: enqueueFramework: %v", f.Key(), msg)
klog.Infof("[%v]: enqueueFramework: %v", f.Key(), msg)
}
func (c *FrameworkController) syncFrameworkStatus(f *ci.Framework) error {
logPfx := fmt.Sprintf("[%v]: syncFrameworkStatus: ", f.Key())
log.Infof(logPfx + "Started")
defer func() { log.Infof(logPfx + "Completed") }()
klog.Infof(logPfx + "Started")
defer func() { klog.Infof(logPfx + "Completed") }()
if f.Status == nil {
f.Status = f.NewFrameworkStatus()
@ -690,11 +690,11 @@ func (c *FrameworkController) syncFrameworkStatus(f *ci.Framework) error {
func (c *FrameworkController) syncFrameworkState(f *ci.Framework) (err error) {
logPfx := fmt.Sprintf("[%v]: syncFrameworkState: ", f.Key())
log.Infof(logPfx + "Started")
defer func() { log.Infof(logPfx + "Completed") }()
klog.Infof(logPfx + "Started")
defer func() { klog.Infof(logPfx + "Completed") }()
if f.Status.State == ci.FrameworkCompleted {
log.Infof(logPfx + "Skipped: Framework is already completed")
klog.Infof(logPfx + "Skipped: Framework is already completed")
return nil
}
@ -716,10 +716,10 @@ func (c *FrameworkController) syncFrameworkState(f *ci.Framework) (err error) {
if f.Spec.ExecutionType == ci.ExecutionStop {
diag = fmt.Sprintf("User has requested to stop the Framework")
code = ci.CompletionCodeStopFrameworkRequested
log.Infof(logPfx + diag)
klog.Infof(logPfx + diag)
} else {
if c.enqueueFrameworkAttemptCreationTimeoutCheck(f, true) {
log.Infof(logPfx +
klog.Infof(logPfx +
"Waiting ConfigMap to appear in the local cache or timeout")
return nil
}
@ -729,7 +729,7 @@ func (c *FrameworkController) syncFrameworkState(f *ci.Framework) (err error) {
"so consider it was deleted and force delete it",
common.SecToDuration(c.cConfig.ObjectLocalCacheCreationTimeoutSec))
code = ci.CompletionCodeConfigMapCreationTimeout
log.Warnf(logPfx + diag)
klog.Warningf(logPfx + diag)
}
// Ensure cm is deleted in remote to avoid managed cm leak after
@ -746,7 +746,7 @@ func (c *FrameworkController) syncFrameworkState(f *ci.Framework) (err error) {
if f.Status.State != ci.FrameworkAttemptCreationPending {
if f.Status.AttemptStatus.CompletionStatus == nil {
diag := fmt.Sprintf("ConfigMap was deleted by others")
log.Warnf(logPfx + diag)
klog.Warningf(logPfx + diag)
c.completeFrameworkAttempt(f, true,
ci.CompletionCodeConfigMapExternalDeleted.NewCompletionStatus(diag))
} else {
@ -773,7 +773,7 @@ func (c *FrameworkController) syncFrameworkState(f *ci.Framework) (err error) {
if f.Status.State == ci.FrameworkAttemptDeletionRequested {
// The deletion requested object will never appear again with the same UID,
// so always just wait.
log.Infof(logPfx +
klog.Infof(logPfx +
"Waiting ConfigMap to disappearing or disappear in the local cache")
} else {
// At this point, f.Status.State must be in:
@ -787,13 +787,13 @@ func (c *FrameworkController) syncFrameworkState(f *ci.Framework) (err error) {
} else {
if f.Status.AttemptStatus.CompletionStatus == nil {
diag := fmt.Sprintf("ConfigMap is being deleted by others")
log.Warnf(logPfx + diag)
klog.Warningf(logPfx + diag)
f.Status.AttemptStatus.CompletionStatus =
ci.CompletionCodeConfigMapExternalDeleted.NewCompletionStatus(diag)
}
f.TransitionFrameworkState(ci.FrameworkAttemptDeleting)
log.Infof(logPfx + "Waiting ConfigMap to be deleted")
klog.Infof(logPfx + "Waiting ConfigMap to be deleted")
}
}
}
@ -814,14 +814,14 @@ func (c *FrameworkController) syncFrameworkState(f *ci.Framework) (err error) {
// RetryFramework is not yet scheduled, so need to be decided.
if retryDecision.ShouldRetry {
// scheduleToRetryFramework
log.Infof(logPfx+
klog.Infof(logPfx+
"Will retry Framework with new FrameworkAttempt: RetryDecision: %v",
retryDecision)
f.Status.RetryPolicyStatus.RetryDelaySec = &retryDecision.DelaySec
} else {
// completeFramework
log.Infof(logPfx+
klog.Infof(logPfx+
"Will complete Framework: RetryDecision: %v",
retryDecision)
@ -835,18 +835,18 @@ func (c *FrameworkController) syncFrameworkState(f *ci.Framework) (err error) {
// RetryFramework is already scheduled, so just need to check whether it
// should be executed now.
if f.Spec.ExecutionType == ci.ExecutionStop {
log.Infof(logPfx +
klog.Infof(logPfx +
"User has requested to stop the Framework, " +
"so immediately retry without delay")
} else {
if c.enqueueFrameworkRetryDelayTimeoutCheck(f, true) {
log.Infof(logPfx + "Waiting Framework to retry after delay")
klog.Infof(logPfx + "Waiting Framework to retry after delay")
return nil
}
}
// retryFramework
log.Infof(logPfx + "Retry Framework")
klog.Infof(logPfx + "Retry Framework")
f.Status.RetryPolicyStatus.TotalRetriedCount++
if retryDecision.IsAccountable {
f.Status.RetryPolicyStatus.AccountableRetriedCount++
@ -865,7 +865,7 @@ func (c *FrameworkController) syncFrameworkState(f *ci.Framework) (err error) {
if f.Status.State == ci.FrameworkAttemptCreationPending {
if f.Spec.ExecutionType == ci.ExecutionStop {
diag := fmt.Sprintf("User has requested to stop the Framework")
log.Infof(logPfx + diag)
klog.Infof(logPfx + diag)
// Ensure cm is deleted in remote to avoid managed cm leak after
// FrameworkAttemptCompleted.
@ -897,7 +897,7 @@ func (c *FrameworkController) syncFrameworkState(f *ci.Framework) (err error) {
// The ground truth cm is the local cached one instead of the remote one,
// so need to wait before continue the sync.
log.Infof(logPfx +
klog.Infof(logPfx +
"Waiting ConfigMap to appear in the local cache or timeout")
return nil
}
@ -912,7 +912,7 @@ func (c *FrameworkController) syncFrameworkState(f *ci.Framework) (err error) {
if !f.IsCompleting() {
if f.Spec.ExecutionType == ci.ExecutionStop {
diag := fmt.Sprintf("User has requested to stop the Framework")
log.Infof(logPfx + diag)
klog.Infof(logPfx + diag)
c.completeFrameworkAttempt(f, false,
ci.CompletionCodeStopFrameworkRequested.NewCompletionStatus(diag))
}
@ -1026,7 +1026,7 @@ func (c *FrameworkController) deleteConfigMap(
}
}
log.Infof(
klog.Infof(
"[%v]: Succeeded to delete ConfigMap %v, %v: force: %v",
f.Key(), cmName, cmUID, force)
return nil
@ -1055,7 +1055,7 @@ func (c *FrameworkController) createConfigMap(
return nil, fmt.Errorf(errPfx+"%v", createErr)
} else {
log.Infof(
klog.Infof(
"[%v]: Succeeded to create ConfigMap %v",
f.Key(), cm.Name)
return remoteCM, nil
@ -1065,12 +1065,12 @@ func (c *FrameworkController) createConfigMap(
func (c *FrameworkController) syncTaskRoleStatuses(
f *ci.Framework, cm *core.ConfigMap) (err error) {
logPfx := fmt.Sprintf("[%v]: syncTaskRoleStatuses: ", f.Key())
log.Infof(logPfx + "Started")
defer func() { log.Infof(logPfx + "Completed") }()
klog.Infof(logPfx + "Started")
defer func() { klog.Infof(logPfx + "Completed") }()
errs := []error{}
for _, taskRoleStatus := range f.TaskRoleStatuses() {
log.Infof("[%v][%v]: syncTaskRoleStatus", f.Key(), taskRoleStatus.Name)
klog.Infof("[%v][%v]: syncTaskRoleStatus", f.Key(), taskRoleStatus.Name)
for _, taskStatus := range taskRoleStatus.TaskStatuses {
// At this point, f.Status.State must be in:
// {FrameworkAttemptPreparing, FrameworkAttemptRunning,
@ -1091,8 +1091,8 @@ func (c *FrameworkController) syncTaskState(
taskRoleName string, taskIndex int32) (err error) {
logPfx := fmt.Sprintf("[%v][%v][%v]: syncTaskState: ",
f.Key(), taskRoleName, taskIndex)
log.Infof(logPfx + "Started")
defer func() { log.Infof(logPfx + "Completed") }()
klog.Infof(logPfx + "Started")
defer func() { klog.Infof(logPfx + "Completed") }()
taskRoleSpec := f.TaskRoleSpec(taskRoleName)
taskSpec := taskRoleSpec.Task
@ -1106,7 +1106,7 @@ func (c *FrameworkController) syncTaskState(
// but the FrameworkAttemptDeletionPending is not persisted, the TaskCompleted
// should have already triggered and persisted FrameworkAttemptDeletionPending
// in previous sync, so current sync should have already been skipped but not.
log.Infof(logPfx + "Skipped: Task is already completed")
klog.Infof(logPfx + "Skipped: Task is already completed")
return nil
}
@ -1124,7 +1124,7 @@ func (c *FrameworkController) syncTaskState(
// pod is remote creation requested but not found in the local cache.
if taskStatus.State == ci.TaskAttemptCreationRequested {
if c.enqueueTaskAttemptCreationTimeoutCheck(f, taskRoleName, taskIndex, true) {
log.Infof(logPfx +
klog.Infof(logPfx +
"Waiting Pod to appear in the local cache or timeout")
return nil
}
@ -1133,7 +1133,7 @@ func (c *FrameworkController) syncTaskState(
"Pod does not appear in the local cache within timeout %v, "+
"so consider it was deleted and force delete it",
common.SecToDuration(c.cConfig.ObjectLocalCacheCreationTimeoutSec))
log.Warnf(logPfx + diag)
klog.Warningf(logPfx + diag)
// Ensure pod is deleted in remote to avoid managed pod leak after
// TaskAttemptCompleted.
@ -1150,7 +1150,7 @@ func (c *FrameworkController) syncTaskState(
if taskStatus.State != ci.TaskAttemptCreationPending {
if taskStatus.AttemptStatus.CompletionStatus == nil {
diag := fmt.Sprintf("Pod was deleted by others")
log.Warnf(logPfx + diag)
klog.Warningf(logPfx + diag)
c.completeTaskAttempt(f, taskRoleName, taskIndex, true,
ci.CompletionCodePodExternalDeleted.NewCompletionStatus(diag))
} else {
@ -1177,7 +1177,7 @@ func (c *FrameworkController) syncTaskState(
if taskStatus.State == ci.TaskAttemptDeletionRequested {
// The deletion requested object will never appear again with the same UID,
// so always just wait.
log.Infof(logPfx +
klog.Infof(logPfx +
"Waiting Pod to disappearing or disappear in the local cache")
return nil
}
@ -1195,7 +1195,7 @@ func (c *FrameworkController) syncTaskState(
// it will only be automatically deleted after the kubelet comes back and
// kills the Pod.
if pod.Status.Phase == core.PodUnknown {
log.Infof(logPfx+
klog.Infof(logPfx+
"Waiting Pod to be deleted or deleting or transitioned from %v",
pod.Status.Phase)
return nil
@ -1214,7 +1214,7 @@ func (c *FrameworkController) syncTaskState(
return nil
} else if pod.Status.Phase == core.PodSucceeded {
diag := fmt.Sprintf("Pod succeeded")
log.Infof(logPfx + diag)
klog.Infof(logPfx + diag)
c.completeTaskAttempt(f, taskRoleName, taskIndex, false,
ci.CompletionCodeSucceeded.NewCompletionStatus(diag))
return nil
@ -1248,14 +1248,14 @@ func (c *FrameworkController) syncTaskState(
diag := fmt.Sprintf(
"Pod failed without any non-zero container exit code, maybe " +
"stopped by the system")
log.Warnf(logPfx + diag)
klog.Warningf(logPfx + diag)
c.completeTaskAttempt(f, taskRoleName, taskIndex, false,
ci.CompletionCodePodFailedWithoutFailedContainer.NewCompletionStatus(diag))
} else {
diag := fmt.Sprintf(
"Pod failed with non-zero container exit code: %v",
strings.Join(allContainerDiags, ", "))
log.Infof(logPfx + diag)
klog.Infof(logPfx + diag)
if strings.Contains(diag, string(ci.ReasonOOMKilled)) {
c.completeTaskAttempt(f, taskRoleName, taskIndex, false,
ci.CompletionCodeContainerOOMKilled.NewCompletionStatus(diag))
@ -1272,13 +1272,13 @@ func (c *FrameworkController) syncTaskState(
} else {
if taskStatus.AttemptStatus.CompletionStatus == nil {
diag := fmt.Sprintf("Pod is being deleted by others")
log.Warnf(logPfx + diag)
klog.Warningf(logPfx + diag)
taskStatus.AttemptStatus.CompletionStatus =
ci.CompletionCodePodExternalDeleted.NewCompletionStatus(diag)
}
f.TransitionTaskState(taskRoleName, taskIndex, ci.TaskAttemptDeleting)
log.Infof(logPfx + "Waiting Pod to be deleted")
klog.Infof(logPfx + "Waiting Pod to be deleted")
return nil
}
}
@ -1297,14 +1297,14 @@ func (c *FrameworkController) syncTaskState(
// RetryTask is not yet scheduled, so need to be decided.
if retryDecision.ShouldRetry {
// scheduleToRetryTask
log.Infof(logPfx+
klog.Infof(logPfx+
"Will retry Task with new TaskAttempt: RetryDecision: %v",
retryDecision)
taskStatus.RetryPolicyStatus.RetryDelaySec = &retryDecision.DelaySec
} else {
// completeTask
log.Infof(logPfx+
klog.Infof(logPfx+
"Will complete Task: RetryDecision: %v",
retryDecision)
@ -1317,12 +1317,12 @@ func (c *FrameworkController) syncTaskState(
// RetryTask is already scheduled, so just need to check whether it
// should be executed now.
if c.enqueueTaskRetryDelayTimeoutCheck(f, taskRoleName, taskIndex, true) {
log.Infof(logPfx + "Waiting Task to retry after delay")
klog.Infof(logPfx + "Waiting Task to retry after delay")
return nil
}
// retryTask
log.Infof(logPfx + "Retry Task")
klog.Infof(logPfx + "Retry Task")
taskStatus.RetryPolicyStatus.TotalRetriedCount++
if retryDecision.IsAccountable {
taskStatus.RetryPolicyStatus.AccountableRetriedCount++
@ -1338,7 +1338,7 @@ func (c *FrameworkController) syncTaskState(
if taskStatus.State == ci.TaskAttemptCreationPending {
if f.IsCompleting() {
log.Infof(logPfx + "Skip to createTaskAttempt: " +
klog.Infof(logPfx + "Skip to createTaskAttempt: " +
"FrameworkAttempt is completing")
return nil
}
@ -1353,7 +1353,7 @@ func (c *FrameworkController) syncTaskState(
"Pod Spec is invalid in TaskRole [%v]: "+
"Triggered by Task [%v][%v]: Diagnostics: %v",
taskRoleName, taskRoleName, taskIndex, apiErr)
log.Infof(logPfx + diag)
klog.Infof(logPfx + diag)
// Ensure pod is deleted in remote to avoid managed pod leak after
// TaskAttemptCompleted.
@ -1382,7 +1382,7 @@ func (c *FrameworkController) syncTaskState(
// The ground truth pod is the local cached one instead of the remote one,
// so need to wait before continue the sync.
log.Infof(logPfx +
klog.Infof(logPfx +
"Waiting Pod to appear in the local cache or timeout")
return nil
}
@ -1391,7 +1391,7 @@ func (c *FrameworkController) syncTaskState(
if taskStatus.State == ci.TaskCompleted {
if f.IsCompleting() {
log.Infof(logPfx + "Skip to attemptToCompleteFrameworkAttempt: " +
klog.Infof(logPfx + "Skip to attemptToCompleteFrameworkAttempt: " +
"FrameworkAttempt is completing")
return nil
}
@ -1409,7 +1409,7 @@ func (c *FrameworkController) syncTaskState(
"Triggered by Task [%v][%v]: Diagnostics: %v",
failedTaskCount, minFailedTaskCount, taskRoleName,
taskRoleName, taskIndex, taskStatus.AttemptStatus.CompletionStatus.Diagnostics)
log.Infof(logPfx + diag)
klog.Infof(logPfx + diag)
c.completeFrameworkAttempt(f, false,
taskStatus.AttemptStatus.CompletionStatus.Code.NewCompletionStatus(diag))
return nil
@ -1424,7 +1424,7 @@ func (c *FrameworkController) syncTaskState(
"Triggered by Task [%v][%v]: Diagnostics: %v",
succeededTaskCount, minSucceededTaskCount, taskRoleName,
taskRoleName, taskIndex, taskStatus.AttemptStatus.CompletionStatus.Diagnostics)
log.Infof(logPfx + diag)
klog.Infof(logPfx + diag)
c.completeFrameworkAttempt(f, false,
ci.CompletionCodeSucceeded.NewCompletionStatus(diag))
return nil
@ -1441,7 +1441,7 @@ func (c *FrameworkController) syncTaskState(
"Triggered by Task [%v][%v]: Diagnostics: %v",
totalTaskCount, failedTaskCount,
taskRoleName, taskIndex, taskStatus.AttemptStatus.CompletionStatus.Diagnostics)
log.Infof(logPfx + diag)
klog.Infof(logPfx + diag)
c.completeFrameworkAttempt(f, false,
ci.CompletionCodeSucceeded.NewCompletionStatus(diag))
return nil
@ -1545,7 +1545,7 @@ func (c *FrameworkController) deletePod(
}
}
log.Infof(
klog.Infof(
"[%v][%v][%v]: Succeeded to delete Pod %v, %v: force: %v",
f.Key(), taskRoleName, taskIndex, podName, podUID, force)
return nil
@ -1575,7 +1575,7 @@ func (c *FrameworkController) createPod(
return nil, errorWrap.Wrapf(createErr, errPfx)
} else {
log.Infof(
klog.Infof(
"[%v][%v][%v]: Succeeded to create Pod %v",
f.Key(), taskRoleName, taskIndex, pod.Name)
return remotePod, nil
@ -1600,18 +1600,18 @@ func (c *FrameworkController) completeTaskAttempt(
f.TransitionTaskState(taskRoleName, taskIndex, ci.TaskAttemptCompleted)
if taskStatus.TaskAttemptInstanceUID() == nil {
log.Infof(logPfx+
klog.Infof(logPfx+
"TaskAttempt %v is completed with CompletionStatus: %v",
taskStatus.TaskAttemptID(), taskStatus.AttemptStatus.CompletionStatus)
} else {
log.Infof(logPfx+
klog.Infof(logPfx+
"TaskAttemptInstance %v is completed with CompletionStatus: %v",
*taskStatus.TaskAttemptInstanceUID(), taskStatus.AttemptStatus.CompletionStatus)
}
// To ensure the completed TaskAttempt is persisted before exposed,
// we need to wait until next sync to expose it, so manually enqueue a sync.
log.Infof(logPfx + "Waiting the completed TaskAttempt to be persisted")
klog.Infof(logPfx + "Waiting the completed TaskAttempt to be persisted")
c.enqueueFramework(f, "TaskAttemptCompleted")
} else {
f.TransitionTaskState(taskRoleName, taskIndex, ci.TaskAttemptDeletionPending)
@ -1619,7 +1619,7 @@ func (c *FrameworkController) completeTaskAttempt(
// To ensure the CompletionStatus is persisted before deleting the pod,
// we need to wait until next sync to delete the pod, so manually enqueue
// a sync.
log.Infof(logPfx + "Waiting the CompletionStatus to be persisted")
klog.Infof(logPfx + "Waiting the CompletionStatus to be persisted")
c.enqueueFramework(f, "TaskAttemptDeletionPending")
}
}
@ -1664,18 +1664,18 @@ func (c *FrameworkController) completeFrameworkAttempt(
f.TransitionFrameworkState(ci.FrameworkAttemptCompleted)
if f.FrameworkAttemptInstanceUID() == nil {
log.Infof(logPfx+
klog.Infof(logPfx+
"FrameworkAttempt %v is completed with CompletionStatus: %v",
f.FrameworkAttemptID(), f.Status.AttemptStatus.CompletionStatus)
} else {
log.Infof(logPfx+
klog.Infof(logPfx+
"FrameworkAttemptInstance %v is completed with CompletionStatus: %v",
*f.FrameworkAttemptInstanceUID(), f.Status.AttemptStatus.CompletionStatus)
}
// To ensure the completed FrameworkAttempt is persisted before exposed,
// we need to wait until next sync to expose it, so manually enqueue a sync.
log.Infof(logPfx + "Waiting the completed FrameworkAttempt to be persisted")
klog.Infof(logPfx + "Waiting the completed FrameworkAttempt to be persisted")
c.enqueueFramework(f, "FrameworkAttemptCompleted")
} else {
f.TransitionFrameworkState(ci.FrameworkAttemptDeletionPending)
@ -1683,15 +1683,15 @@ func (c *FrameworkController) completeFrameworkAttempt(
// To ensure the CompletionStatus is persisted before deleting the cm,
// we need to wait until next sync to delete the cm, so manually enqueue
// a sync.
log.Infof(logPfx + "Waiting the CompletionStatus to be persisted")
klog.Infof(logPfx + "Waiting the CompletionStatus to be persisted")
c.enqueueFramework(f, "FrameworkAttemptDeletionPending")
}
}
func (c *FrameworkController) updateRemoteFrameworkStatus(f *ci.Framework) error {
logPfx := fmt.Sprintf("[%v]: updateRemoteFrameworkStatus: ", f.Key())
log.Infof(logPfx + "Started")
defer func() { log.Infof(logPfx + "Completed") }()
klog.Infof(logPfx + "Started")
defer func() { klog.Infof(logPfx + "Completed") }()
tried := false
updateErr := retry.RetryOnConflict(retry.DefaultRetry, func() error {
@ -1745,13 +1745,13 @@ func (c *FrameworkController) getExpectedFrameworkStatusInfo(key string) *Expect
}
func (c *FrameworkController) deleteExpectedFrameworkStatusInfo(key string) {
log.Infof("[%v]: deleteExpectedFrameworkStatusInfo: ", key)
klog.Infof("[%v]: deleteExpectedFrameworkStatusInfo: ", key)
c.fExpectedStatusInfos.Delete(key)
}
func (c *FrameworkController) updateExpectedFrameworkStatusInfo(key string,
status *ci.FrameworkStatus, remoteSynced bool) {
log.Infof("[%v]: updateExpectedFrameworkStatusInfo", key)
klog.Infof("[%v]: updateExpectedFrameworkStatusInfo", key)
c.fExpectedStatusInfos.Store(key, &ExpectedFrameworkStatusInfo{
status: status,
remoteSynced: remoteSynced,

Просмотреть файл

@ -20,21 +20,40 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE
package util
package internal
import (
"fmt"
frameworkClient "github.com/microsoft/frameworkcontroller/pkg/client/clientset/versioned"
"github.com/microsoft/frameworkcontroller/pkg/common"
log "github.com/sirupsen/logrus"
core "k8s.io/api/core/v1"
apiExtensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
apiClient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
apiErrors "k8s.io/apimachinery/pkg/api/errors"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
kubeClient "k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/cache"
"k8s.io/klog"
"reflect"
)
func CreateClients(kConfig *rest.Config) (
kubeClient.Interface, frameworkClient.Interface) {
kClient, err := kubeClient.NewForConfig(kConfig)
if err != nil {
panic(fmt.Errorf("Failed to create KubeClient: %v", err))
}
fClient, err := frameworkClient.NewForConfig(kConfig)
if err != nil {
panic(fmt.Errorf("Failed to create FrameworkClient: %v", err))
}
return kClient, fClient
}
func PutCRD(
config *rest.Config, crd *apiExtensions.CustomResourceDefinition,
establishedCheckIntervalSec *int64, establishedCheckTimeoutSec *int64) {
@ -44,7 +63,7 @@ func PutCRD(
if err != nil {
panic(fmt.Errorf("Failed to put CRD: %v", err))
} else {
log.Infof("Succeeded to put CRD")
klog.Infof("Succeeded to put CRD")
}
}
@ -55,7 +74,7 @@ func DeleteCRD(config *rest.Config, name string) {
if err != nil && !apiErrors.IsNotFound(err) {
panic(fmt.Errorf("Failed to delete CRD: %v", err))
} else {
log.Infof("Succeeded to delete CRD")
klog.Infof("Succeeded to delete CRD")
}
}
@ -74,7 +93,7 @@ func putCRDInternal(
remoteCRD, err := client.ApiextensionsV1beta1().CustomResourceDefinitions().Get(newCRD.Name, meta.GetOptions{})
if err == nil {
log.Infof("Update CRD %v", newCRD.Name)
klog.Infof("Update CRD %v", newCRD.Name)
if !reflect.DeepEqual(remoteCRD.Spec, newCRD.Spec) {
updateCRD := remoteCRD
updateCRD.Spec = newCRD.Spec
@ -84,7 +103,7 @@ func putCRDInternal(
}
}
} else if apiErrors.IsNotFound(err) {
log.Infof("Create CRD %v", newCRD.Name)
klog.Infof("Create CRD %v", newCRD.Name)
remoteCRD, err = client.ApiextensionsV1beta1().CustomResourceDefinitions().Create(newCRD)
if err != nil {
return err
@ -117,3 +136,61 @@ func isCRDEstablished(crd *apiExtensions.CustomResourceDefinition) bool {
}
return false
}
func GetKey(obj interface{}) (string, error) {
return cache.DeletionHandlingMetaNamespaceKeyFunc(obj)
}
func SplitKey(key string) (namespace, name string, err error) {
return cache.SplitMetaNamespaceKey(key)
}
// obj could be *core.ConfigMap or cache.DeletedFinalStateUnknown.
func ToConfigMap(obj interface{}) *core.ConfigMap {
cm, ok := obj.(*core.ConfigMap)
if !ok {
deletedFinalStateUnknown, ok := obj.(cache.DeletedFinalStateUnknown)
if !ok {
klog.Errorf(
"Failed to convert obj to ConfigMap or DeletedFinalStateUnknown: %#v",
obj)
return nil
}
cm, ok = deletedFinalStateUnknown.Obj.(*core.ConfigMap)
if !ok {
klog.Errorf(
"Failed to convert DeletedFinalStateUnknown.Obj to ConfigMap: %#v",
deletedFinalStateUnknown)
return nil
}
}
return cm
}
// obj could be *core.Pod or cache.DeletedFinalStateUnknown.
func ToPod(obj interface{}) *core.Pod {
pod, ok := obj.(*core.Pod)
if !ok {
deletedFinalStateUnknown, ok := obj.(cache.DeletedFinalStateUnknown)
if !ok {
klog.Errorf(
"Failed to convert obj to Pod or DeletedFinalStateUnknown: %#v",
obj)
return nil
}
pod, ok = deletedFinalStateUnknown.Obj.(*core.Pod)
if !ok {
klog.Errorf(
"Failed to convert DeletedFinalStateUnknown.Obj to Pod: %#v",
deletedFinalStateUnknown)
return nil
}
}
return pod
}

Просмотреть файл

@ -1,106 +0,0 @@
// MIT License
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE
package util
import (
"fmt"
frameworkClient "github.com/microsoft/frameworkcontroller/pkg/client/clientset/versioned"
log "github.com/sirupsen/logrus"
core "k8s.io/api/core/v1"
kubeClient "k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/cache"
)
func CreateClients(kConfig *rest.Config) (
kubeClient.Interface, frameworkClient.Interface) {
kClient, err := kubeClient.NewForConfig(kConfig)
if err != nil {
panic(fmt.Errorf("Failed to create KubeClient: %v", err))
}
fClient, err := frameworkClient.NewForConfig(kConfig)
if err != nil {
panic(fmt.Errorf("Failed to create FrameworkClient: %v", err))
}
return kClient, fClient
}
func GetKey(obj interface{}) (string, error) {
return cache.DeletionHandlingMetaNamespaceKeyFunc(obj)
}
func SplitKey(key string) (namespace, name string, err error) {
return cache.SplitMetaNamespaceKey(key)
}
// obj could be *core.ConfigMap or cache.DeletedFinalStateUnknown.
func ToConfigMap(obj interface{}) *core.ConfigMap {
cm, ok := obj.(*core.ConfigMap)
if !ok {
deletedFinalStateUnknown, ok := obj.(cache.DeletedFinalStateUnknown)
if !ok {
log.Errorf(
"Failed to convert obj to ConfigMap or DeletedFinalStateUnknown: %#v",
obj)
return nil
}
cm, ok = deletedFinalStateUnknown.Obj.(*core.ConfigMap)
if !ok {
log.Errorf(
"Failed to convert DeletedFinalStateUnknown.Obj to ConfigMap: %#v",
deletedFinalStateUnknown)
return nil
}
}
return cm
}
// obj could be *core.Pod or cache.DeletedFinalStateUnknown.
func ToPod(obj interface{}) *core.Pod {
pod, ok := obj.(*core.Pod)
if !ok {
deletedFinalStateUnknown, ok := obj.(cache.DeletedFinalStateUnknown)
if !ok {
log.Errorf(
"Failed to convert obj to Pod or DeletedFinalStateUnknown: %#v",
obj)
return nil
}
pod, ok = deletedFinalStateUnknown.Obj.(*core.Pod)
if !ok {
log.Errorf(
"Failed to convert DeletedFinalStateUnknown.Obj to Pod: %#v",
deletedFinalStateUnknown)
return nil
}
}
return pod
}

9
vendor/github.com/konsorten/go-windows-terminal-sequences/LICENSE сгенерированный поставляемый
Просмотреть файл

@ -1,9 +0,0 @@
(The MIT License)
Copyright (c) 2017 marvin + konsorten GmbH (open-source@konsorten.de)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

36
vendor/github.com/konsorten/go-windows-terminal-sequences/sequences.go сгенерированный поставляемый
Просмотреть файл

@ -1,36 +0,0 @@
// +build windows
package sequences
import (
"syscall"
"unsafe"
)
var (
kernel32Dll *syscall.LazyDLL = syscall.NewLazyDLL("Kernel32.dll")
setConsoleMode *syscall.LazyProc = kernel32Dll.NewProc("SetConsoleMode")
)
func EnableVirtualTerminalProcessing(stream syscall.Handle, enable bool) error {
const ENABLE_VIRTUAL_TERMINAL_PROCESSING uint32 = 0x4
var mode uint32
err := syscall.GetConsoleMode(syscall.Stdout, &mode)
if err != nil {
return err
}
if enable {
mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING
} else {
mode &^= ENABLE_VIRTUAL_TERMINAL_PROCESSING
}
ret, _, err := setConsoleMode.Call(uintptr(unsafe.Pointer(stream)), uintptr(mode))
if ret == 0 {
return err
}
return nil
}

11
vendor/github.com/konsorten/go-windows-terminal-sequences/sequences_dummy.go сгенерированный поставляемый
Просмотреть файл

@ -1,11 +0,0 @@
// +build linux darwin
package sequences
import (
"fmt"
)
func EnableVirtualTerminalProcessing(stream uintptr, enable bool) error {
return fmt.Errorf("windows only package")
}

21
vendor/github.com/sirupsen/logrus/LICENSE сгенерированный поставляемый
Просмотреть файл

@ -1,21 +0,0 @@
The MIT License (MIT)
Copyright (c) 2014 Simon Eskildsen
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

76
vendor/github.com/sirupsen/logrus/alt_exit.go сгенерированный поставляемый
Просмотреть файл

@ -1,76 +0,0 @@
package logrus
// The following code was sourced and modified from the
// https://github.com/tebeka/atexit package governed by the following license:
//
// Copyright (c) 2012 Miki Tebeka <miki.tebeka@gmail.com>.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import (
"fmt"
"os"
)
var handlers = []func(){}
func runHandler(handler func()) {
defer func() {
if err := recover(); err != nil {
fmt.Fprintln(os.Stderr, "Error: Logrus exit handler error:", err)
}
}()
handler()
}
func runHandlers() {
for _, handler := range handlers {
runHandler(handler)
}
}
// Exit runs all the Logrus atexit handlers and then terminates the program using os.Exit(code)
func Exit(code int) {
runHandlers()
os.Exit(code)
}
// RegisterExitHandler appends a Logrus Exit handler to the list of handlers,
// call logrus.Exit to invoke all handlers. The handlers will also be invoked when
// any Fatal log entry is made.
//
// This method is useful when a caller wishes to use logrus to log a fatal
// message but also needs to gracefully shutdown. An example usecase could be
// closing database connections, or sending a alert that the application is
// closing.
func RegisterExitHandler(handler func()) {
handlers = append(handlers, handler)
}
// DeferExitHandler prepends a Logrus Exit handler to the list of handlers,
// call logrus.Exit to invoke all handlers. The handlers will also be invoked when
// any Fatal log entry is made.
//
// This method is useful when a caller wishes to use logrus to log a fatal
// message but also needs to gracefully shutdown. An example usecase could be
// closing database connections, or sending a alert that the application is
// closing.
func DeferExitHandler(handler func()) {
handlers = append([]func(){handler}, handlers...)
}

26
vendor/github.com/sirupsen/logrus/doc.go сгенерированный поставляемый
Просмотреть файл

@ -1,26 +0,0 @@
/*
Package logrus is a structured logger for Go, completely API compatible with the standard library logger.
The simplest way to use Logrus is simply the package-level exported logger:
package main
import (
log "github.com/sirupsen/logrus"
)
func main() {
log.WithFields(log.Fields{
"animal": "walrus",
"number": 1,
"size": 10,
}).Info("A walrus appears")
}
Output:
time="2015-09-07T08:48:33Z" level=info msg="A walrus appears" animal=walrus number=1 size=10
For a full guide visit https://github.com/sirupsen/logrus
*/
package logrus

407
vendor/github.com/sirupsen/logrus/entry.go сгенерированный поставляемый
Просмотреть файл

@ -1,407 +0,0 @@
package logrus
import (
"bytes"
"context"
"fmt"
"os"
"reflect"
"runtime"
"strings"
"sync"
"time"
)
var (
bufferPool *sync.Pool
// qualified package name, cached at first use
logrusPackage string
// Positions in the call stack when tracing to report the calling method
minimumCallerDepth int
// Used for caller information initialisation
callerInitOnce sync.Once
)
const (
maximumCallerDepth int = 25
knownLogrusFrames int = 4
)
func init() {
bufferPool = &sync.Pool{
New: func() interface{} {
return new(bytes.Buffer)
},
}
// start at the bottom of the stack before the package-name cache is primed
minimumCallerDepth = 1
}
// Defines the key when adding errors using WithError.
var ErrorKey = "error"
// An entry is the final or intermediate Logrus logging entry. It contains all
// the fields passed with WithField{,s}. It's finally logged when Trace, Debug,
// Info, Warn, Error, Fatal or Panic is called on it. These objects can be
// reused and passed around as much as you wish to avoid field duplication.
type Entry struct {
Logger *Logger
// Contains all the fields set by the user.
Data Fields
// Time at which the log entry was created
Time time.Time
// Level the log entry was logged at: Trace, Debug, Info, Warn, Error, Fatal or Panic
// This field will be set on entry firing and the value will be equal to the one in Logger struct field.
Level Level
// Calling method, with package name
Caller *runtime.Frame
// Message passed to Trace, Debug, Info, Warn, Error, Fatal or Panic
Message string
// When formatter is called in entry.log(), a Buffer may be set to entry
Buffer *bytes.Buffer
// Contains the context set by the user. Useful for hook processing etc.
Context context.Context
// err may contain a field formatting error
err string
}
func NewEntry(logger *Logger) *Entry {
return &Entry{
Logger: logger,
// Default is three fields, plus one optional. Give a little extra room.
Data: make(Fields, 6),
}
}
// Returns the string representation from the reader and ultimately the
// formatter.
func (entry *Entry) String() (string, error) {
serialized, err := entry.Logger.Formatter.Format(entry)
if err != nil {
return "", err
}
str := string(serialized)
return str, nil
}
// Add an error as single field (using the key defined in ErrorKey) to the Entry.
func (entry *Entry) WithError(err error) *Entry {
return entry.WithField(ErrorKey, err)
}
// Add a context to the Entry.
func (entry *Entry) WithContext(ctx context.Context) *Entry {
return &Entry{Logger: entry.Logger, Data: entry.Data, Time: entry.Time, err: entry.err, Context: ctx}
}
// Add a single field to the Entry.
func (entry *Entry) WithField(key string, value interface{}) *Entry {
return entry.WithFields(Fields{key: value})
}
// Add a map of fields to the Entry.
func (entry *Entry) WithFields(fields Fields) *Entry {
data := make(Fields, len(entry.Data)+len(fields))
for k, v := range entry.Data {
data[k] = v
}
fieldErr := entry.err
for k, v := range fields {
isErrField := false
if t := reflect.TypeOf(v); t != nil {
switch t.Kind() {
case reflect.Func:
isErrField = true
case reflect.Ptr:
isErrField = t.Elem().Kind() == reflect.Func
}
}
if isErrField {
tmp := fmt.Sprintf("can not add field %q", k)
if fieldErr != "" {
fieldErr = entry.err + ", " + tmp
} else {
fieldErr = tmp
}
} else {
data[k] = v
}
}
return &Entry{Logger: entry.Logger, Data: data, Time: entry.Time, err: fieldErr, Context: entry.Context}
}
// Overrides the time of the Entry.
func (entry *Entry) WithTime(t time.Time) *Entry {
return &Entry{Logger: entry.Logger, Data: entry.Data, Time: t, err: entry.err, Context: entry.Context}
}
// getPackageName reduces a fully qualified function name to the package name
// There really ought to be to be a better way...
func getPackageName(f string) string {
for {
lastPeriod := strings.LastIndex(f, ".")
lastSlash := strings.LastIndex(f, "/")
if lastPeriod > lastSlash {
f = f[:lastPeriod]
} else {
break
}
}
return f
}
// getCaller retrieves the name of the first non-logrus calling function
func getCaller() *runtime.Frame {
// cache this package's fully-qualified name
callerInitOnce.Do(func() {
pcs := make([]uintptr, 2)
_ = runtime.Callers(0, pcs)
logrusPackage = getPackageName(runtime.FuncForPC(pcs[1]).Name())
// now that we have the cache, we can skip a minimum count of known-logrus functions
// XXX this is dubious, the number of frames may vary
minimumCallerDepth = knownLogrusFrames
})
// Restrict the lookback frames to avoid runaway lookups
pcs := make([]uintptr, maximumCallerDepth)
depth := runtime.Callers(minimumCallerDepth, pcs)
frames := runtime.CallersFrames(pcs[:depth])
for f, again := frames.Next(); again; f, again = frames.Next() {
pkg := getPackageName(f.Function)
// If the caller isn't part of this package, we're done
if pkg != logrusPackage {
return &f
}
}
// if we got here, we failed to find the caller's context
return nil
}
func (entry Entry) HasCaller() (has bool) {
return entry.Logger != nil &&
entry.Logger.ReportCaller &&
entry.Caller != nil
}
// This function is not declared with a pointer value because otherwise
// race conditions will occur when using multiple goroutines
func (entry Entry) log(level Level, msg string) {
var buffer *bytes.Buffer
// Default to now, but allow users to override if they want.
//
// We don't have to worry about polluting future calls to Entry#log()
// with this assignment because this function is declared with a
// non-pointer receiver.
if entry.Time.IsZero() {
entry.Time = time.Now()
}
entry.Level = level
entry.Message = msg
if entry.Logger.ReportCaller {
entry.Caller = getCaller()
}
entry.fireHooks()
buffer = bufferPool.Get().(*bytes.Buffer)
buffer.Reset()
defer bufferPool.Put(buffer)
entry.Buffer = buffer
entry.write()
entry.Buffer = nil
// To avoid Entry#log() returning a value that only would make sense for
// panic() to use in Entry#Panic(), we avoid the allocation by checking
// directly here.
if level <= PanicLevel {
panic(&entry)
}
}
func (entry *Entry) fireHooks() {
entry.Logger.mu.Lock()
defer entry.Logger.mu.Unlock()
err := entry.Logger.Hooks.Fire(entry.Level, entry)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to fire hook: %v\n", err)
}
}
func (entry *Entry) write() {
entry.Logger.mu.Lock()
defer entry.Logger.mu.Unlock()
serialized, err := entry.Logger.Formatter.Format(entry)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to obtain reader, %v\n", err)
} else {
_, err = entry.Logger.Out.Write(serialized)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to write to log, %v\n", err)
}
}
}
func (entry *Entry) Log(level Level, args ...interface{}) {
if entry.Logger.IsLevelEnabled(level) {
entry.log(level, fmt.Sprint(args...))
}
}
func (entry *Entry) Trace(args ...interface{}) {
entry.Log(TraceLevel, args...)
}
func (entry *Entry) Debug(args ...interface{}) {
entry.Log(DebugLevel, args...)
}
func (entry *Entry) Print(args ...interface{}) {
entry.Info(args...)
}
func (entry *Entry) Info(args ...interface{}) {
entry.Log(InfoLevel, args...)
}
func (entry *Entry) Warn(args ...interface{}) {
entry.Log(WarnLevel, args...)
}
func (entry *Entry) Warning(args ...interface{}) {
entry.Warn(args...)
}
func (entry *Entry) Error(args ...interface{}) {
entry.Log(ErrorLevel, args...)
}
func (entry *Entry) Fatal(args ...interface{}) {
entry.Log(FatalLevel, args...)
entry.Logger.Exit(1)
}
func (entry *Entry) Panic(args ...interface{}) {
entry.Log(PanicLevel, args...)
panic(fmt.Sprint(args...))
}
// Entry Printf family functions
func (entry *Entry) Logf(level Level, format string, args ...interface{}) {
if entry.Logger.IsLevelEnabled(level) {
entry.Log(level, fmt.Sprintf(format, args...))
}
}
func (entry *Entry) Tracef(format string, args ...interface{}) {
entry.Logf(TraceLevel, format, args...)
}
func (entry *Entry) Debugf(format string, args ...interface{}) {
entry.Logf(DebugLevel, format, args...)
}
func (entry *Entry) Infof(format string, args ...interface{}) {
entry.Logf(InfoLevel, format, args...)
}
func (entry *Entry) Printf(format string, args ...interface{}) {
entry.Infof(format, args...)
}
func (entry *Entry) Warnf(format string, args ...interface{}) {
entry.Logf(WarnLevel, format, args...)
}
func (entry *Entry) Warningf(format string, args ...interface{}) {
entry.Warnf(format, args...)
}
func (entry *Entry) Errorf(format string, args ...interface{}) {
entry.Logf(ErrorLevel, format, args...)
}
func (entry *Entry) Fatalf(format string, args ...interface{}) {
entry.Logf(FatalLevel, format, args...)
entry.Logger.Exit(1)
}
func (entry *Entry) Panicf(format string, args ...interface{}) {
entry.Logf(PanicLevel, format, args...)
}
// Entry Println family functions
func (entry *Entry) Logln(level Level, args ...interface{}) {
if entry.Logger.IsLevelEnabled(level) {
entry.Log(level, entry.sprintlnn(args...))
}
}
func (entry *Entry) Traceln(args ...interface{}) {
entry.Logln(TraceLevel, args...)
}
func (entry *Entry) Debugln(args ...interface{}) {
entry.Logln(DebugLevel, args...)
}
func (entry *Entry) Infoln(args ...interface{}) {
entry.Logln(InfoLevel, args...)
}
func (entry *Entry) Println(args ...interface{}) {
entry.Infoln(args...)
}
func (entry *Entry) Warnln(args ...interface{}) {
entry.Logln(WarnLevel, args...)
}
func (entry *Entry) Warningln(args ...interface{}) {
entry.Warnln(args...)
}
func (entry *Entry) Errorln(args ...interface{}) {
entry.Logln(ErrorLevel, args...)
}
func (entry *Entry) Fatalln(args ...interface{}) {
entry.Logln(FatalLevel, args...)
entry.Logger.Exit(1)
}
func (entry *Entry) Panicln(args ...interface{}) {
entry.Logln(PanicLevel, args...)
}
// Sprintlnn => Sprint no newline. This is to get the behavior of how
// fmt.Sprintln where spaces are always added between operands, regardless of
// their type. Instead of vendoring the Sprintln implementation to spare a
// string allocation, we do the simplest thing.
func (entry *Entry) sprintlnn(args ...interface{}) string {
msg := fmt.Sprintln(args...)
return msg[:len(msg)-1]
}

225
vendor/github.com/sirupsen/logrus/exported.go сгенерированный поставляемый
Просмотреть файл

@ -1,225 +0,0 @@
package logrus
import (
"context"
"io"
"time"
)
var (
// std is the name of the standard logger in stdlib `log`
std = New()
)
func StandardLogger() *Logger {
return std
}
// SetOutput sets the standard logger output.
func SetOutput(out io.Writer) {
std.SetOutput(out)
}
// SetFormatter sets the standard logger formatter.
func SetFormatter(formatter Formatter) {
std.SetFormatter(formatter)
}
// SetReportCaller sets whether the standard logger will include the calling
// method as a field.
func SetReportCaller(include bool) {
std.SetReportCaller(include)
}
// SetLevel sets the standard logger level.
func SetLevel(level Level) {
std.SetLevel(level)
}
// GetLevel returns the standard logger level.
func GetLevel() Level {
return std.GetLevel()
}
// IsLevelEnabled checks if the log level of the standard logger is greater than the level param
func IsLevelEnabled(level Level) bool {
return std.IsLevelEnabled(level)
}
// AddHook adds a hook to the standard logger hooks.
func AddHook(hook Hook) {
std.AddHook(hook)
}
// WithError creates an entry from the standard logger and adds an error to it, using the value defined in ErrorKey as key.
func WithError(err error) *Entry {
return std.WithField(ErrorKey, err)
}
// WithContext creates an entry from the standard logger and adds a context to it.
func WithContext(ctx context.Context) *Entry {
return std.WithContext(ctx)
}
// WithField creates an entry from the standard logger and adds a field to
// it. If you want multiple fields, use `WithFields`.
//
// Note that it doesn't log until you call Debug, Print, Info, Warn, Fatal
// or Panic on the Entry it returns.
func WithField(key string, value interface{}) *Entry {
return std.WithField(key, value)
}
// WithFields creates an entry from the standard logger and adds multiple
// fields to it. This is simply a helper for `WithField`, invoking it
// once for each field.
//
// Note that it doesn't log until you call Debug, Print, Info, Warn, Fatal
// or Panic on the Entry it returns.
func WithFields(fields Fields) *Entry {
return std.WithFields(fields)
}
// WithTime creats an entry from the standard logger and overrides the time of
// logs generated with it.
//
// Note that it doesn't log until you call Debug, Print, Info, Warn, Fatal
// or Panic on the Entry it returns.
func WithTime(t time.Time) *Entry {
return std.WithTime(t)
}
// Trace logs a message at level Trace on the standard logger.
func Trace(args ...interface{}) {
std.Trace(args...)
}
// Debug logs a message at level Debug on the standard logger.
func Debug(args ...interface{}) {
std.Debug(args...)
}
// Print logs a message at level Info on the standard logger.
func Print(args ...interface{}) {
std.Print(args...)
}
// Info logs a message at level Info on the standard logger.
func Info(args ...interface{}) {
std.Info(args...)
}
// Warn logs a message at level Warn on the standard logger.
func Warn(args ...interface{}) {
std.Warn(args...)
}
// Warning logs a message at level Warn on the standard logger.
func Warning(args ...interface{}) {
std.Warning(args...)
}
// Error logs a message at level Error on the standard logger.
func Error(args ...interface{}) {
std.Error(args...)
}
// Panic logs a message at level Panic on the standard logger.
func Panic(args ...interface{}) {
std.Panic(args...)
}
// Fatal logs a message at level Fatal on the standard logger then the process will exit with status set to 1.
func Fatal(args ...interface{}) {
std.Fatal(args...)
}
// Tracef logs a message at level Trace on the standard logger.
func Tracef(format string, args ...interface{}) {
std.Tracef(format, args...)
}
// Debugf logs a message at level Debug on the standard logger.
func Debugf(format string, args ...interface{}) {
std.Debugf(format, args...)
}
// Printf logs a message at level Info on the standard logger.
func Printf(format string, args ...interface{}) {
std.Printf(format, args...)
}
// Infof logs a message at level Info on the standard logger.
func Infof(format string, args ...interface{}) {
std.Infof(format, args...)
}
// Warnf logs a message at level Warn on the standard logger.
func Warnf(format string, args ...interface{}) {
std.Warnf(format, args...)
}
// Warningf logs a message at level Warn on the standard logger.
func Warningf(format string, args ...interface{}) {
std.Warningf(format, args...)
}
// Errorf logs a message at level Error on the standard logger.
func Errorf(format string, args ...interface{}) {
std.Errorf(format, args...)
}
// Panicf logs a message at level Panic on the standard logger.
func Panicf(format string, args ...interface{}) {
std.Panicf(format, args...)
}
// Fatalf logs a message at level Fatal on the standard logger then the process will exit with status set to 1.
func Fatalf(format string, args ...interface{}) {
std.Fatalf(format, args...)
}
// Traceln logs a message at level Trace on the standard logger.
func Traceln(args ...interface{}) {
std.Traceln(args...)
}
// Debugln logs a message at level Debug on the standard logger.
func Debugln(args ...interface{}) {
std.Debugln(args...)
}
// Println logs a message at level Info on the standard logger.
func Println(args ...interface{}) {
std.Println(args...)
}
// Infoln logs a message at level Info on the standard logger.
func Infoln(args ...interface{}) {
std.Infoln(args...)
}
// Warnln logs a message at level Warn on the standard logger.
func Warnln(args ...interface{}) {
std.Warnln(args...)
}
// Warningln logs a message at level Warn on the standard logger.
func Warningln(args ...interface{}) {
std.Warningln(args...)
}
// Errorln logs a message at level Error on the standard logger.
func Errorln(args ...interface{}) {
std.Errorln(args...)
}
// Panicln logs a message at level Panic on the standard logger.
func Panicln(args ...interface{}) {
std.Panicln(args...)
}
// Fatalln logs a message at level Fatal on the standard logger then the process will exit with status set to 1.
func Fatalln(args ...interface{}) {
std.Fatalln(args...)
}

78
vendor/github.com/sirupsen/logrus/formatter.go сгенерированный поставляемый
Просмотреть файл

@ -1,78 +0,0 @@
package logrus
import "time"
// Default key names for the default fields
const (
defaultTimestampFormat = time.RFC3339
FieldKeyMsg = "msg"
FieldKeyLevel = "level"
FieldKeyTime = "time"
FieldKeyLogrusError = "logrus_error"
FieldKeyFunc = "func"
FieldKeyFile = "file"
)
// The Formatter interface is used to implement a custom Formatter. It takes an
// `Entry`. It exposes all the fields, including the default ones:
//
// * `entry.Data["msg"]`. The message passed from Info, Warn, Error ..
// * `entry.Data["time"]`. The timestamp.
// * `entry.Data["level"]. The level the entry was logged at.
//
// Any additional fields added with `WithField` or `WithFields` are also in
// `entry.Data`. Format is expected to return an array of bytes which are then
// logged to `logger.Out`.
type Formatter interface {
Format(*Entry) ([]byte, error)
}
// This is to not silently overwrite `time`, `msg`, `func` and `level` fields when
// dumping it. If this code wasn't there doing:
//
// logrus.WithField("level", 1).Info("hello")
//
// Would just silently drop the user provided level. Instead with this code
// it'll logged as:
//
// {"level": "info", "fields.level": 1, "msg": "hello", "time": "..."}
//
// It's not exported because it's still using Data in an opinionated way. It's to
// avoid code duplication between the two default formatters.
func prefixFieldClashes(data Fields, fieldMap FieldMap, reportCaller bool) {
timeKey := fieldMap.resolve(FieldKeyTime)
if t, ok := data[timeKey]; ok {
data["fields."+timeKey] = t
delete(data, timeKey)
}
msgKey := fieldMap.resolve(FieldKeyMsg)
if m, ok := data[msgKey]; ok {
data["fields."+msgKey] = m
delete(data, msgKey)
}
levelKey := fieldMap.resolve(FieldKeyLevel)
if l, ok := data[levelKey]; ok {
data["fields."+levelKey] = l
delete(data, levelKey)
}
logrusErrKey := fieldMap.resolve(FieldKeyLogrusError)
if l, ok := data[logrusErrKey]; ok {
data["fields."+logrusErrKey] = l
delete(data, logrusErrKey)
}
// If reportCaller is not set, 'func' will not conflict.
if reportCaller {
funcKey := fieldMap.resolve(FieldKeyFunc)
if l, ok := data[funcKey]; ok {
data["fields."+funcKey] = l
}
fileKey := fieldMap.resolve(FieldKeyFile)
if l, ok := data[fileKey]; ok {
data["fields."+fileKey] = l
}
}
}

34
vendor/github.com/sirupsen/logrus/hooks.go сгенерированный поставляемый
Просмотреть файл

@ -1,34 +0,0 @@
package logrus
// A hook to be fired when logging on the logging levels returned from
// `Levels()` on your implementation of the interface. Note that this is not
// fired in a goroutine or a channel with workers, you should handle such
// functionality yourself if your call is non-blocking and you don't wish for
// the logging calls for levels returned from `Levels()` to block.
type Hook interface {
Levels() []Level
Fire(*Entry) error
}
// Internal type for storing the hooks on a logger instance.
type LevelHooks map[Level][]Hook
// Add a hook to an instance of logger. This is called with
// `log.Hooks.Add(new(MyHook))` where `MyHook` implements the `Hook` interface.
func (hooks LevelHooks) Add(hook Hook) {
for _, level := range hook.Levels() {
hooks[level] = append(hooks[level], hook)
}
}
// Fire all the hooks for the passed level. Used by `entry.log` to fire
// appropriate hooks for a log entry.
func (hooks LevelHooks) Fire(level Level, entry *Entry) error {
for _, hook := range hooks[level] {
if err := hook.Fire(entry); err != nil {
return err
}
}
return nil
}

121
vendor/github.com/sirupsen/logrus/json_formatter.go сгенерированный поставляемый
Просмотреть файл

@ -1,121 +0,0 @@
package logrus
import (
"bytes"
"encoding/json"
"fmt"
"runtime"
)
type fieldKey string
// FieldMap allows customization of the key names for default fields.
type FieldMap map[fieldKey]string
func (f FieldMap) resolve(key fieldKey) string {
if k, ok := f[key]; ok {
return k
}
return string(key)
}
// JSONFormatter formats logs into parsable json
type JSONFormatter struct {
// TimestampFormat sets the format used for marshaling timestamps.
TimestampFormat string
// DisableTimestamp allows disabling automatic timestamps in output
DisableTimestamp bool
// DataKey allows users to put all the log entry parameters into a nested dictionary at a given key.
DataKey string
// FieldMap allows users to customize the names of keys for default fields.
// As an example:
// formatter := &JSONFormatter{
// FieldMap: FieldMap{
// FieldKeyTime: "@timestamp",
// FieldKeyLevel: "@level",
// FieldKeyMsg: "@message",
// FieldKeyFunc: "@caller",
// },
// }
FieldMap FieldMap
// CallerPrettyfier can be set by the user to modify the content
// of the function and file keys in the json data when ReportCaller is
// activated. If any of the returned value is the empty string the
// corresponding key will be removed from json fields.
CallerPrettyfier func(*runtime.Frame) (function string, file string)
// PrettyPrint will indent all json logs
PrettyPrint bool
}
// Format renders a single log entry
func (f *JSONFormatter) Format(entry *Entry) ([]byte, error) {
data := make(Fields, len(entry.Data)+4)
for k, v := range entry.Data {
switch v := v.(type) {
case error:
// Otherwise errors are ignored by `encoding/json`
// https://github.com/sirupsen/logrus/issues/137
data[k] = v.Error()
default:
data[k] = v
}
}
if f.DataKey != "" {
newData := make(Fields, 4)
newData[f.DataKey] = data
data = newData
}
prefixFieldClashes(data, f.FieldMap, entry.HasCaller())
timestampFormat := f.TimestampFormat
if timestampFormat == "" {
timestampFormat = defaultTimestampFormat
}
if entry.err != "" {
data[f.FieldMap.resolve(FieldKeyLogrusError)] = entry.err
}
if !f.DisableTimestamp {
data[f.FieldMap.resolve(FieldKeyTime)] = entry.Time.Format(timestampFormat)
}
data[f.FieldMap.resolve(FieldKeyMsg)] = entry.Message
data[f.FieldMap.resolve(FieldKeyLevel)] = entry.Level.String()
if entry.HasCaller() {
funcVal := entry.Caller.Function
fileVal := fmt.Sprintf("%s:%d", entry.Caller.File, entry.Caller.Line)
if f.CallerPrettyfier != nil {
funcVal, fileVal = f.CallerPrettyfier(entry.Caller)
}
if funcVal != "" {
data[f.FieldMap.resolve(FieldKeyFunc)] = funcVal
}
if fileVal != "" {
data[f.FieldMap.resolve(FieldKeyFile)] = fileVal
}
}
var b *bytes.Buffer
if entry.Buffer != nil {
b = entry.Buffer
} else {
b = &bytes.Buffer{}
}
encoder := json.NewEncoder(b)
if f.PrettyPrint {
encoder.SetIndent("", " ")
}
if err := encoder.Encode(data); err != nil {
return nil, fmt.Errorf("failed to marshal fields to JSON, %v", err)
}
return b.Bytes(), nil
}

351
vendor/github.com/sirupsen/logrus/logger.go сгенерированный поставляемый
Просмотреть файл

@ -1,351 +0,0 @@
package logrus
import (
"context"
"io"
"os"
"sync"
"sync/atomic"
"time"
)
type Logger struct {
// The logs are `io.Copy`'d to this in a mutex. It's common to set this to a
// file, or leave it default which is `os.Stderr`. You can also set this to
// something more adventurous, such as logging to Kafka.
Out io.Writer
// Hooks for the logger instance. These allow firing events based on logging
// levels and log entries. For example, to send errors to an error tracking
// service, log to StatsD or dump the core on fatal errors.
Hooks LevelHooks
// All log entries pass through the formatter before logged to Out. The
// included formatters are `TextFormatter` and `JSONFormatter` for which
// TextFormatter is the default. In development (when a TTY is attached) it
// logs with colors, but to a file it wouldn't. You can easily implement your
// own that implements the `Formatter` interface, see the `README` or included
// formatters for examples.
Formatter Formatter
// Flag for whether to log caller info (off by default)
ReportCaller bool
// The logging level the logger should log at. This is typically (and defaults
// to) `logrus.Info`, which allows Info(), Warn(), Error() and Fatal() to be
// logged.
Level Level
// Used to sync writing to the log. Locking is enabled by Default
mu MutexWrap
// Reusable empty entry
entryPool sync.Pool
// Function to exit the application, defaults to `os.Exit()`
ExitFunc exitFunc
}
type exitFunc func(int)
type MutexWrap struct {
lock sync.Mutex
disabled bool
}
func (mw *MutexWrap) Lock() {
if !mw.disabled {
mw.lock.Lock()
}
}
func (mw *MutexWrap) Unlock() {
if !mw.disabled {
mw.lock.Unlock()
}
}
func (mw *MutexWrap) Disable() {
mw.disabled = true
}
// Creates a new logger. Configuration should be set by changing `Formatter`,
// `Out` and `Hooks` directly on the default logger instance. You can also just
// instantiate your own:
//
// var log = &Logger{
// Out: os.Stderr,
// Formatter: new(JSONFormatter),
// Hooks: make(LevelHooks),
// Level: logrus.DebugLevel,
// }
//
// It's recommended to make this a global instance called `log`.
func New() *Logger {
return &Logger{
Out: os.Stderr,
Formatter: new(TextFormatter),
Hooks: make(LevelHooks),
Level: InfoLevel,
ExitFunc: os.Exit,
ReportCaller: false,
}
}
func (logger *Logger) newEntry() *Entry {
entry, ok := logger.entryPool.Get().(*Entry)
if ok {
return entry
}
return NewEntry(logger)
}
func (logger *Logger) releaseEntry(entry *Entry) {
entry.Data = map[string]interface{}{}
logger.entryPool.Put(entry)
}
// Adds a field to the log entry, note that it doesn't log until you call
// Debug, Print, Info, Warn, Error, Fatal or Panic. It only creates a log entry.
// If you want multiple fields, use `WithFields`.
func (logger *Logger) WithField(key string, value interface{}) *Entry {
entry := logger.newEntry()
defer logger.releaseEntry(entry)
return entry.WithField(key, value)
}
// Adds a struct of fields to the log entry. All it does is call `WithField` for
// each `Field`.
func (logger *Logger) WithFields(fields Fields) *Entry {
entry := logger.newEntry()
defer logger.releaseEntry(entry)
return entry.WithFields(fields)
}
// Add an error as single field to the log entry. All it does is call
// `WithError` for the given `error`.
func (logger *Logger) WithError(err error) *Entry {
entry := logger.newEntry()
defer logger.releaseEntry(entry)
return entry.WithError(err)
}
// Add a context to the log entry.
func (logger *Logger) WithContext(ctx context.Context) *Entry {
entry := logger.newEntry()
defer logger.releaseEntry(entry)
return entry.WithContext(ctx)
}
// Overrides the time of the log entry.
func (logger *Logger) WithTime(t time.Time) *Entry {
entry := logger.newEntry()
defer logger.releaseEntry(entry)
return entry.WithTime(t)
}
func (logger *Logger) Logf(level Level, format string, args ...interface{}) {
if logger.IsLevelEnabled(level) {
entry := logger.newEntry()
entry.Logf(level, format, args...)
logger.releaseEntry(entry)
}
}
func (logger *Logger) Tracef(format string, args ...interface{}) {
logger.Logf(TraceLevel, format, args...)
}
func (logger *Logger) Debugf(format string, args ...interface{}) {
logger.Logf(DebugLevel, format, args...)
}
func (logger *Logger) Infof(format string, args ...interface{}) {
logger.Logf(InfoLevel, format, args...)
}
func (logger *Logger) Printf(format string, args ...interface{}) {
entry := logger.newEntry()
entry.Printf(format, args...)
logger.releaseEntry(entry)
}
func (logger *Logger) Warnf(format string, args ...interface{}) {
logger.Logf(WarnLevel, format, args...)
}
func (logger *Logger) Warningf(format string, args ...interface{}) {
logger.Warnf(format, args...)
}
func (logger *Logger) Errorf(format string, args ...interface{}) {
logger.Logf(ErrorLevel, format, args...)
}
func (logger *Logger) Fatalf(format string, args ...interface{}) {
logger.Logf(FatalLevel, format, args...)
logger.Exit(1)
}
func (logger *Logger) Panicf(format string, args ...interface{}) {
logger.Logf(PanicLevel, format, args...)
}
func (logger *Logger) Log(level Level, args ...interface{}) {
if logger.IsLevelEnabled(level) {
entry := logger.newEntry()
entry.Log(level, args...)
logger.releaseEntry(entry)
}
}
func (logger *Logger) Trace(args ...interface{}) {
logger.Log(TraceLevel, args...)
}
func (logger *Logger) Debug(args ...interface{}) {
logger.Log(DebugLevel, args...)
}
func (logger *Logger) Info(args ...interface{}) {
logger.Log(InfoLevel, args...)
}
func (logger *Logger) Print(args ...interface{}) {
entry := logger.newEntry()
entry.Print(args...)
logger.releaseEntry(entry)
}
func (logger *Logger) Warn(args ...interface{}) {
logger.Log(WarnLevel, args...)
}
func (logger *Logger) Warning(args ...interface{}) {
logger.Warn(args...)
}
func (logger *Logger) Error(args ...interface{}) {
logger.Log(ErrorLevel, args...)
}
func (logger *Logger) Fatal(args ...interface{}) {
logger.Log(FatalLevel, args...)
logger.Exit(1)
}
func (logger *Logger) Panic(args ...interface{}) {
logger.Log(PanicLevel, args...)
}
func (logger *Logger) Logln(level Level, args ...interface{}) {
if logger.IsLevelEnabled(level) {
entry := logger.newEntry()
entry.Logln(level, args...)
logger.releaseEntry(entry)
}
}
func (logger *Logger) Traceln(args ...interface{}) {
logger.Logln(TraceLevel, args...)
}
func (logger *Logger) Debugln(args ...interface{}) {
logger.Logln(DebugLevel, args...)
}
func (logger *Logger) Infoln(args ...interface{}) {
logger.Logln(InfoLevel, args...)
}
func (logger *Logger) Println(args ...interface{}) {
entry := logger.newEntry()
entry.Println(args...)
logger.releaseEntry(entry)
}
func (logger *Logger) Warnln(args ...interface{}) {
logger.Logln(WarnLevel, args...)
}
func (logger *Logger) Warningln(args ...interface{}) {
logger.Warnln(args...)
}
func (logger *Logger) Errorln(args ...interface{}) {
logger.Logln(ErrorLevel, args...)
}
func (logger *Logger) Fatalln(args ...interface{}) {
logger.Logln(FatalLevel, args...)
logger.Exit(1)
}
func (logger *Logger) Panicln(args ...interface{}) {
logger.Logln(PanicLevel, args...)
}
func (logger *Logger) Exit(code int) {
runHandlers()
if logger.ExitFunc == nil {
logger.ExitFunc = os.Exit
}
logger.ExitFunc(code)
}
//When file is opened with appending mode, it's safe to
//write concurrently to a file (within 4k message on Linux).
//In these cases user can choose to disable the lock.
func (logger *Logger) SetNoLock() {
logger.mu.Disable()
}
func (logger *Logger) level() Level {
return Level(atomic.LoadUint32((*uint32)(&logger.Level)))
}
// SetLevel sets the logger level.
func (logger *Logger) SetLevel(level Level) {
atomic.StoreUint32((*uint32)(&logger.Level), uint32(level))
}
// GetLevel returns the logger level.
func (logger *Logger) GetLevel() Level {
return logger.level()
}
// AddHook adds a hook to the logger hooks.
func (logger *Logger) AddHook(hook Hook) {
logger.mu.Lock()
defer logger.mu.Unlock()
logger.Hooks.Add(hook)
}
// IsLevelEnabled checks if the log level of the logger is greater than the level param
func (logger *Logger) IsLevelEnabled(level Level) bool {
return logger.level() >= level
}
// SetFormatter sets the logger formatter.
func (logger *Logger) SetFormatter(formatter Formatter) {
logger.mu.Lock()
defer logger.mu.Unlock()
logger.Formatter = formatter
}
// SetOutput sets the logger output.
func (logger *Logger) SetOutput(output io.Writer) {
logger.mu.Lock()
defer logger.mu.Unlock()
logger.Out = output
}
func (logger *Logger) SetReportCaller(reportCaller bool) {
logger.mu.Lock()
defer logger.mu.Unlock()
logger.ReportCaller = reportCaller
}
// ReplaceHooks replaces the logger hooks and returns the old ones
func (logger *Logger) ReplaceHooks(hooks LevelHooks) LevelHooks {
logger.mu.Lock()
oldHooks := logger.Hooks
logger.Hooks = hooks
logger.mu.Unlock()
return oldHooks
}

186
vendor/github.com/sirupsen/logrus/logrus.go сгенерированный поставляемый
Просмотреть файл

@ -1,186 +0,0 @@
package logrus
import (
"fmt"
"log"
"strings"
)
// Fields type, used to pass to `WithFields`.
type Fields map[string]interface{}
// Level type
type Level uint32
// Convert the Level to a string. E.g. PanicLevel becomes "panic".
func (level Level) String() string {
if b, err := level.MarshalText(); err == nil {
return string(b)
} else {
return "unknown"
}
}
// ParseLevel takes a string level and returns the Logrus log level constant.
func ParseLevel(lvl string) (Level, error) {
switch strings.ToLower(lvl) {
case "panic":
return PanicLevel, nil
case "fatal":
return FatalLevel, nil
case "error":
return ErrorLevel, nil
case "warn", "warning":
return WarnLevel, nil
case "info":
return InfoLevel, nil
case "debug":
return DebugLevel, nil
case "trace":
return TraceLevel, nil
}
var l Level
return l, fmt.Errorf("not a valid logrus Level: %q", lvl)
}
// UnmarshalText implements encoding.TextUnmarshaler.
func (level *Level) UnmarshalText(text []byte) error {
l, err := ParseLevel(string(text))
if err != nil {
return err
}
*level = Level(l)
return nil
}
func (level Level) MarshalText() ([]byte, error) {
switch level {
case TraceLevel:
return []byte("trace"), nil
case DebugLevel:
return []byte("debug"), nil
case InfoLevel:
return []byte("info"), nil
case WarnLevel:
return []byte("warning"), nil
case ErrorLevel:
return []byte("error"), nil
case FatalLevel:
return []byte("fatal"), nil
case PanicLevel:
return []byte("panic"), nil
}
return nil, fmt.Errorf("not a valid logrus level %d", level)
}
// A constant exposing all logging levels
var AllLevels = []Level{
PanicLevel,
FatalLevel,
ErrorLevel,
WarnLevel,
InfoLevel,
DebugLevel,
TraceLevel,
}
// These are the different logging levels. You can set the logging level to log
// on your instance of logger, obtained with `logrus.New()`.
const (
// PanicLevel level, highest level of severity. Logs and then calls panic with the
// message passed to Debug, Info, ...
PanicLevel Level = iota
// FatalLevel level. Logs and then calls `logger.Exit(1)`. It will exit even if the
// logging level is set to Panic.
FatalLevel
// ErrorLevel level. Logs. Used for errors that should definitely be noted.
// Commonly used for hooks to send errors to an error tracking service.
ErrorLevel
// WarnLevel level. Non-critical entries that deserve eyes.
WarnLevel
// InfoLevel level. General operational entries about what's going on inside the
// application.
InfoLevel
// DebugLevel level. Usually only enabled when debugging. Very verbose logging.
DebugLevel
// TraceLevel level. Designates finer-grained informational events than the Debug.
TraceLevel
)
// Won't compile if StdLogger can't be realized by a log.Logger
var (
_ StdLogger = &log.Logger{}
_ StdLogger = &Entry{}
_ StdLogger = &Logger{}
)
// StdLogger is what your logrus-enabled library should take, that way
// it'll accept a stdlib logger and a logrus logger. There's no standard
// interface, this is the closest we get, unfortunately.
type StdLogger interface {
Print(...interface{})
Printf(string, ...interface{})
Println(...interface{})
Fatal(...interface{})
Fatalf(string, ...interface{})
Fatalln(...interface{})
Panic(...interface{})
Panicf(string, ...interface{})
Panicln(...interface{})
}
// The FieldLogger interface generalizes the Entry and Logger types
type FieldLogger interface {
WithField(key string, value interface{}) *Entry
WithFields(fields Fields) *Entry
WithError(err error) *Entry
Debugf(format string, args ...interface{})
Infof(format string, args ...interface{})
Printf(format string, args ...interface{})
Warnf(format string, args ...interface{})
Warningf(format string, args ...interface{})
Errorf(format string, args ...interface{})
Fatalf(format string, args ...interface{})
Panicf(format string, args ...interface{})
Debug(args ...interface{})
Info(args ...interface{})
Print(args ...interface{})
Warn(args ...interface{})
Warning(args ...interface{})
Error(args ...interface{})
Fatal(args ...interface{})
Panic(args ...interface{})
Debugln(args ...interface{})
Infoln(args ...interface{})
Println(args ...interface{})
Warnln(args ...interface{})
Warningln(args ...interface{})
Errorln(args ...interface{})
Fatalln(args ...interface{})
Panicln(args ...interface{})
// IsDebugEnabled() bool
// IsInfoEnabled() bool
// IsWarnEnabled() bool
// IsErrorEnabled() bool
// IsFatalEnabled() bool
// IsPanicEnabled() bool
}
// Ext1FieldLogger (the first extension to FieldLogger) is superfluous, it is
// here for consistancy. Do not use. Use Logger or Entry instead.
type Ext1FieldLogger interface {
FieldLogger
Tracef(format string, args ...interface{})
Trace(args ...interface{})
Traceln(args ...interface{})
}

11
vendor/github.com/sirupsen/logrus/terminal_check_appengine.go сгенерированный поставляемый
Просмотреть файл

@ -1,11 +0,0 @@
// +build appengine
package logrus
import (
"io"
)
func checkIfTerminal(w io.Writer) bool {
return true
}

13
vendor/github.com/sirupsen/logrus/terminal_check_bsd.go сгенерированный поставляемый
Просмотреть файл

@ -1,13 +0,0 @@
// +build darwin dragonfly freebsd netbsd openbsd
package logrus
import "golang.org/x/sys/unix"
const ioctlReadTermios = unix.TIOCGETA
func isTerminal(fd int) bool {
_, err := unix.IoctlGetTermios(fd, ioctlReadTermios)
return err == nil
}

11
vendor/github.com/sirupsen/logrus/terminal_check_no_terminal.go сгенерированный поставляемый
Просмотреть файл

@ -1,11 +0,0 @@
// +build js nacl plan9
package logrus
import (
"io"
)
func checkIfTerminal(w io.Writer) bool {
return false
}

17
vendor/github.com/sirupsen/logrus/terminal_check_notappengine.go сгенерированный поставляемый
Просмотреть файл

@ -1,17 +0,0 @@
// +build !appengine,!js,!windows,!nacl,!plan9
package logrus
import (
"io"
"os"
)
func checkIfTerminal(w io.Writer) bool {
switch v := w.(type) {
case *os.File:
return isTerminal(int(v.Fd()))
default:
return false
}
}

11
vendor/github.com/sirupsen/logrus/terminal_check_solaris.go сгенерированный поставляемый
Просмотреть файл

@ -1,11 +0,0 @@
package logrus
import (
"golang.org/x/sys/unix"
)
// IsTerminal returns true if the given file descriptor is a terminal.
func isTerminal(fd int) bool {
_, err := unix.IoctlGetTermio(fd, unix.TCGETA)
return err == nil
}

13
vendor/github.com/sirupsen/logrus/terminal_check_unix.go сгенерированный поставляемый
Просмотреть файл

@ -1,13 +0,0 @@
// +build linux aix
package logrus
import "golang.org/x/sys/unix"
const ioctlReadTermios = unix.TCGETS
func isTerminal(fd int) bool {
_, err := unix.IoctlGetTermios(fd, ioctlReadTermios)
return err == nil
}

34
vendor/github.com/sirupsen/logrus/terminal_check_windows.go сгенерированный поставляемый
Просмотреть файл

@ -1,34 +0,0 @@
// +build !appengine,!js,windows
package logrus
import (
"io"
"os"
"syscall"
sequences "github.com/konsorten/go-windows-terminal-sequences"
)
func initTerminal(w io.Writer) {
switch v := w.(type) {
case *os.File:
sequences.EnableVirtualTerminalProcessing(syscall.Handle(v.Fd()), true)
}
}
func checkIfTerminal(w io.Writer) bool {
var ret bool
switch v := w.(type) {
case *os.File:
var mode uint32
err := syscall.GetConsoleMode(syscall.Handle(v.Fd()), &mode)
ret = (err == nil)
default:
ret = false
}
if ret {
initTerminal(w)
}
return ret
}

295
vendor/github.com/sirupsen/logrus/text_formatter.go сгенерированный поставляемый
Просмотреть файл

@ -1,295 +0,0 @@
package logrus
import (
"bytes"
"fmt"
"os"
"runtime"
"sort"
"strings"
"sync"
"time"
)
const (
red = 31
yellow = 33
blue = 36
gray = 37
)
var baseTimestamp time.Time
func init() {
baseTimestamp = time.Now()
}
// TextFormatter formats logs into text
type TextFormatter struct {
// Set to true to bypass checking for a TTY before outputting colors.
ForceColors bool
// Force disabling colors.
DisableColors bool
// Override coloring based on CLICOLOR and CLICOLOR_FORCE. - https://bixense.com/clicolors/
EnvironmentOverrideColors bool
// Disable timestamp logging. useful when output is redirected to logging
// system that already adds timestamps.
DisableTimestamp bool
// Enable logging the full timestamp when a TTY is attached instead of just
// the time passed since beginning of execution.
FullTimestamp bool
// TimestampFormat to use for display when a full timestamp is printed
TimestampFormat string
// The fields are sorted by default for a consistent output. For applications
// that log extremely frequently and don't use the JSON formatter this may not
// be desired.
DisableSorting bool
// The keys sorting function, when uninitialized it uses sort.Strings.
SortingFunc func([]string)
// Disables the truncation of the level text to 4 characters.
DisableLevelTruncation bool
// QuoteEmptyFields will wrap empty fields in quotes if true
QuoteEmptyFields bool
// Whether the logger's out is to a terminal
isTerminal bool
// FieldMap allows users to customize the names of keys for default fields.
// As an example:
// formatter := &TextFormatter{
// FieldMap: FieldMap{
// FieldKeyTime: "@timestamp",
// FieldKeyLevel: "@level",
// FieldKeyMsg: "@message"}}
FieldMap FieldMap
// CallerPrettyfier can be set by the user to modify the content
// of the function and file keys in the data when ReportCaller is
// activated. If any of the returned value is the empty string the
// corresponding key will be removed from fields.
CallerPrettyfier func(*runtime.Frame) (function string, file string)
terminalInitOnce sync.Once
}
func (f *TextFormatter) init(entry *Entry) {
if entry.Logger != nil {
f.isTerminal = checkIfTerminal(entry.Logger.Out)
}
}
func (f *TextFormatter) isColored() bool {
isColored := f.ForceColors || (f.isTerminal && (runtime.GOOS != "windows"))
if f.EnvironmentOverrideColors {
if force, ok := os.LookupEnv("CLICOLOR_FORCE"); ok && force != "0" {
isColored = true
} else if ok && force == "0" {
isColored = false
} else if os.Getenv("CLICOLOR") == "0" {
isColored = false
}
}
return isColored && !f.DisableColors
}
// Format renders a single log entry
func (f *TextFormatter) Format(entry *Entry) ([]byte, error) {
data := make(Fields)
for k, v := range entry.Data {
data[k] = v
}
prefixFieldClashes(data, f.FieldMap, entry.HasCaller())
keys := make([]string, 0, len(data))
for k := range data {
keys = append(keys, k)
}
var funcVal, fileVal string
fixedKeys := make([]string, 0, 4+len(data))
if !f.DisableTimestamp {
fixedKeys = append(fixedKeys, f.FieldMap.resolve(FieldKeyTime))
}
fixedKeys = append(fixedKeys, f.FieldMap.resolve(FieldKeyLevel))
if entry.Message != "" {
fixedKeys = append(fixedKeys, f.FieldMap.resolve(FieldKeyMsg))
}
if entry.err != "" {
fixedKeys = append(fixedKeys, f.FieldMap.resolve(FieldKeyLogrusError))
}
if entry.HasCaller() {
if f.CallerPrettyfier != nil {
funcVal, fileVal = f.CallerPrettyfier(entry.Caller)
} else {
funcVal = entry.Caller.Function
fileVal = fmt.Sprintf("%s:%d", entry.Caller.File, entry.Caller.Line)
}
if funcVal != "" {
fixedKeys = append(fixedKeys, f.FieldMap.resolve(FieldKeyFunc))
}
if fileVal != "" {
fixedKeys = append(fixedKeys, f.FieldMap.resolve(FieldKeyFile))
}
}
if !f.DisableSorting {
if f.SortingFunc == nil {
sort.Strings(keys)
fixedKeys = append(fixedKeys, keys...)
} else {
if !f.isColored() {
fixedKeys = append(fixedKeys, keys...)
f.SortingFunc(fixedKeys)
} else {
f.SortingFunc(keys)
}
}
} else {
fixedKeys = append(fixedKeys, keys...)
}
var b *bytes.Buffer
if entry.Buffer != nil {
b = entry.Buffer
} else {
b = &bytes.Buffer{}
}
f.terminalInitOnce.Do(func() { f.init(entry) })
timestampFormat := f.TimestampFormat
if timestampFormat == "" {
timestampFormat = defaultTimestampFormat
}
if f.isColored() {
f.printColored(b, entry, keys, data, timestampFormat)
} else {
for _, key := range fixedKeys {
var value interface{}
switch {
case key == f.FieldMap.resolve(FieldKeyTime):
value = entry.Time.Format(timestampFormat)
case key == f.FieldMap.resolve(FieldKeyLevel):
value = entry.Level.String()
case key == f.FieldMap.resolve(FieldKeyMsg):
value = entry.Message
case key == f.FieldMap.resolve(FieldKeyLogrusError):
value = entry.err
case key == f.FieldMap.resolve(FieldKeyFunc) && entry.HasCaller():
value = funcVal
case key == f.FieldMap.resolve(FieldKeyFile) && entry.HasCaller():
value = fileVal
default:
value = data[key]
}
f.appendKeyValue(b, key, value)
}
}
b.WriteByte('\n')
return b.Bytes(), nil
}
func (f *TextFormatter) printColored(b *bytes.Buffer, entry *Entry, keys []string, data Fields, timestampFormat string) {
var levelColor int
switch entry.Level {
case DebugLevel, TraceLevel:
levelColor = gray
case WarnLevel:
levelColor = yellow
case ErrorLevel, FatalLevel, PanicLevel:
levelColor = red
default:
levelColor = blue
}
levelText := strings.ToUpper(entry.Level.String())
if !f.DisableLevelTruncation {
levelText = levelText[0:4]
}
// Remove a single newline if it already exists in the message to keep
// the behavior of logrus text_formatter the same as the stdlib log package
entry.Message = strings.TrimSuffix(entry.Message, "\n")
caller := ""
if entry.HasCaller() {
funcVal := fmt.Sprintf("%s()", entry.Caller.Function)
fileVal := fmt.Sprintf("%s:%d", entry.Caller.File, entry.Caller.Line)
if f.CallerPrettyfier != nil {
funcVal, fileVal = f.CallerPrettyfier(entry.Caller)
}
if fileVal == "" {
caller = funcVal
} else if funcVal == "" {
caller = fileVal
} else {
caller = fileVal + " " + funcVal
}
}
if f.DisableTimestamp {
fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m%s %-44s ", levelColor, levelText, caller, entry.Message)
} else if !f.FullTimestamp {
fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%04d]%s %-44s ", levelColor, levelText, int(entry.Time.Sub(baseTimestamp)/time.Second), caller, entry.Message)
} else {
fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%s]%s %-44s ", levelColor, levelText, entry.Time.Format(timestampFormat), caller, entry.Message)
}
for _, k := range keys {
v := data[k]
fmt.Fprintf(b, " \x1b[%dm%s\x1b[0m=", levelColor, k)
f.appendValue(b, v)
}
}
func (f *TextFormatter) needsQuoting(text string) bool {
if f.QuoteEmptyFields && len(text) == 0 {
return true
}
for _, ch := range text {
if !((ch >= 'a' && ch <= 'z') ||
(ch >= 'A' && ch <= 'Z') ||
(ch >= '0' && ch <= '9') ||
ch == '-' || ch == '.' || ch == '_' || ch == '/' || ch == '@' || ch == '^' || ch == '+') {
return true
}
}
return false
}
func (f *TextFormatter) appendKeyValue(b *bytes.Buffer, key string, value interface{}) {
if b.Len() > 0 {
b.WriteByte(' ')
}
b.WriteString(key)
b.WriteByte('=')
f.appendValue(b, value)
}
func (f *TextFormatter) appendValue(b *bytes.Buffer, value interface{}) {
stringVal, ok := value.(string)
if !ok {
stringVal = fmt.Sprint(value)
}
if !f.needsQuoting(stringVal) {
b.WriteString(stringVal)
} else {
b.WriteString(fmt.Sprintf("%q", stringVal))
}
}

64
vendor/github.com/sirupsen/logrus/writer.go сгенерированный поставляемый
Просмотреть файл

@ -1,64 +0,0 @@
package logrus
import (
"bufio"
"io"
"runtime"
)
func (logger *Logger) Writer() *io.PipeWriter {
return logger.WriterLevel(InfoLevel)
}
func (logger *Logger) WriterLevel(level Level) *io.PipeWriter {
return NewEntry(logger).WriterLevel(level)
}
func (entry *Entry) Writer() *io.PipeWriter {
return entry.WriterLevel(InfoLevel)
}
func (entry *Entry) WriterLevel(level Level) *io.PipeWriter {
reader, writer := io.Pipe()
var printFunc func(args ...interface{})
switch level {
case TraceLevel:
printFunc = entry.Trace
case DebugLevel:
printFunc = entry.Debug
case InfoLevel:
printFunc = entry.Info
case WarnLevel:
printFunc = entry.Warn
case ErrorLevel:
printFunc = entry.Error
case FatalLevel:
printFunc = entry.Fatal
case PanicLevel:
printFunc = entry.Panic
default:
printFunc = entry.Print
}
go entry.writerScanner(reader, printFunc)
runtime.SetFinalizer(writer, writerFinalizer)
return writer
}
func (entry *Entry) writerScanner(reader *io.PipeReader, printFunc func(args ...interface{})) {
scanner := bufio.NewScanner(reader)
for scanner.Scan() {
printFunc(scanner.Text())
}
if err := scanner.Err(); err != nil {
entry.Errorf("Error while reading from Writer: %s", err)
}
reader.Close()
}
func writerFinalizer(writer *io.PipeWriter) {
writer.Close()
}