Skip to content

Commit

Permalink
fix: logging formats
Browse files Browse the repository at this point in the history
  • Loading branch information
butschi84 committed Dec 9, 2023
1 parent fae69ac commit 7d88e3e
Show file tree
Hide file tree
Showing 16 changed files with 67 additions and 44 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ kafka:
key: test-response
```

Fitler values will have to be one of `equal`, `not equal`, `contains` or `not contains`

### Debugging
Environment Variables take precedence over the configmap and are useful for local testing / debugging.

Expand Down
4 changes: 1 addition & 3 deletions f2soperator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ import (
"butschi84/f2s/state/queue"
"fmt"

"golang.org/x/exp/slog"

"sync"
)

var (
F2SConfiguration configuration.F2SConfiguration
logging *slog.Logger
logging *logger.F2SLogger
F2SHub hub.F2SHub
)

Expand Down
4 changes: 1 addition & 3 deletions f2soperator/operation/apiserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ import (
"net/http"
"regexp"

"golang.org/x/exp/slog"

"github.com/gorilla/mux"
)

var logging *slog.Logger
var logging *logger.F2SLogger

var f2shub *hub.F2SHub

Expand Down
4 changes: 2 additions & 2 deletions f2soperator/operation/dispatcher/handlerequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ func handleRequest(req *queue.F2SRequest, result *chan queue.F2SRequestResult) {
// measure time elapsed
elapsed := time.Since(start).Milliseconds()
elapsedPerInflight := int(time.Since(start).Milliseconds()) / len(pod.InflightRequests)
logging.Info(fmt.Sprintf("[%s] Function execution time: %s\n", req.UID, fmt.Sprintf("%vms", elapsed)))
logging.Info(fmt.Sprintf("[%s] Function execution time per inflight request: %sms\n", req.UID, fmt.Sprintf("%v", elapsedPerInflight)))
logging.Info(fmt.Sprintf("[%s] Function execution time: %s", req.UID, fmt.Sprintf("%vms", elapsed)))
logging.Info(fmt.Sprintf("[%s] Function execution time per inflight request: %sms", req.UID, fmt.Sprintf("%v", elapsedPerInflight)))

// prepare output
requestResult.Success = true
Expand Down
4 changes: 1 addition & 3 deletions f2soperator/operation/dispatcher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import (
"butschi84/f2s/services/logger"
"fmt"
"time"

"golang.org/x/exp/slog"
)

var logging *slog.Logger
var logging *logger.F2SLogger
var f2shub *hub.F2SHub

func Initialize(h *hub.F2SHub) {
Expand Down
4 changes: 1 addition & 3 deletions f2soperator/operation/kafka/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import (
"butschi84/f2s/services/logger"
"fmt"
"time"

"golang.org/x/exp/slog"
)

var logging *slog.Logger
var logging *logger.F2SLogger
var f2shub *hub.F2SHub

func init() {
Expand Down
15 changes: 15 additions & 0 deletions f2soperator/operation/kafka/matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ package kafka
import (
"butschi84/f2s/state/configuration"
"fmt"
"strings"
)

// function to check if a configured kafka trigger matches the message
// => input (key, value)
// compare to f2s config
func matchMessage(key string, value string, kafkaListenerConfig *configuration.F2SConfigMapKafkaListener) []configuration.F2SConfigMapKafkaListenerAction {
logging.Info(fmt.Sprintf("Kafka Message: %s => %s", key, value))

Expand All @@ -30,6 +33,18 @@ func matchMessage(key string, value string, kafkaListenerConfig *configuration.F
if actualValue == trigger.Value {
resInvokeActions = append(resInvokeActions, action)
}
case "not equal":
if actualValue != trigger.Value {
resInvokeActions = append(resInvokeActions, action)
}
case "contains":
if strings.Contains(actualValue, trigger.Value) {
resInvokeActions = append(resInvokeActions, action)
}
case "not contains":
if !strings.Contains(actualValue, trigger.Value) {
resInvokeActions = append(resInvokeActions, action)
}
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions f2soperator/operation/metrics/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ import (
"butschi84/f2s/services/logger"
"net/http"

"golang.org/x/exp/slog"

"github.com/gorilla/mux"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)

var logging *slog.Logger
var logging *logger.F2SLogger

// pointer to F2SConfiguration
var f2shub hub.F2SHub
Expand Down
4 changes: 1 addition & 3 deletions f2soperator/operation/operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ import (
"strconv"
"time"

"golang.org/x/exp/slog"

kubernetesservice "butschi84/f2s/services/kubernetes"
)

var logging *slog.Logger
var logging *logger.F2SLogger
var f2shub *hub.F2SHub

func init() {
Expand Down
4 changes: 1 addition & 3 deletions f2soperator/services/kubernetes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ package kubernetesservice

import (
"butschi84/f2s/services/logger"

"golang.org/x/exp/slog"
)

var logging *slog.Logger
var logging *logger.F2SLogger

func init() {
// initialize logging
Expand Down
35 changes: 26 additions & 9 deletions f2soperator/services/logger/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,39 @@ package logger

import (
"os"
"strings"

"golang.org/x/exp/slog"
)

type IF2SLogger interface {
Debug()
Info()
Warn()
Error()
}

type F2SLogger struct {
ComponentName string
Logger *slog.Logger
}

func Initialize(ComponentName string) *slog.Logger {
return slog.New(slog.NewTextHandler(os.Stdout, nil)).With("component", ComponentName)
func Initialize(ComponentName string) *F2SLogger {
logger := slog.New(slog.NewTextHandler(os.Stdout, nil)).With("component", ComponentName)
return &F2SLogger{
ComponentName: ComponentName,
Logger: logger,
}
}

// standard logging functions
func (l F2SLogger) Info(text ...string) {
l.Logger.Info(strings.Join(text, " "), "type", "log")
}
func (l F2SLogger) Debug(text ...string) {
l.Logger.Debug(strings.Join(text, " "), "type", "log")
}
func (l F2SLogger) Warn(text ...string) {
l.Logger.Warn(strings.Join(text, " "), "type", "log")
}
func (l F2SLogger) Error(text ...string) {
l.Logger.Error(strings.Join(text, " "), "type", "log")
}

// log an event
func (l F2SLogger) Event(text ...string) {
l.Logger.Info(strings.Join(text, " "), "type", "event")
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ package v1alpha1

import (
"butschi84/f2s/services/logger"

"golang.org/x/exp/slog"
)

var logging *slog.Logger
var logging *logger.F2SLogger

func init() {
// initialize logging
Expand Down
4 changes: 1 addition & 3 deletions f2soperator/state/configuration/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ import (
"log"
"os"

"golang.org/x/exp/slog"

"gopkg.in/yaml.v2"
)

var logging *slog.Logger
var logging *logger.F2SLogger

var ActiveConfiguration F2SConfiguration

Expand Down
4 changes: 1 addition & 3 deletions f2soperator/state/dispatcherstate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ package dispatcherstate

import (
"butschi84/f2s/services/logger"

"golang.org/x/exp/slog"
)

var logging *slog.Logger
var logging *logger.F2SLogger

var functionTargets F2SDispatcherHub

Expand Down
4 changes: 1 addition & 3 deletions f2soperator/state/queue/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ package queue
import (
"butschi84/f2s/services/logger"
"fmt"

"golang.org/x/exp/slog"
)

var logging *slog.Logger
var logging *logger.F2SLogger

func init() {
// initialize logging
Expand Down
11 changes: 11 additions & 0 deletions helm/templates/prometheus/promtail.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ data:
- role: pod
pipeline_stages:
- docker: {}
- logfmt:
mapping:
component:
type:
timestamp:
source: file
- labels:
timestamp:
component:
source:
type:
relabel_configs:
- source_labels:
- __meta_kubernetes_pod_node_name
Expand Down

0 comments on commit 7d88e3e

Please sign in to comment.