Skip to content

Commit

Permalink
Allow to set log level through environment variable (fission#1217)
Browse files Browse the repository at this point in the history
  • Loading branch information
life1347 authored Jul 6, 2019
1 parent 78a774c commit 9d13081
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 59 deletions.
119 changes: 72 additions & 47 deletions charts/fission-all/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,16 @@ spec:
command: ["/fission-bundle"]
args: ["--controllerPort", "8888", "--collectorEndpoint", "{{ .Values.traceCollectorEndpoint }}"]
env:
- name: FISSION_FUNCTION_NAMESPACE
value: "{{ .Values.functionNamespace }}"
- name: TRACING_SAMPLING_RATE
value: {{ .Values.traceSamplingRate | default "0.5" | quote }}
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: FISSION_FUNCTION_NAMESPACE
value: "{{ .Values.functionNamespace }}"
- name: TRACING_SAMPLING_RATE
value: {{ .Values.traceSamplingRate | default "0.5" | quote }}
- name: DEBUG_ENV
value: {{ .Values.debugEnv | quote }}
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
readinessProbe:
httpGet:
path: "/healthz"
Expand All @@ -158,6 +160,9 @@ spec:
- name: config-volume
mountPath: /etc/config/config.yaml
subPath: config.yaml
ports:
- containerPort: 8888
name: http
serviceAccount: fission-svc
volumes:
- name: config-volume
Expand Down Expand Up @@ -192,32 +197,32 @@ spec:
command: ["/fission-bundle"]
args: ["--routerPort", "8888", "--executorUrl", "https://executor.{{ .Release.Namespace }}", "--collectorEndpoint", "{{ .Values.traceCollectorEndpoint }}"]
env:
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: ROUTER_ROUND_TRIP_TIMEOUT
value: {{ .Values.routerRoundTripTimeout | default "50ms" | quote }}
- name: ROUTER_ROUNDTRIP_TIMEOUT_EXPONENT
value: {{ .Values.routerRoundTripTimeoutExponent | default 2 | quote }}
- name: ROUTER_ROUND_TRIP_KEEP_ALIVE_TIME
value: {{ .Values.routerRoundTripKeepAliveTime | default "30s" | quote }}
- name: ROUTER_ROUND_TRIP_MAX_RETRIES
value: {{ .Values.routerRoundTripMaxRetries | default 10 | quote }}
- name: ROUTER_ROUND_TRIP_SVC_ADDRESS_MAX_RETRIES
value: {{ .Values.routerRoundTripSvcAddressMaxRetries | default 5 | quote }}
- name: ROUTER_ROUND_TRIP_SVC_ADDRESS_UPDATE_TIMEOUT
value: {{ .Values.routerRoundTripSvcAddressUpdateTimeout | default 30 | quote }}
- name: DEBUG_ENV
value: {{ .Values.debugEnv | quote }}
- name: TRACING_SAMPLING_RATE
value: {{ .Values.traceSamplingRate | default "0.5" | quote }}
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: ROUTER_ROUND_TRIP_TIMEOUT
value: {{ .Values.routerRoundTripTimeout | default "50ms" | quote }}
- name: ROUTER_ROUNDTRIP_TIMEOUT_EXPONENT
value: {{ .Values.routerRoundTripTimeoutExponent | default 2 | quote }}
- name: ROUTER_ROUND_TRIP_KEEP_ALIVE_TIME
value: {{ .Values.routerRoundTripKeepAliveTime | default "30s" | quote }}
- name: ROUTER_ROUND_TRIP_MAX_RETRIES
value: {{ .Values.routerRoundTripMaxRetries | default 10 | quote }}
- name: ROUTER_ROUND_TRIP_SVC_ADDRESS_MAX_RETRIES
value: {{ .Values.routerRoundTripSvcAddressMaxRetries | default 5 | quote }}
- name: ROUTER_ROUND_TRIP_SVC_ADDRESS_UPDATE_TIMEOUT
value: {{ .Values.routerRoundTripSvcAddressUpdateTimeout | default 30 | quote }}
- name: DEBUG_ENV
value: {{ .Values.debugEnv | quote }}
- name: TRACING_SAMPLING_RATE
value: {{ .Values.traceSamplingRate | default "0.5" | quote }}
{{ if .Values.analytics }}
- name: ANALYTICS_URL
value: "https://g.fission.sh/metrics"
- name: ANALYTICS_URL
value: "https://g.fission.sh/metrics"
{{ else if .Values.analyticsNonHelmInstall }}
- name: ANALYTICS_URL
value: "https://g.fission.sh/metrics"
- name: ANALYTICS_URL
value: "https://g.fission.sh/metrics"
{{ end }}
readinessProbe:
httpGet:
Expand Down Expand Up @@ -303,6 +308,8 @@ spec:
value: {{ .Values.fetcherMaxMem | default "128Mi" | quote }}
- name: TRACING_SAMPLING_RATE
value: {{ .Values.traceSamplingRate | default "0.5" | quote }}
- name: DEBUG_ENV
value: {{ .Values.debugEnv | quote }}
readinessProbe:
httpGet:
path: "/healthz"
Expand Down Expand Up @@ -366,7 +373,9 @@ spec:
- name: FETCHER_MAXCPU
value: {{ .Values.fetcherMaxCpu | default "1000m" | quote }}
- name: FETCHER_MAXMEM
value: {{ .Values.fetcherMaxMem | default "128Mi" | quote }}
value: {{ .Values.fetcherMaxMem | default "128Mi" | quote }}
- name: DEBUG_ENV
value: {{ .Values.debugEnv | quote }}
serviceAccount: fission-svc
{{- if .Values.extraCoreComponmentPodConfig }}
{{ toYaml .Values.extraCoreComponmentPodConfig | indent 6 -}}
Expand Down Expand Up @@ -395,6 +404,8 @@ spec:
env:
- name: TRACING_SAMPLING_RATE
value: {{ .Values.traceSamplingRate | default "0.5" | quote }}
- name: DEBUG_ENV
value: {{ .Values.debugEnv | quote }}
serviceAccount: fission-svc
{{- if .Values.extraCoreComponmentPodConfig }}
{{ toYaml .Values.extraCoreComponmentPodConfig | indent 6 -}}
Expand Down Expand Up @@ -435,18 +446,18 @@ spec:
image: fission/influxdb
imagePullPolicy: {{ .Values.pullPolicy }}
env:
- name: PRE_CREATE_DB
value: fissionFunctionLog
- name: ADMIN_USER
valueFrom:
secretKeyRef:
name: influxdb
key: username
- name: INFLUXDB_INIT_PWD
valueFrom:
secretKeyRef:
name: influxdb
key: password
- name: PRE_CREATE_DB
value: fissionFunctionLog
- name: ADMIN_USER
valueFrom:
secretKeyRef:
name: influxdb
key: username
- name: INFLUXDB_INIT_PWD
valueFrom:
secretKeyRef:
name: influxdb
key: password
{{- if .Values.extraCoreComponmentPodConfig }}
{{ toYaml .Values.extraCoreComponmentPodConfig | indent 6 -}}
{{- end }}
Expand Down Expand Up @@ -514,6 +525,9 @@ spec:
imagePullPolicy: {{ .Values.pullPolicy }}
command: ["/fission-bundle"]
args: ["--timer", "--routerUrl", "https://router.{{ .Release.Namespace }}"]
env:
- name: DEBUG_ENV
value: {{ .Values.debugEnv | quote }}
serviceAccount: fission-svc
{{- if .Values.extraCoreComponmentPodConfig }}
{{ toYaml .Values.extraCoreComponmentPodConfig | indent 6 -}}
Expand Down Expand Up @@ -622,7 +636,9 @@ spec:
- name: MESSAGE_QUEUE_URL
value: nats:https://{{ .Values.nats.authToken }}@nats-streaming:4222
- name: TRACING_SAMPLING_RATE
value: {{ .Values.traceSamplingRate | default "0.5" | quote }}
value: {{ .Values.traceSamplingRate | default "0.5" | quote }}
- name: DEBUG_ENV
value: {{ .Values.debugEnv | quote }}
serviceAccount: fission-svc
{{- if .Values.extraCoreComponmentPodConfig }}
{{ toYaml .Values.extraCoreComponmentPodConfig | indent 6 -}}
Expand Down Expand Up @@ -659,7 +675,9 @@ spec:
- name: MESSAGE_QUEUE_KAFKA_VERSION
value: "{{.Values.kafka.version}}"
- name: TRACING_SAMPLING_RATE
value: {{ .Values.traceSamplingRate | default "0.5" | quote }}
value: {{ .Values.traceSamplingRate | default "0.5" | quote }}
- name: DEBUG_ENV
value: {{ .Values.debugEnv | quote }}
serviceAccount: fission-svc
{{- if .Values.extraCoreComponmentPodConfig }}
{{ toYaml .Values.extraCoreComponmentPodConfig | indent 6 -}}
Expand Down Expand Up @@ -700,6 +718,8 @@ spec:
secretKeyRef:
name: azure-storage-account-key
key: key
- name: DEBUG_ENV
value: {{ .Values.debugEnv | quote }}
serviceAccount: fission-svc
{{- if .Values.extraCoreComponmentPodConfig }}
{{ toYaml .Values.extraCoreComponmentPodConfig | indent 6 -}}
Expand Down Expand Up @@ -731,6 +751,8 @@ spec:
value: {{ .Values.traceSamplingRate | default "0.5" | quote }}
- name: PRUNE_INTERVAL
value: "{{.Values.pruneInterval}}"
- name: DEBUG_ENV
value: {{ .Values.debugEnv | quote }}
volumeMounts:
- name: fission-storage
mountPath: /fission
Expand All @@ -747,6 +769,9 @@ spec:
port: 8000
initialDelaySeconds: 35
periodSeconds: 5
ports:
- containerPort: 8000
name: http
serviceAccount: fission-svc
volumes:
- name: fission-storage
Expand Down
2 changes: 1 addition & 1 deletion charts/fission-all/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ preUpgradeChecksImage: fission/pre-upgrade-checks

## if there are any pod specialization errors when a function is triggered and this flag is set to true, the error
## summary is returned as part of http response
debugEnv: true
debugEnv: false


## set this flag to true if prometheus needs to be deployed along with fission
Expand Down
16 changes: 16 additions & 0 deletions charts/fission-core/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ spec:
- name: config-volume
mountPath: /etc/config/config.yaml
subPath: config.yaml
ports:
- containerPort: 8888
name: http
serviceAccount: fission-svc
volumes:
- name: config-volume
Expand Down Expand Up @@ -234,6 +237,11 @@ spec:
port: 8888
initialDelaySeconds: 35
periodSeconds: 5
ports:
- containerPort: 8080
name: metrics
- containerPort: 8888
name: http
serviceAccount: fission-svc
{{- if .Values.extraCoreComponmentPodConfig }}
{{ toYaml .Values.extraCoreComponmentPodConfig | indent 6 -}}
Expand Down Expand Up @@ -311,6 +319,11 @@ spec:
port: 8888
initialDelaySeconds: 35
periodSeconds: 5
ports:
- containerPort: 8080
name: metrics
- containerPort: 8888
name: http
serviceAccount: fission-svc
{{- if .Values.extraCoreComponmentPodConfig }}
{{ toYaml .Values.extraCoreComponmentPodConfig | indent 6 -}}
Expand Down Expand Up @@ -447,6 +460,9 @@ spec:
volumeMounts:
- name: fission-storage
mountPath: /fission
ports:
- containerPort: 8000
name: http
serviceAccount: fission-svc
volumes:
- name: fission-storage
Expand Down
2 changes: 1 addition & 1 deletion charts/fission-core/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ preUpgradeChecksImage: fission/pre-upgrade-checks

## if there are any pod specialization errors when a function is triggered and this flag is set to true, the error
## summary is returned as part of http response
debugEnv: true
debugEnv: false

## set this flag to true if prometheus needs to be deployed along with fission
prometheusDeploy: false
Expand Down
11 changes: 10 additions & 1 deletion cmd/fission-bundle/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,16 @@ Options:
--builderMgr Start builder manager.
--version Print version information
`
logger, err := zap.NewProduction()

var logger *zap.Logger
var err error

isDebugEnv, _ := strconv.ParseBool(os.Getenv("DEBUG_ENV"))
if isDebugEnv {
logger, err = zap.NewDevelopment()
} else {
logger, err = zap.NewProduction()
}
if err != nil {
log.Fatalf("can't initialize zap logger: %v", err)
}
Expand Down
16 changes: 8 additions & 8 deletions pkg/utils/rbacutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func AddSaToRoleBindingWithRetries(logger *zap.Logger, k8sClient *kubernetes.Cli
rbObj := makeRoleBindingObj(roleBinding, roleBindingNs, role, roleKind, sa, saNamespace)
rbObj, err = k8sClient.RbacV1beta1().RoleBindings(roleBindingNs).Create(rbObj)
if err == nil {
logger.Info("created rolebinding",
logger.Debug("created rolebinding",
zap.String("role_binding", roleBinding),
zap.String("role_binding_namespace", roleBindingNs))
return err
Expand Down Expand Up @@ -181,7 +181,7 @@ func RemoveSAFromRoleBindingWithRetries(logger *zap.Logger, k8sClient *kubernete
roleBinding, metav1.GetOptions{})
if err != nil {
// silently ignoring the error. there's no need for us to remove sa anymore.
logger.Info("rolebinding not found, but ignoring the error since we're cleaning up",
logger.Debug("rolebinding not found, but ignoring the error since we're cleaning up",
zap.Error(err),
zap.String("role_binding", roleBinding),
zap.String("role_binding_namespace", roleBindingNs))
Expand Down Expand Up @@ -213,13 +213,13 @@ func RemoveSAFromRoleBindingWithRetries(logger *zap.Logger, k8sClient *kubernete
_, err = k8sClient.RbacV1beta1().RoleBindings(rbObj.Namespace).Update(rbObj)
switch {
case err == nil:
logger.Info("removed service accounts from rolebinding",
logger.Debug("removed service accounts from rolebinding",
zap.Any("service_accounts", saToRemove),
zap.String("role_binding", roleBinding),
zap.String("role_binding_namespace", roleBindingNs))
return nil
case k8serrors.IsConflict(err):
logger.Info("conflict in update of rolebinding - retrying",
logger.Error("conflict in update of rolebinding - retrying",
zap.Error(err),
zap.String("role_binding", roleBinding),
zap.String("role_binding_namespace", roleBindingNs))
Expand All @@ -241,14 +241,14 @@ func SetupRoleBinding(logger *zap.Logger, k8sClient *kubernetes.Clientset, roleB

if err == nil {
if !isSAInRoleBinding(rbObj, sa, saNamespace) {
logger.Info("service account is not present in the rolebinding - will add",
logger.Debug("service account is not present in the rolebinding - will add",
zap.String("service_account_name", sa),
zap.String("service_account_namespace", saNamespace),
zap.String("role_binding", roleBinding),
zap.String("role_binding_namespace", roleBindingNs))
return AddSaToRoleBindingWithRetries(logger, k8sClient, roleBinding, roleBindingNs, sa, saNamespace, role, roleKind)
}
logger.Info("service account already present in rolebinding so nothing to add",
logger.Debug("service account already present in rolebinding so nothing to add",
zap.String("service_account_name", sa),
zap.String("service_account_namespace", saNamespace),
zap.String("role_binding", roleBinding),
Expand All @@ -258,14 +258,14 @@ func SetupRoleBinding(logger *zap.Logger, k8sClient *kubernetes.Clientset, roleB

// if role binding is missing, create it. also add this sa to the binding.
if k8serrors.IsNotFound(err) {
logger.Info("rolebinding does NOT exist in namespace - creating it",
logger.Debug("rolebinding does NOT exist in namespace - creating it",
zap.Error(err),
zap.String("role_binding", roleBinding),
zap.String("role_binding_namespace", roleBindingNs))
rbObj = makeRoleBindingObj(roleBinding, roleBindingNs, role, roleKind, sa, saNamespace)
rbObj, err = k8sClient.RbacV1beta1().RoleBindings(roleBindingNs).Create(rbObj)
if k8serrors.IsAlreadyExists(err) {
logger.Info("rolebinding already exists in namespace - adding service account to rolebinding",
logger.Debug("rolebinding already exists in namespace - adding service account to rolebinding",
zap.String("service_account_name", sa),
zap.String("service_account_namespace", saNamespace),
zap.String("role_binding", roleBinding),
Expand Down
2 changes: 1 addition & 1 deletion test/test_utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ helm_install_fission() {
ns=f-$id
fns=f-func-$id

helmVars=repository=$repo,image=$image,imageTag=$imageTag,fetcherImage=$fetcherImage,fetcherImageTag=$fetcherImageTag,functionNamespace=$fns,controllerPort=$controllerNodeport,routerPort=$routerNodeport,pullPolicy=Always,analytics=false,pruneInterval=$pruneInterval,routerServiceType=$routerServiceType,serviceType=$serviceType,preUpgradeChecksImage=$preUpgradeCheckImage,prometheus.server.persistentVolume.enabled=false,prometheus.alertmanager.enabled=false,prometheus.kubeStateMetrics.enabled=false,prometheus.nodeExporter.enabled=false
helmVars=repository=$repo,image=$image,imageTag=$imageTag,fetcherImage=$fetcherImage,fetcherImageTag=$fetcherImageTag,functionNamespace=$fns,controllerPort=$controllerNodeport,routerPort=$routerNodeport,pullPolicy=Always,analytics=false,debugEnv=true,pruneInterval=$pruneInterval,routerServiceType=$routerServiceType,serviceType=$serviceType,preUpgradeChecksImage=$preUpgradeCheckImage,prometheus.server.persistentVolume.enabled=false,prometheus.alertmanager.enabled=false,prometheus.kubeStateMetrics.enabled=false,prometheus.nodeExporter.enabled=false

timeout 30 bash -c "helm_setup"

Expand Down

0 comments on commit 9d13081

Please sign in to comment.