+9
-7
@@ -24,7 +24,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"go.uber.org/zap"
|
||||
apiv1 "k8s.io/api/core/v1"
|
||||
kerrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
@@ -46,6 +46,7 @@ func init() {
|
||||
|
||||
type (
|
||||
API struct {
|
||||
logger *zap.Logger
|
||||
fissionClient *crd.FissionClient
|
||||
kubernetesClient *kubernetes.Clientset
|
||||
storageServiceUrl string
|
||||
@@ -63,8 +64,8 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
func MakeAPI(featureStatus map[string]string) (*API, error) {
|
||||
api, err := makeCRDBackedAPI()
|
||||
func MakeAPI(logger *zap.Logger, featureStatus map[string]string) (*API, error) {
|
||||
api, err := makeCRDBackedAPI(logger)
|
||||
|
||||
u := os.Getenv("STORAGE_SERVICE_URL")
|
||||
if len(u) > 0 {
|
||||
@@ -119,7 +120,7 @@ func (api *API) respondWithError(w http.ResponseWriter, err error) {
|
||||
}
|
||||
|
||||
code, msg := fission.GetHTTPError(err)
|
||||
log.Errorf("Error: %v: %v", code, msg)
|
||||
api.logger.Error(msg, zap.Int("code", code))
|
||||
http.Error(w, msg, code)
|
||||
}
|
||||
|
||||
@@ -270,7 +271,8 @@ func (api *API) Serve(port int) {
|
||||
|
||||
address := fmt.Sprintf(":%v", port)
|
||||
|
||||
log.WithFields(log.Fields{"port": port}).Info("Server started")
|
||||
r.Use(fission.LoggingMiddleware)
|
||||
log.Fatal(http.ListenAndServe(address, r))
|
||||
api.logger.Info("server started", zap.Int("port", port))
|
||||
r.Use(fission.LoggingMiddleware(api.logger))
|
||||
err := http.ListenAndServe(address, r)
|
||||
api.logger.Fatal("done listening", zap.Error(err))
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"go.uber.org/zap"
|
||||
"k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
@@ -344,7 +345,10 @@ func TestMain(m *testing.M) {
|
||||
return
|
||||
}
|
||||
|
||||
go Start(8888, true)
|
||||
logger, err := zap.NewDevelopment()
|
||||
panicIf(err)
|
||||
|
||||
go Start(logger, 8888, true)
|
||||
|
||||
time.Sleep(5 * time.Second)
|
||||
g.client = client.MakeClient("http://localhost:8888")
|
||||
|
||||
@@ -23,7 +23,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"go.uber.org/zap"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
"github.com/fission/fission"
|
||||
@@ -47,7 +47,7 @@ func (a *API) CanaryConfigApiCreate(w http.ResponseWriter, r *http.Request) {
|
||||
var canaryCfg crd.CanaryConfig
|
||||
err = json.Unmarshal(body, &canaryCfg)
|
||||
if err != nil {
|
||||
log.Printf("Failed to unmarshal request body: [%v]", body)
|
||||
a.logger.Error("failed to unmarshal request body", zap.Error(err), zap.Binary("body", body))
|
||||
a.respondWithError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -18,9 +18,9 @@ package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/pkg/errors"
|
||||
"go.uber.org/zap"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
|
||||
"github.com/fission/fission/canaryconfigmgr"
|
||||
@@ -28,24 +28,24 @@ import (
|
||||
config "github.com/fission/fission/featureconfig"
|
||||
)
|
||||
|
||||
func ConfigCanaryFeature(context context.Context, fissionClient *crd.FissionClient, kubeClient *kubernetes.Clientset, featureConfig *config.FeatureConfig, featureStatus map[string]string) error {
|
||||
func ConfigCanaryFeature(context context.Context, logger *zap.Logger, fissionClient *crd.FissionClient, kubeClient *kubernetes.Clientset, featureConfig *config.FeatureConfig, featureStatus map[string]string) error {
|
||||
// start the appropriate controller
|
||||
if featureConfig.CanaryConfig.IsEnabled {
|
||||
canaryCfgMgr, err := canaryconfigmgr.MakeCanaryConfigMgr(fissionClient, kubeClient, fissionClient.GetCrdClient(),
|
||||
canaryCfgMgr, err := canaryconfigmgr.MakeCanaryConfigMgr(logger, fissionClient, kubeClient, fissionClient.GetCrdClient(),
|
||||
featureConfig.CanaryConfig.PrometheusSvc)
|
||||
if err != nil {
|
||||
featureStatus[config.CanaryFeature] = err.Error()
|
||||
return fmt.Errorf("failed to start canary config manager: %v", err)
|
||||
return errors.Wrap(err, "failed to start canary config manager")
|
||||
}
|
||||
canaryCfgMgr.Run(context)
|
||||
log.Printf("Started canary config manager")
|
||||
logger.Info("started canary config manager")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ConfigureFeatures gets the feature config and configures the features that are enabled
|
||||
func ConfigureFeatures(context context.Context, unitTestMode bool, fissionClient *crd.FissionClient, kubeClient *kubernetes.Clientset) (map[string]string, error) {
|
||||
func ConfigureFeatures(context context.Context, logger *zap.Logger, unitTestMode bool, fissionClient *crd.FissionClient, kubeClient *kubernetes.Clientset) (map[string]string, error) {
|
||||
// set feature enabled to false if unitTestMode
|
||||
if unitTestMode {
|
||||
return nil, nil
|
||||
@@ -54,7 +54,7 @@ func ConfigureFeatures(context context.Context, unitTestMode bool, fissionClient
|
||||
// get the featureConfig from config map mounted onto the file system
|
||||
featureConfig, err := config.GetFeatureConfig()
|
||||
if err != nil {
|
||||
log.Printf("Error getting feature config : %v", err)
|
||||
logger.Error("error getting feature config", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -62,6 +62,6 @@ func ConfigureFeatures(context context.Context, unitTestMode bool, fissionClient
|
||||
|
||||
// configure respective features
|
||||
// in the future when new optional features are added, we need to add corresponding feature handlers and invoke them here
|
||||
err = ConfigCanaryFeature(context, fissionClient, kubeClient, featureConfig, featureStatus)
|
||||
err = ConfigCanaryFeature(context, logger, fissionClient, kubeClient, featureConfig, featureStatus)
|
||||
return featureStatus, err
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"go.uber.org/zap"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
@@ -35,7 +35,7 @@ func (a *API) ConfigMapGet(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
configMap, err := a.kubernetesClient.CoreV1().ConfigMaps(ns).Get(name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
log.Printf("Error getting config map: %s from ns: %s", name, ns)
|
||||
a.logger.Error("error getting config map", zap.Error(err), zap.String("config_map_name", name), zap.String("namespace", ns))
|
||||
a.respondWithError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
+12
-10
@@ -18,41 +18,43 @@ package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/fission/fission"
|
||||
"github.com/fission/fission/crd"
|
||||
)
|
||||
|
||||
func Start(port int, unitTestFlag bool) {
|
||||
func Start(logger *zap.Logger, port int, unitTestFlag bool) {
|
||||
cLogger := logger.Named("controller")
|
||||
// setup a signal handler for SIGTERM
|
||||
fission.SetupStackTraceHandler()
|
||||
|
||||
fc, kc, apiExtClient, err := crd.MakeFissionClient()
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to connect to K8s API: %v", err)
|
||||
cLogger.Fatal("failed to connect to k8s API", zap.Error(err))
|
||||
}
|
||||
|
||||
err = crd.EnsureFissionCRDs(apiExtClient)
|
||||
err = crd.EnsureFissionCRDs(cLogger, apiExtClient)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to create fission CRDs: %v", err)
|
||||
cLogger.Fatal("failed to create fission CRDs", zap.Error(err))
|
||||
}
|
||||
|
||||
err = fc.WaitForCRDs()
|
||||
if err != nil {
|
||||
log.Fatalf("Error waiting for CRDs: %v", err)
|
||||
cLogger.Fatal("error waiting for CRDs", zap.Error(err))
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
featureStatus, err := ConfigureFeatures(ctx, unitTestFlag, fc, kc)
|
||||
featureStatus, err := ConfigureFeatures(ctx, cLogger, unitTestFlag, fc, kc)
|
||||
if err != nil {
|
||||
log.Printf("Error configuring features : %v. Proceeding without optional features", err.Error())
|
||||
cLogger.Info("error configuring features - proceeding without optional features", zap.Error(err))
|
||||
}
|
||||
defer cancel()
|
||||
|
||||
api, err := MakeAPI(featureStatus)
|
||||
api, err := MakeAPI(cLogger, featureStatus)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to start controller: %v", err)
|
||||
cLogger.Fatal("failed to start controller", zap.Error(err))
|
||||
}
|
||||
api.Serve(port)
|
||||
}
|
||||
|
||||
+8
-2
@@ -17,13 +17,19 @@ limitations under the License.
|
||||
package controller
|
||||
|
||||
import (
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/fission/fission/crd"
|
||||
)
|
||||
|
||||
func makeCRDBackedAPI() (*API, error) {
|
||||
func makeCRDBackedAPI(logger *zap.Logger) (*API, error) {
|
||||
fissionClient, kubernetesClient, _, err := crd.MakeFissionClient()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &API{fissionClient: fissionClient, kubernetesClient: kubernetesClient}, nil
|
||||
return &API{
|
||||
logger: logger.Named("api"),
|
||||
fissionClient: fissionClient,
|
||||
kubernetesClient: kubernetesClient,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"go.uber.org/zap"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
"github.com/fission/fission"
|
||||
@@ -60,7 +60,7 @@ func (a *API) EnvironmentApiCreate(w http.ResponseWriter, r *http.Request) {
|
||||
var env crd.Environment
|
||||
err = json.Unmarshal(body, &env)
|
||||
if err != nil {
|
||||
log.Printf("Failed to unmarshal request body: [%v]", body)
|
||||
a.logger.Error("failed to unmarshal request body", zap.Error(err), zap.Binary("body", body))
|
||||
a.respondWithError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ import (
|
||||
"sort"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"go.uber.org/zap"
|
||||
apiv1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
restclient "k8s.io/client-go/rest"
|
||||
@@ -188,7 +188,9 @@ func (a *API) FunctionLogsApiPost(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
svcUrl, err := url.Parse(dbCnf.httpURL)
|
||||
if err != nil {
|
||||
log.Printf("Failed to establish proxy server for function logs: %v", err)
|
||||
a.logger.Error("failed parse url to establish proxy to database for function logs",
|
||||
zap.Error(err),
|
||||
zap.String("database_url", dbCnf.httpURL))
|
||||
}
|
||||
// set up proxy server director
|
||||
director := func(req *http.Request) {
|
||||
|
||||
@@ -26,7 +26,7 @@ import (
|
||||
)
|
||||
|
||||
func (a *API) RecordsApiListAll(w http.ResponseWriter, r *http.Request) {
|
||||
resp, err := redis.RecordsListAll()
|
||||
resp, err := redis.RecordsListAll(a.logger.Named("redis"))
|
||||
if err != nil {
|
||||
a.respondWithError(w, err)
|
||||
return
|
||||
@@ -50,7 +50,7 @@ func (a *API) RecordsApiFilterByFunction(w http.ResponseWriter, r *http.Request)
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := redis.RecordsFilterByFunction(query, recorders, triggers)
|
||||
resp, err := redis.RecordsFilterByFunction(a.logger.Named("redis"), query, recorders, triggers)
|
||||
if err != nil {
|
||||
a.respondWithError(w, err)
|
||||
return
|
||||
@@ -74,7 +74,7 @@ func (a *API) RecordsApiFilterByTrigger(w http.ResponseWriter, r *http.Request)
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := redis.RecordsFilterByTrigger(query, recorders, triggers)
|
||||
resp, err := redis.RecordsFilterByTrigger(a.logger.Named("redis"), query, recorders, triggers)
|
||||
if err != nil {
|
||||
a.respondWithError(w, err)
|
||||
return
|
||||
@@ -86,7 +86,7 @@ func (a *API) RecordsApiFilterByTime(w http.ResponseWriter, r *http.Request) {
|
||||
from := r.FormValue("from")
|
||||
to := r.FormValue("to")
|
||||
|
||||
resp, err := redis.RecordsFilterByTime(from, to)
|
||||
resp, err := redis.RecordsFilterByTime(a.logger.Named("redis"), from, to)
|
||||
if err != nil {
|
||||
a.respondWithError(w, err)
|
||||
return
|
||||
|
||||
@@ -31,7 +31,7 @@ func (a *API) ReplayByReqUID(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
routerUrl := fmt.Sprintf("http://router.%v", podNamespace)
|
||||
|
||||
resp, err := redis.ReplayByReqUID(routerUrl, queriedID)
|
||||
resp, err := redis.ReplayByReqUID(a.logger, routerUrl, queriedID)
|
||||
if err != nil {
|
||||
a.respondWithError(w, err)
|
||||
return
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"go.uber.org/zap"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
@@ -35,7 +35,10 @@ func (a *API) SecretGet(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
secret, err := a.kubernetesClient.CoreV1().Secrets(ns).Get(name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
log.Printf("Error getting secret: %s from ns: %s", name, ns)
|
||||
a.logger.Error("error getting secret",
|
||||
zap.Error(err),
|
||||
zap.String("secret_name", name),
|
||||
zap.String("namespace", ns))
|
||||
a.respondWithError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -18,19 +18,20 @@ package controller
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
"net/url"
|
||||
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func (api *API) StorageServiceProxy(w http.ResponseWriter, r *http.Request) {
|
||||
u := api.storageServiceUrl
|
||||
ssUrl, err := url.Parse(u)
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("Error parsing url %v: %v", u, err)
|
||||
log.Println(msg)
|
||||
http.Error(w, msg, http.StatusInternalServerError)
|
||||
e := "error parsing url"
|
||||
api.logger.Error(e, zap.Error(err), zap.String("url", u))
|
||||
http.Error(w, fmt.Sprintf("%s %s: %v", e, u, err), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
director := func(req *http.Request) {
|
||||
|
||||
@@ -2,10 +2,11 @@ package controller
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gorilla/mux"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
"net/url"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
func (api *API) WorkflowApiserverProxy(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
Reference in New Issue
Block a user