Skip to content

Commit

Permalink
configure log format via Values.logFormat (#60)
Browse files Browse the repository at this point in the history
* configure log format via Values.logFormat

* update release version to 1.2.4
  • Loading branch information
JorritSalverda authored Nov 25, 2019
1 parent d62145d commit dcf7b7f
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 33 deletions.
4 changes: 2 additions & 2 deletions .estafette.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ version:
semver:
major: 1
minor: 2
patch: 3
patch: 4
labelTemplate: '{{branch}}-{{auto}}'
releaseBranch: 1.2.3
releaseBranch: 1.2.4

stages:
build-lint-and-package:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/alecthomas/kingpin v2.2.5+incompatible
github.com/alecthomas/repr v0.0.0-20181024024818-d37bc2a10ba1 // indirect
github.com/ericchiang/k8s v0.0.0-20170725150632-85c31b99a193
github.com/estafette/estafette-foundation v0.0.21
github.com/estafette/estafette-foundation v0.0.32
github.com/ghodss/yaml v1.0.0
github.com/google/go-intervals v0.0.0-20171120085516-250c62ad245e
github.com/kr/pretty v0.1.0 // indirect
Expand Down
8 changes: 6 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/ericchiang/k8s v0.0.0-20170725150632-85c31b99a193 h1:u+lHWzgg4ERLJzw2rS0fWP/XPDN8JwsQMZzjWQyqYr0=
github.com/ericchiang/k8s v0.0.0-20170725150632-85c31b99a193/go.mod h1:/OmBgSq2cd9IANnsGHGlEz27nwMZV2YxlpXuQtU3Bz4=
github.com/estafette/estafette-foundation v0.0.21 h1:OCO9lqElDMlf0bAKX6rB+ced0DMZNKFOfhnhrRQmjv8=
github.com/estafette/estafette-foundation v0.0.21/go.mod h1:CugZ5IABfGepKKoAri5ObS1R25esdTcuD8XNAD24+vA=
github.com/estafette/estafette-foundation v0.0.32 h1:s32Gt59N1+tkv5CKbtPtCtxGFqXUecfl9v9/IB1sv9I=
github.com/estafette/estafette-foundation v0.0.32/go.mod h1:pgqDp5MyMR9PgRFwU5w7zb8XAa8hkyaf51Sutl04llY=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
Expand All @@ -35,6 +35,8 @@ github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/go-intervals v0.0.0-20171120085516-250c62ad245e h1:VH1kYLi3bp6AOWYdo9dyls7PmYt7+nUJ8TUv0bGgL7c=
github.com/google/go-intervals v0.0.0-20171120085516-250c62ad245e/go.mod h1:mjqke8WRSUEe8uXvgOGaWTwD286ilkbJzB9o6fja/Fo=
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
Expand All @@ -43,6 +45,8 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/logrusorgru/aurora v0.0.0-20191116043053-66b7ad493a23 h1:Wp7NjqGKGN9te9N/rvXYRhlVcrulGdxnz8zadXWs7fc=
github.com/logrusorgru/aurora v0.0.0-20191116043053-66b7ad493a23/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
github.com/mattn/go-isatty v0.0.6 h1:SrwhHcpV4nWrMGdNcC2kXpMfcBVYGDuTArqyhocJgvA=
github.com/mattn/go-isatty v0.0.6/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ spec:
{{- toYaml . | nindent 12 }}
{{- end }}
env:
- name: "ESTAFETTE_LOG_FORMAT"
value: "{{ .Values.logFormat }}"
- name: DRAIN_TIMEOUT
value: {{ .Values.drainTimeout | quote }}
- name: INTERVAL
Expand Down
3 changes: 3 additions & 0 deletions helm/estafette-gke-preemptible-killer/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ secret:
# sets a json keyfile for a gcp service account
googleServiceAccountKeyfileJson: '{"type": "service_account"}'

# the following log formats are available: plaintext, console, json, stackdriver, v3 (see https://github.com/estafette/estafette-foundation for more info)
logFormat: plaintext

#
# GENERIC SETTINGS
#
Expand Down
30 changes: 2 additions & 28 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"fmt"
stdlog "log"
"math/rand"
"os"
"runtime"
Expand All @@ -14,7 +13,6 @@ import (
apiv1 "github.com/ericchiang/k8s/api/v1"
foundation "github.com/estafette/estafette-foundation"
"github.com/prometheus/client_golang/prometheus"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)

Expand Down Expand Up @@ -91,8 +89,8 @@ func main() {
// parse command line parameters
kingpin.Parse()

// configure json logging
foundation.InitLogging(appgroup, app, version, branch, revision, buildDate)
// init log format from envvar ESTAFETTE_LOG_FORMAT
foundation.InitLoggingFromEnv(appgroup, app, version, branch, revision, buildDate)

// configure prometheus metrics endpoint
foundation.InitMetrics()
Expand Down Expand Up @@ -167,30 +165,6 @@ func main() {
foundation.HandleGracefulShutdown(gracefulShutdown, waitGroup)
}

func initializeLogger() {
// log as severity for stackdriver logging to recognize the level
zerolog.LevelFieldName = "severity"

// set some default fields added to all logs
log.Logger = zerolog.New(os.Stdout).With().
Timestamp().
Str("app", "estafette-gke-preemptible-killer").
Str("version", version).
Logger()

// use zerolog for any logs sent via standard log library
stdlog.SetFlags(0)
stdlog.SetOutput(log.Logger)

// log startup message
log.Info().
Str("branch", branch).
Str("revision", revision).
Str("buildDate", buildDate).
Str("goVersion", goVersion).
Msg("Starting estafette-gke-preemptible-killer...")
}

// getCurrentNodeState return the state of the node by reading its metadata annotations
func getCurrentNodeState(node *apiv1.Node) (state GKEPreemptibleKillerState) {
var ok bool
Expand Down

0 comments on commit dcf7b7f

Please sign in to comment.