diff --git a/f2soperator/go.mod b/f2soperator/go.mod index 31371c1..f18b0c3 100644 --- a/f2soperator/go.mod +++ b/f2soperator/go.mod @@ -3,6 +3,8 @@ module butschi84/f2s go 1.19 require ( + github.com/confluentinc/confluent-kafka-go v1.9.2 + github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/google/uuid v1.3.0 github.com/gorilla/mux v1.8.0 github.com/prometheus/client_golang v1.16.0 @@ -15,9 +17,7 @@ require ( require ( github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect - github.com/confluentinc/confluent-kafka-go v1.9.2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect github.com/emicklei/go-restful/v3 v3.9.0 // indirect github.com/go-logr/logr v1.2.3 // indirect github.com/go-openapi/jsonpointer v0.19.6 // indirect @@ -40,11 +40,12 @@ require ( github.com/prometheus/common v0.42.0 // indirect github.com/prometheus/procfs v0.10.1 // indirect github.com/spf13/pflag v1.0.5 // indirect - golang.org/x/net v0.9.0 // indirect + golang.org/x/exp v0.0.0-20231127185646-65229373498e // indirect + golang.org/x/net v0.8.0 // indirect golang.org/x/oauth2 v0.5.0 // indirect golang.org/x/sys v0.8.0 // indirect - golang.org/x/term v0.7.0 // indirect - golang.org/x/text v0.9.0 // indirect + golang.org/x/term v0.6.0 // indirect + golang.org/x/text v0.8.0 // indirect golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/protobuf v1.30.0 // indirect diff --git a/f2soperator/go.sum b/f2soperator/go.sum index d4b9f6c..a9e5385 100644 --- a/f2soperator/go.sum +++ b/f2soperator/go.sum @@ -45,7 +45,6 @@ github.com/frankban/quicktest v1.7.2/go.mod h1:jaStnuzAqU1AJdCO0l53JDCJrVDKcS03D github.com/frankban/quicktest v1.10.0/go.mod h1:ui7WezCLWMWxVWr1GETZY3smRy0G4KWq9vcPtJmFl7Y= github.com/frankban/quicktest v1.14.0/go.mod h1:NeW+ay9A/U67EYXNFA1nPE8e/tnQv/09mUdL/ijj8og= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= -github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0= github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= @@ -95,7 +94,6 @@ github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeN github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.1.0 h1:Hsa8mG0dQ46ij8Sl2AYJDUv1oA9/d6Vk+3LG99Oe02g= github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJYCmNdQXq6neHJOYx3V6jnqNEec= github.com/google/pprof v0.0.0-20211008130755-947d60d73cc0 h1:zHs+jv3LO743/zFGcByu2KmpbliCU2AhjcGgrdTwSG4= github.com/google/pprof v0.0.0-20211008130755-947d60d73cc0/go.mod h1:KgnwoLYCZ8IQu3XUZ8Nc/bM9CCZFOyjUNOSygVozoDg= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= @@ -118,7 +116,6 @@ github.com/jhump/protoreflect v1.11.0/go.mod h1:U7aMIjN0NWq9swDP7xDdoMfRHb35uiuT github.com/jhump/protoreflect v1.12.0/go.mod h1:JytZfP5d0r8pVNLZvai7U/MCuTWITgrI4tTg7puQFKI= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= -github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= @@ -152,13 +149,11 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= -github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/nrwiersma/avro-benchmarks v0.0.0-20210913175520-21aec48c8f76/go.mod h1:iKyFMidsk/sVYONJRE372sJuX/QTRPacU7imPqqsu7g= github.com/onsi/ginkgo/v2 v2.9.1 h1:zie5Ly042PD3bsCvsSOPvRnFwyo3rKe64TJlD6nu0mk= github.com/onsi/gomega v1.27.4 h1:Z2AnStgsdSayCMDiCU42qIz+HLqEPcgiOCXjAU/w+8E= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= -github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v1.16.0 h1:yk/hx9hDbrGHovbci4BY+pRMfSuuat626eFsHb7tmT8= @@ -197,6 +192,8 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20231127185646-65229373498e h1:Gvh4YaCaXNs6dKTlfgismwWZKyjVZXwOPfIyUaqU3No= +golang.org/x/exp v0.0.0-20231127185646-65229373498e/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= @@ -216,8 +213,8 @@ golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81R golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= -golang.org/x/net v0.9.0 h1:aWJ/m6xSmxWBx+V0XRHTlrYrPG56jKsLdTFmsSsCzOM= -golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= +golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ= +golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.5.0 h1:HuArIo48skDwlrvM3sEdHXElYslAMsf3KwRkkW4MC4s= @@ -242,14 +239,14 @@ golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.7.0 h1:BEvjmm5fURWqcfbSKTdpkDXYBrUS1c0m8agp14W48vQ= -golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY= +golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw= +golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= -golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68= +golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 h1:vVKdlvoWBphwdxWKrFZEuM0kGgGLxUOYcY4U/2Vjg44= golang.org/x/time v0.0.0-20220210224613-90d013bbcef8/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/f2soperator/main.go b/f2soperator/main.go index c93c8cd..8f7f42d 100644 --- a/f2soperator/main.go +++ b/f2soperator/main.go @@ -14,12 +14,13 @@ import ( "butschi84/f2s/state/operatorstate" "butschi84/f2s/state/queue" "fmt" + "log/slog" "sync" ) var ( F2SConfiguration configuration.F2SConfiguration - logging logger.F2SLogger + logging *slog.Logger F2SHub hub.F2SHub ) diff --git a/f2soperator/operation/apiserver/authorization.go b/f2soperator/operation/apiserver/authorization.go index eeb85a4..a3075f0 100644 --- a/f2soperator/operation/apiserver/authorization.go +++ b/f2soperator/operation/apiserver/authorization.go @@ -60,7 +60,7 @@ func getUsers() ([]queue.F2SAuthUser, error) { return []byte(jwtSecret), nil }) if err != nil { - logging.Error(fmt.Errorf("error decoding token '%s': %s", f2shub.F2SConfiguration.Config.F2S.Auth.Token.Tokens[i].Token, err.Error())) + logging.Error(fmt.Sprintf("error decoding token '%s': %s", f2shub.F2SConfiguration.Config.F2S.Auth.Token.Tokens[i].Token, err.Error())) continue } diff --git a/f2soperator/operation/apiserver/functions.go b/f2soperator/operation/apiserver/functions.go index 6ca10d4..9cde3b0 100644 --- a/f2soperator/operation/apiserver/functions.go +++ b/f2soperator/operation/apiserver/functions.go @@ -73,7 +73,7 @@ func createFunction(w http.ResponseWriter, r *http.Request) { // Unmarshal the JSON data into the function struct if err := json.Unmarshal(body, &function); err != nil { - logging.Error(err) + logging.Error(fmt.Sprintf("%s", err)) http.Error(w, "Failed to parse JSON data", http.StatusBadRequest) return } diff --git a/f2soperator/operation/apiserver/invoke.go b/f2soperator/operation/apiserver/invoke.go index 36a226f..83d1c35 100644 --- a/f2soperator/operation/apiserver/invoke.go +++ b/f2soperator/operation/apiserver/invoke.go @@ -73,7 +73,7 @@ func invokeFunction(w http.ResponseWriter, r *http.Request) { // get user info currentUser, getUserErr := getCurrentUser(r) if getUserErr != nil { - logging.Error(fmt.Errorf("[%s] failed to get user info for this request", request.UID)) + logging.Error(fmt.Sprintf("[%s] failed to get user info for this request", request.UID)) } request.F2SUser = currentUser @@ -82,7 +82,7 @@ func invokeFunction(w http.ResponseWriter, r *http.Request) { logging.Debug(fmt.Sprintf("[%s] reading request body", request.UID)) body, err := io.ReadAll(r.Body) if err != nil { - logging.Error(fmt.Errorf("[%s] Failed to read request body", request.UID)) + logging.Error(fmt.Sprintf("[%s] Failed to read request body", request.UID)) http.Error(w, "Failed to read request body", http.StatusInternalServerError) return } diff --git a/f2soperator/operation/apiserver/main.go b/f2soperator/operation/apiserver/main.go index 43eb87f..cfa6804 100644 --- a/f2soperator/operation/apiserver/main.go +++ b/f2soperator/operation/apiserver/main.go @@ -5,13 +5,14 @@ import ( "butschi84/f2s/services/logger" "butschi84/f2s/state/configuration" "fmt" + "log/slog" "net/http" "regexp" "github.com/gorilla/mux" ) -var logging logger.F2SLogger +var logging *slog.Logger var f2shub *hub.F2SHub diff --git a/f2soperator/operation/apiserver/prometheus.go b/f2soperator/operation/apiserver/prometheus.go index 5b31cea..2916a51 100644 --- a/f2soperator/operation/apiserver/prometheus.go +++ b/f2soperator/operation/apiserver/prometheus.go @@ -18,7 +18,7 @@ func getPrometheusMetric(w http.ResponseWriter, r *http.Request) { result, err := prometheus.ReadPrometheusMetric(f2shub.F2SConfiguration, query) if err != nil { - logging.Error(fmt.Errorf("could not read prometheus metric: %s", err)) + logging.Error(fmt.Sprintf("could not read prometheus metric: %s", err)) json.NewEncoder(w).Encode(Status{Status: fmt.Sprintf("could not read prometheus metric %s", err)}) return } diff --git a/f2soperator/operation/dispatcher/handlerequest.go b/f2soperator/operation/dispatcher/handlerequest.go index c33cd47..1e1bb08 100644 --- a/f2soperator/operation/dispatcher/handlerequest.go +++ b/f2soperator/operation/dispatcher/handlerequest.go @@ -80,8 +80,8 @@ func handleRequest(req *queue.F2SRequest, result *chan queue.F2SRequestResult) { logging.Debug(fmt.Sprintf("[%s] search function target for endpoint: %s", req.UID, req.Path)) functionTarget, err := f2shub.F2SDispatcherHub.GetDispatcherFunctionByEndpoint(req.Path) if err != nil { - logging.Error(fmt.Errorf("[%s] cannot serve request. function target not found for endpoint %s", req.UID, req.Path)) - logging.Error(err) + logging.Error(fmt.Sprintf("[%s] cannot serve request. function target not found for endpoint %s", req.UID, req.Path)) + logging.Error(fmt.Sprintf("%s", err)) } logging.Debug(fmt.Sprintf("[%s] function target is: %s", req.UID, functionTarget.Function.Name)) @@ -110,7 +110,7 @@ func handleRequest(req *queue.F2SRequest, result *chan queue.F2SRequestResult) { if len(functionTarget.ServingPods) == 0 { err := waitForTargetPod(functionTarget) if err != nil { - logging.Error(fmt.Errorf("[%s] aborting function '%s'. scale from 0 failed: %s", req.UID, functionTarget.Function.Name, err.Error())) + logging.Error(fmt.Sprintf("[%s] aborting function '%s'. scale from 0 failed: %s", req.UID, functionTarget.Function.Name, err.Error())) // send result to channel requestResult.Details = fmt.Sprintf("[%s] aborting function '%s'. scale from 0 failed: %s", req.UID, functionTarget.Function.Name, err.Error()) requestResult.Success = false @@ -122,7 +122,7 @@ func handleRequest(req *queue.F2SRequest, result *chan queue.F2SRequestResult) { // get the pod that will actually serve the request pod, err := functionTarget.ServeRequest(req) if err != nil { - logging.Error(fmt.Errorf("[%s] cannot serve request because cannot determine which pod should serve the request: %s", req.UID, err.Error())) + logging.Error(fmt.Sprintf("[%s] cannot serve request because cannot determine which pod should serve the request: %s", req.UID, err.Error())) requestResult.Details = fmt.Sprintf("[%s] aborting function '%s' invocation because target cannot serve request: %s", req.UID, functionTarget.Function.Name, err.Error()) requestResult.Success = false *result <- requestResult @@ -166,7 +166,7 @@ func handleRequest(req *queue.F2SRequest, result *chan queue.F2SRequestResult) { } if requestErr != nil { - logging.Error(err) + logging.Error(fmt.Sprintf("%s", err)) // send result to channel requestResult.Details = fmt.Sprintf("[%s] error on function http invocation: %s", req.UID, requestErr.Error()) requestResult.Success = false diff --git a/f2soperator/operation/dispatcher/httpget.go b/f2soperator/operation/dispatcher/httpget.go index 146f25c..9ac38e3 100644 --- a/f2soperator/operation/dispatcher/httpget.go +++ b/f2soperator/operation/dispatcher/httpget.go @@ -21,10 +21,10 @@ func httpGet(url string, result *queue.F2SRequestResult) error { response, err := client.Get(url) if err != nil { if strings.Contains(err.Error(), "context deadline exceeded") { - logging.Error(fmt.Errorf("[%s] http_timeout: %s", result.Request.UID, err)) + logging.Error(fmt.Sprintf("[%s] http_timeout: %s", result.Request.UID, err)) return fmt.Errorf("http_timeout: %s", err) } else { - logging.Error(fmt.Errorf("[%s] error during httpGet function Call: %s", result.Request.UID, err)) + logging.Error(fmt.Sprintf("[%s] error during httpGet function Call: %s", result.Request.UID, err)) return err } @@ -64,10 +64,10 @@ func httpPost(url, data string, result *queue.F2SRequestResult) error { response, err := client.Post(url, contentType, body) if err != nil { if strings.Contains(err.Error(), "context deadline exceeded") { - logging.Error(fmt.Errorf("http_timeout: %s", err)) + logging.Error(fmt.Sprintf("http_timeout: %s", err)) return fmt.Errorf("http_timeout: %s", err) } else { - logging.Error(fmt.Errorf("[%s] error during httpPost function Call: %s", result.Request.UID, err)) + logging.Error(fmt.Sprintf("[%s] error during httpPost function Call: %s", result.Request.UID, err)) return err } } @@ -93,7 +93,7 @@ func httpPut(url, data string, result *queue.F2SRequestResult) error { // Create a PUT request using http.NewRequest req, err := http.NewRequest("PUT", url, body) if err != nil { - logging.Error(fmt.Errorf("[%s] error creating PUT request: %s", result.Request.UID, err)) + logging.Error(fmt.Sprintf("[%s] error creating PUT request: %s", result.Request.UID, err)) return err } @@ -109,10 +109,10 @@ func httpPut(url, data string, result *queue.F2SRequestResult) error { response, err := client.Do(req) if err != nil { if strings.Contains(err.Error(), "context deadline exceeded") { - logging.Error(fmt.Errorf("[%s] http_timeout: %s", result.Request.UID, err)) + logging.Error(fmt.Sprintf("[%s] http_timeout: %s", result.Request.UID, err)) return fmt.Errorf("http_timeout: %s", err) } else { - logging.Error(fmt.Errorf("[%s] error during httpPut function Call: %s", result.Request.UID, err)) + logging.Error(fmt.Sprintf("[%s] error during httpPut function Call: %s", result.Request.UID, err)) return err } } @@ -135,7 +135,7 @@ func httpDelete(url string, result *queue.F2SRequestResult) error { // Create a DELETE request using http.NewRequest req, err := http.NewRequest("DELETE", url, nil) if err != nil { - logging.Error(fmt.Errorf("[%s] error creating DELETE request: %s", result.Request.UID, err)) + logging.Error(fmt.Sprintf("[%s] error creating DELETE request: %s", result.Request.UID, err)) return err } @@ -143,10 +143,10 @@ func httpDelete(url string, result *queue.F2SRequestResult) error { response, err := client.Do(req) if err != nil { if strings.Contains(err.Error(), "context deadline exceeded") { - logging.Error(fmt.Errorf("[%s] http_timeout: %s", result.Request.UID, err)) + logging.Error(fmt.Sprintf("[%s] http_timeout: %s", result.Request.UID, err)) return fmt.Errorf("http_timeout: %s", err) } else { - logging.Error(fmt.Errorf("[%s] error during httpDelete function Call: %s", result.Request.UID, err)) + logging.Error(fmt.Sprintf("[%s] error during httpDelete function Call: %s", result.Request.UID, err)) return err } } @@ -165,7 +165,7 @@ func fetchResponse(response *http.Response, result *queue.F2SRequestResult) (err // Read response body responseBody, err := io.ReadAll(response.Body) if err != nil { - logging.Error(fmt.Errorf("[%s] [fetchResponse] error when reading httpPost function call result body: %s", result.Request.UID, err)) + logging.Error(fmt.Sprintf("[%s] [fetchResponse] error when reading httpPost function call result body: %s", result.Request.UID, err)) return err } diff --git a/f2soperator/operation/dispatcher/main.go b/f2soperator/operation/dispatcher/main.go index f2c8eb9..f010c9c 100644 --- a/f2soperator/operation/dispatcher/main.go +++ b/f2soperator/operation/dispatcher/main.go @@ -4,10 +4,11 @@ import ( "butschi84/f2s/hub" "butschi84/f2s/services/logger" "fmt" + "log/slog" "time" ) -var logging logger.F2SLogger +var logging *slog.Logger var f2shub *hub.F2SHub func Initialize(h *hub.F2SHub) { @@ -44,7 +45,7 @@ func GetCurrentDispatcherData() string { // get function target target, err := f2shub.F2SDispatcherHub.GetDispatcherFunctionByName(function.Name) - logging.Error(err) + logging.Error(fmt.Sprintf("%s", err)) output += fmt.Sprintf("Endpoints: %d", len(target.ServingPods)) for _, endpoint := range target.ServingPods { diff --git a/f2soperator/operation/kafka/invoker.go b/f2soperator/operation/kafka/invoker.go index ae8103c..84d5474 100644 --- a/f2soperator/operation/kafka/invoker.go +++ b/f2soperator/operation/kafka/invoker.go @@ -15,7 +15,7 @@ func invokeFunction(functionUid string, requestBody string) (result string, err // get this function from config f2sfunction, errGetFunction := f2shub.F2SConfiguration.GetFunctionByUID(functionUid) if errGetFunction != nil { - logging.Error(fmt.Errorf("error getting function %s from running config. abort function invocation", functionUid)) + logging.Error(fmt.Sprintf("error getting function %s from running config. abort function invocation", functionUid)) return } diff --git a/f2soperator/operation/kafka/main.go b/f2soperator/operation/kafka/main.go index 956ba73..5f8cd61 100644 --- a/f2soperator/operation/kafka/main.go +++ b/f2soperator/operation/kafka/main.go @@ -4,10 +4,11 @@ import ( "butschi84/f2s/hub" "butschi84/f2s/services/logger" "fmt" + "log/slog" "time" ) -var logging logger.F2SLogger +var logging *slog.Logger var f2shub *hub.F2SHub func init() { diff --git a/f2soperator/operation/metrics/eventhandler.go b/f2soperator/operation/metrics/eventhandler.go index bc48f6d..ab8c4fb 100644 --- a/f2soperator/operation/metrics/eventhandler.go +++ b/f2soperator/operation/metrics/eventhandler.go @@ -36,7 +36,7 @@ func handleEvent(event eventmanager.Event) { result := event.Data.(queue.F2SRequestResult) functionTarget, err := f2shub.F2SDispatcherHub.GetDispatcherFunctionByEndpoint(result.Request.Path) if err != nil { - logging.Error(fmt.Errorf("[%s] cannot calculate metrics for request because: %s", result.Request.UID, err.Error())) + logging.Error(fmt.Sprintf("[%s] cannot calculate metrics for request because: %s", result.Request.UID, err.Error())) } if result.Success { diff --git a/f2soperator/operation/metrics/main.go b/f2soperator/operation/metrics/main.go index d686f86..c27031e 100644 --- a/f2soperator/operation/metrics/main.go +++ b/f2soperator/operation/metrics/main.go @@ -3,6 +3,7 @@ package metrics import ( "butschi84/f2s/hub" "butschi84/f2s/services/logger" + "log/slog" "net/http" "github.com/gorilla/mux" @@ -10,7 +11,7 @@ import ( "github.com/prometheus/client_golang/prometheus/promhttp" ) -var logging logger.F2SLogger +var logging *slog.Logger // pointer to F2SConfiguration var f2shub hub.F2SHub diff --git a/f2soperator/operation/operator/balancer.go b/f2soperator/operation/operator/balancer.go index 2683036..d78567f 100644 --- a/f2soperator/operation/operator/balancer.go +++ b/f2soperator/operation/operator/balancer.go @@ -103,7 +103,7 @@ func getLastScalingTimestamp(deploymentName string) (time.Time, bool) { // get annotations of k8s deployment annotations, err := kubernetesservice.GetDeploymentAnnotations(deploymentName) if err != nil { - logging.Error(fmt.Errorf("could not get annotations of kubernetes deployment: %s", deploymentName)) + logging.Error(fmt.Sprintf("could not get annotations of kubernetes deployment: %s", deploymentName)) return time.Time{}, false } @@ -114,7 +114,7 @@ func getLastScalingTimestamp(deploymentName string) (time.Time, bool) { // convert to time.time tm, err := convertMillisToTime(timestamp) if err != nil { - logging.Error(fmt.Errorf("could not convert timestamp %s to time.time", timestamp)) + logging.Error(fmt.Sprintf("could not convert timestamp %s to time.time", timestamp)) return time.Time{}, false } return tm, true @@ -130,9 +130,9 @@ func scaleDeployments() { for _, function := range functions.Items { var resultScale int currentAvailableReplicas, err := prometheus.ReadCurrentPrometheusMetricValue(&configuration.ActiveConfiguration, fmt.Sprintf("kube_deployment_status_replicas_available{functionname=\"%s\"}", function.Name)) - logging.Error(err) + logging.Error(fmt.Sprintf("%s", err)) requiredContainers, err := prometheus.ReadCurrentPrometheusMetricValue(&configuration.ActiveConfiguration, fmt.Sprintf("job:function_containers_required:containers{functionname=\"%s\"}", function.Name)) - logging.Error(err) + logging.Error(fmt.Sprintf("%s", err)) if err != nil { // no invocations / metrics => scale to minimum resultScale = 0 @@ -145,8 +145,8 @@ func scaleDeployments() { // get current inflight requests of function target, err := f2shub.F2SDispatcherHub.GetDispatcherFunctionByName(function.Name) if err != nil { - logging.Error(err) - logging.Error(fmt.Errorf("[scaling] could not get function target for function-name: %s. skipping scaling of this function...", function.Name)) + logging.Error(fmt.Sprintf("%s", err)) + logging.Error(fmt.Sprintf("[scaling] could not get function target for function-name: %s. skipping scaling of this function...", function.Name)) continue } numInflightRequests := target.GetTotalInflightRequests() diff --git a/f2soperator/operation/operator/eventhandler.go b/f2soperator/operation/operator/eventhandler.go index c4a9465..0dcd9dd 100644 --- a/f2soperator/operation/operator/eventhandler.go +++ b/f2soperator/operation/operator/eventhandler.go @@ -36,7 +36,7 @@ func checkMinimumAvailability(function *v1alpha1types.PrettyFunction) { logging.Info("[checkMinimumAvailability] checking minimum availability") target, err := f2shub.F2SDispatcherHub.GetDispatcherFunctionByName(function.Name) if err != nil { - logging.Error(fmt.Errorf("[checkMinimumAvailability] could not get target for function %s. %s", function.Name, err.Error())) + logging.Error(fmt.Sprintf("[checkMinimumAvailability] could not get target for function %s. %s", function.Name, err.Error())) return } if len(target.ServingPods) == 0 { @@ -92,8 +92,8 @@ func OnF2SEndpointsChanged(obj interface{}) { err := runtime.DefaultUnstructuredConverter. FromUnstructured(obj.(*unstructured.Unstructured).UnstructuredContent(), d) if err != nil { - logging.Error(fmt.Errorf("could not convert event to endpoint")) - logging.Error(err) + logging.Error(fmt.Sprintf("could not convert event to endpoint")) + logging.Error(fmt.Sprintf("%s", err)) return } diff --git a/f2soperator/operation/operator/main.go b/f2soperator/operation/operator/main.go index 3ea0bb9..7b9ee55 100644 --- a/f2soperator/operation/operator/main.go +++ b/f2soperator/operation/operator/main.go @@ -7,6 +7,7 @@ import ( "butschi84/f2s/state/configuration" "butschi84/f2s/state/operatorstate" "fmt" + "log/slog" "os" "sort" "strconv" @@ -15,7 +16,7 @@ import ( kubernetesservice "butschi84/f2s/services/kubernetes" ) -var logging logger.F2SLogger +var logging *slog.Logger var f2shub *hub.F2SHub func init() { @@ -73,8 +74,8 @@ func CheckMaster() (bool, error) { logging.Debug("[check master] reading prometheus metric 'f2s_master_election_ready_pods'") result, err := prometheus.ReadPrometheusMetric(&configuration.ActiveConfiguration, "f2s_master_election_ready_pods") if err != nil { - logging.Error(err) - logging.Error(fmt.Errorf("[check master] prometheus seems not to be reachable. prometheus URL can also specified by 'export Prometheus_URL=localhost:9090'")) + logging.Error(fmt.Sprintf("%s", err)) + logging.Error(fmt.Sprintf("[check master] prometheus seems not to be reachable. prometheus URL can also specified by 'export Prometheus_URL=localhost:9090'")) } // get all f2s replica uid's diff --git a/f2soperator/services/kubernetes/deployments.go b/f2soperator/services/kubernetes/deployments.go index 6c07615..0ed5b6b 100644 --- a/f2soperator/services/kubernetes/deployments.go +++ b/f2soperator/services/kubernetes/deployments.go @@ -143,7 +143,7 @@ func DeleteDeployment(uid string) error { err = clientset.AppsV1().Deployments("f2s-containers").Delete(context.Background(), d.Name, metav1.DeleteOptions{}) if err != nil { - logging.Error(fmt.Errorf("error during deletion: %s", err)) + logging.Error(fmt.Sprintf("error during deletion: %s", err)) } return nil diff --git a/f2soperator/services/kubernetes/f2sfunctions.go b/f2soperator/services/kubernetes/f2sfunctions.go index 17f16e2..9dba8bd 100644 --- a/f2soperator/services/kubernetes/f2sfunctions.go +++ b/f2soperator/services/kubernetes/f2sfunctions.go @@ -16,7 +16,7 @@ func GetF2SFunctions() (*typesV1alpha1.FunctionList, error) { logging.Info("initializing k8s clientset") clientSet, err := GetV1Alpha1ClientSet() if err != nil { - logging.Error(fmt.Errorf("error during clientset initialisation: %s", err)) + logging.Error(fmt.Sprintf("error during clientset initialisation: %s", err)) panic(err) } @@ -37,7 +37,7 @@ func CreateF2SFunction(prettyFunction *typesV1alpha1.PrettyFunction) (*typesV1al logging.Info("initializing k8s clientset") clientSet, err := GetV1Alpha1ClientSet() if err != nil { - logging.Error(fmt.Errorf("error during clientset initialisation: %s", err)) + logging.Error(fmt.Sprintf("error during clientset initialisation: %s", err)) panic(err) } @@ -64,7 +64,7 @@ func CreateF2SFunction(prettyFunction *typesV1alpha1.PrettyFunction) (*typesV1al logging.Info("creating function in k8s") function, err := clientSet.Functions("f2s").Create(newFunction) if err != nil { - logging.Error(fmt.Errorf("error during function creation: %s", err)) + logging.Error(fmt.Sprintf("error during function creation: %s", err)) log.Fatal(err) } @@ -79,7 +79,7 @@ func DeleteF2SFunction(uid string) error { logging.Info("initializing k8s clientset") clientSet, err := GetV1Alpha1ClientSet() if err != nil { - logging.Error(fmt.Errorf("error during clientset initialisation: %s", err)) + logging.Error(fmt.Sprintf("error during clientset initialisation: %s", err)) panic(err) } @@ -87,7 +87,7 @@ func DeleteF2SFunction(uid string) error { err = clientSet.Functions("f2s").Delete(uid, metav1.DeleteOptions{}) if err != nil { - logging.Error(fmt.Errorf("error during deletion: %s", err)) + logging.Error(fmt.Sprintf("error during deletion: %s", err)) } return err diff --git a/f2soperator/services/kubernetes/kubernetes.go b/f2soperator/services/kubernetes/kubernetes.go index 018e078..79aba14 100644 --- a/f2soperator/services/kubernetes/kubernetes.go +++ b/f2soperator/services/kubernetes/kubernetes.go @@ -38,8 +38,8 @@ func GetV1Alpha1ClientSet() (*clientV1alpha1.V1Alpha1Client, error) { // Retrieve the in-cluster configuration config, err := getInClusterConfig() if err != nil { - logging.Error(fmt.Errorf("Failed to get in-cluster config: %s\n", err)) - logging.Error(fmt.Errorf("you can use env variable 'export KUBECONFIG=~/.kube/config' to specify a local config file")) + logging.Error(fmt.Sprintf("Failed to get in-cluster config: %s\n", err)) + logging.Error(fmt.Sprintf("you can use env variable 'export KUBECONFIG=~/.kube/config' to specify a local config file")) os.Exit(1) } @@ -57,8 +57,8 @@ func GetV1ClientSet() (*k8s.Clientset, error) { // Retrieve the in-cluster configuration config, err := getInClusterConfig() if err != nil { - logging.Error(fmt.Errorf("Failed to get in-cluster config: %s\n", err)) - logging.Error(fmt.Errorf("you can use env variable 'export KUBECONFIG=~/.kube/config' to specify a local config file")) + logging.Error(fmt.Sprintf("Failed to get in-cluster config: %s\n", err)) + logging.Error(fmt.Sprintf("you can use env variable 'export KUBECONFIG=~/.kube/config' to specify a local config file")) os.Exit(1) } diff --git a/f2soperator/services/kubernetes/main.go b/f2soperator/services/kubernetes/main.go index 2a0cfba..5ead5b3 100644 --- a/f2soperator/services/kubernetes/main.go +++ b/f2soperator/services/kubernetes/main.go @@ -2,9 +2,10 @@ package kubernetesservice import ( "butschi84/f2s/services/logger" + "log/slog" ) -var logging logger.F2SLogger +var logging *slog.Logger func init() { // initialize logging diff --git a/f2soperator/services/kubernetes/services.go b/f2soperator/services/kubernetes/services.go index 5f616b4..cffb1aa 100644 --- a/f2soperator/services/kubernetes/services.go +++ b/f2soperator/services/kubernetes/services.go @@ -79,7 +79,7 @@ func DeleteService(uid string) error { err = clientset.CoreV1().Services("f2s-containers").Delete(context.Background(), d.Name, metav1.DeleteOptions{}) if err != nil { - logging.Error(fmt.Errorf("error during deletion: %s", err)) + logging.Error(fmt.Sprintf("error during deletion: %s", err)) } return nil diff --git a/f2soperator/services/kubernetes/watch.go b/f2soperator/services/kubernetes/watch.go index abff76a..2cbce9c 100644 --- a/f2soperator/services/kubernetes/watch.go +++ b/f2soperator/services/kubernetes/watch.go @@ -52,7 +52,7 @@ func runCRDInformer(stopCh <-chan struct{}, s cache.SharedIndexInformer, callbac func GetDynamicInformer(resource string, namespace string) (informers.GenericInformer, error) { cfg, err := getInClusterConfig() if err != nil { - logging.Error(fmt.Errorf("Failed to get in-cluster config: %s\n", err.Error())) + logging.Error(fmt.Sprintf("Failed to get in-cluster config: %s\n", err.Error())) os.Exit(1) } diff --git a/f2soperator/services/logger/logging.go b/f2soperator/services/logger/logging.go index 97eb3b8..20fdc39 100644 --- a/f2soperator/services/logger/logging.go +++ b/f2soperator/services/logger/logging.go @@ -1,13 +1,10 @@ package logger import ( - "log" + "log/slog" "os" - "strings" ) -var packageName string - type IF2SLogger interface { Debug() Info() @@ -17,27 +14,9 @@ type IF2SLogger interface { type F2SLogger struct { ComponentName string - Logger *log.Logger -} - -func Initialize(ComponentName string) F2SLogger { - return F2SLogger{ - ComponentName: ComponentName, - Logger: log.New(os.Stdout, "component=\""+ComponentName+"\" ", log.LstdFlags), - } + Logger *slog.Logger } -func (l F2SLogger) Info(text ...string) { - l.Logger.Printf("loglevel=info msg=\"%s\"", strings.Join(text, " ")) -} -func (l F2SLogger) Debug(text ...string) { - l.Logger.Printf("loglevel=debug msg=\"%s\"", strings.Join(text, " ")) -} -func (l F2SLogger) Warn(text ...string) { - l.Logger.Printf("loglevel=warn msg=\"%s\"", strings.Join(text, " ")) -} -func (l F2SLogger) Error(err error) { - if err != nil { - l.Logger.Printf("loglevel=error msg=\"%s\"", err.Error()) - } +func Initialize(ComponentName string) *slog.Logger { + return slog.New(slog.NewTextHandler(os.Stdout, nil)).With("component", ComponentName) } diff --git a/f2soperator/state/configuration/api/clientset/v1alpha1/functions.go b/f2soperator/state/configuration/api/clientset/v1alpha1/functions.go index 7a09a5c..09d0b1e 100644 --- a/f2soperator/state/configuration/api/clientset/v1alpha1/functions.go +++ b/f2soperator/state/configuration/api/clientset/v1alpha1/functions.go @@ -36,7 +36,7 @@ func (c *functionClient) List(opts metav1.ListOptions) (*v1alpha1.FunctionList, //VersionedParams(&opts, scheme.ParameterCodec). Do(ctx). Into(&result) - logging.Error(err) + logging.Error(fmt.Sprintf("%s", err)) return &result, err } @@ -51,7 +51,7 @@ func (c *functionClient) Get(name string, opts metav1.GetOptions) (*v1alpha1.Fun VersionedParams(&opts, scheme.ParameterCodec) err := req.Do(ctx).Into(&result) - logging.Error(err) + logging.Error(fmt.Sprintf("%s", err)) return &result, err } @@ -65,7 +65,7 @@ func (c *functionClient) Create(project *v1alpha1.Function) (*v1alpha1.Function, Body(project) err := req.Do(ctx).Into(&result) - logging.Error(err) + logging.Error(fmt.Sprintf("%s", err)) return &result, err } @@ -99,11 +99,11 @@ func (c *functionClient) Delete(uid string, opts metav1.DeleteOptions) error { Name(f.Name). Do(ctx). Error() - logging.Error(err) + logging.Error(fmt.Sprintf("%s", err)) return err } } - logging.Error(fmt.Errorf("function could not be found")) + logging.Error(fmt.Sprint("function could not be found")) return fmt.Errorf("function could not be found") } diff --git a/f2soperator/state/configuration/api/clientset/v1alpha1/main.go b/f2soperator/state/configuration/api/clientset/v1alpha1/main.go index 743a744..48dec31 100644 --- a/f2soperator/state/configuration/api/clientset/v1alpha1/main.go +++ b/f2soperator/state/configuration/api/clientset/v1alpha1/main.go @@ -2,9 +2,10 @@ package v1alpha1 import ( "butschi84/f2s/services/logger" + "log/slog" ) -var logging logger.F2SLogger +var logging *slog.Logger func init() { // initialize logging diff --git a/f2soperator/state/configuration/main.go b/f2soperator/state/configuration/main.go index 87106f3..4a423c6 100644 --- a/f2soperator/state/configuration/main.go +++ b/f2soperator/state/configuration/main.go @@ -5,12 +5,13 @@ import ( "butschi84/f2s/services/logger" "fmt" "log" + "log/slog" "os" "gopkg.in/yaml.v2" ) -var logging logger.F2SLogger +var logging *slog.Logger var ActiveConfiguration F2SConfiguration diff --git a/f2soperator/state/dispatcherstate/main.go b/f2soperator/state/dispatcherstate/main.go index 83f3474..106a7de 100644 --- a/f2soperator/state/dispatcherstate/main.go +++ b/f2soperator/state/dispatcherstate/main.go @@ -2,9 +2,10 @@ package dispatcherstate import ( "butschi84/f2s/services/logger" + "log/slog" ) -var logging logger.F2SLogger +var logging *slog.Logger var functionTargets F2SDispatcherHub diff --git a/f2soperator/state/queue/main.go b/f2soperator/state/queue/main.go index 89ea375..d0f50b8 100644 --- a/f2soperator/state/queue/main.go +++ b/f2soperator/state/queue/main.go @@ -3,9 +3,10 @@ package queue import ( "butschi84/f2s/services/logger" "fmt" + "log/slog" ) -var logging logger.F2SLogger +var logging *slog.Logger func init() { // initialize logging