Removed call to InfluxDB via controller proxy (#2638)
* handle error condition in fission fn log command * use the single stream for log exclude fetcher logs * add all pods in the fn logs command * update the previous stable version * remove proxy to the controller for influxdb call * stop running controller if influxdb flag turned true * port-forward for influx DB * remove controller dependency from test case * port forward to influx DB if URL not provided by the user * archive pruner test
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
{{- if or (.Values.controller.enabled) (.Values.influxdb.enabled) }}
|
||||
{{- if .Values.controller.enabled }}
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: ClusterRole
|
||||
metadata:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{{- if or (.Values.controller.enabled) (.Values.influxdb.enabled) }}
|
||||
{{- if .Values.controller.enabled }}
|
||||
kind: ClusterRoleBinding
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
metadata:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{{- if or (.Values.controller.enabled) (.Values.influxdb.enabled) }}
|
||||
{{- if .Values.controller.enabled }}
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{{- if or (.Values.controller.enabled) (.Values.influxdb.enabled) }}
|
||||
{{- if .Values.controller.enabled }}
|
||||
{{- include "fission-role-generator" (merge (dict "namespace" .Values.defaultNamespace "component" "controller") .) }}
|
||||
|
||||
{{- if not .Values.singleDefaultNamespace }}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{{- if or (.Values.controller.enabled) (.Values.influxdb.enabled) }}
|
||||
{{- if .Values.controller.enabled }}
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{{- if or (.Values.controller.enabled) (.Values.influxdb.enabled) }}
|
||||
{{- if .Values.controller.enabled }}
|
||||
{{- if .Values.serviceMonitor.enabled }}
|
||||
apiVersion: monitoring.coreos.com/v1
|
||||
kind: ServiceMonitor
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{{- if or (.Values.controller.enabled) (.Values.influxdb.enabled) }}
|
||||
{{- if .Values.controller.enabled }}
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
|
||||
@@ -22,8 +22,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
"os"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -42,11 +41,20 @@ const (
|
||||
)
|
||||
|
||||
func NewInfluxDB(ctx context.Context, logDBOptions LogDBOptions) (InfluxDB, error) {
|
||||
server, err := util.GetApplicationUrl(ctx, logDBOptions.Client, "application=fission-api")
|
||||
if err != nil {
|
||||
return InfluxDB{}, err
|
||||
|
||||
dbType := INFLUXDB
|
||||
// retrieve db auth config from the env
|
||||
url := os.Getenv(fmt.Sprintf("%s_URL", dbType))
|
||||
if url == "" {
|
||||
// Portforward to the influxdb
|
||||
localRouterPort, err := util.SetupPortForward(ctx, logDBOptions.Client, util.GetFissionNamespace(), "svc=influxdb")
|
||||
if err != nil {
|
||||
return InfluxDB{}, err
|
||||
}
|
||||
url = "http://127.0.0.1:" + localRouterPort + "/query"
|
||||
}
|
||||
return InfluxDB{endpoint: server}, nil
|
||||
|
||||
return InfluxDB{endpoint: url}, nil
|
||||
}
|
||||
|
||||
type InfluxDB struct {
|
||||
@@ -89,7 +97,7 @@ func (influx InfluxDB) GetLogs(ctx context.Context, filter LogFilter, output *by
|
||||
|
||||
query := influxdbClient.NewQueryWithParameters(queryCmd, INFLUXDB_DATABASE, "", parameters)
|
||||
logEntries := []LogEntry{}
|
||||
response, err := influx.query(query)
|
||||
response, err := influx.query(ctx, query)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -158,18 +166,16 @@ func (influx InfluxDB) GetLogs(ctx context.Context, filter LogFilter, output *by
|
||||
return nil
|
||||
}
|
||||
|
||||
func (influx InfluxDB) query(query influxdbClient.Query) (*influxdbClient.Response, error) {
|
||||
queryURL, err := url.Parse(influx.endpoint)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// connect to controller first, then controller will redirect our query command
|
||||
// to influxdb and proxy back the db response.
|
||||
queryURL.Path = path.Clean(fmt.Sprintf("%s/proxy/%s", queryURL.Path, INFLUXDB))
|
||||
req, err := http.NewRequest(http.MethodPost, queryURL.String(), nil)
|
||||
func (influx InfluxDB) query(ctx context.Context, query influxdbClient.Query) (*influxdbClient.Response, error) {
|
||||
|
||||
username := os.Getenv(fmt.Sprintf("%s_USERNAME", INFLUXDB))
|
||||
password := os.Getenv(fmt.Sprintf("%s_PASSWORD", INFLUXDB))
|
||||
|
||||
req, err := http.NewRequest(http.MethodPost, influx.endpoint, nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "error creating request for log proxy")
|
||||
}
|
||||
req.SetBasicAuth(username, password)
|
||||
|
||||
parametersBytes, err := json.Marshal(query.Parameters)
|
||||
if err != nil {
|
||||
|
||||
@@ -117,9 +117,6 @@ profiles:
|
||||
- op: replace
|
||||
path: /deploy/helm/releases/0/setValues/routerServiceType
|
||||
value: NodePort
|
||||
- op: replace
|
||||
path: /deploy/helm/releases/0/setValues/influxdb.enabled
|
||||
value: true
|
||||
- op: replace
|
||||
path: /deploy/helm/releases/0/setValues/canaryDeployment.enabled
|
||||
value: true
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
# set -euo pipefail
|
||||
source $(dirname $0)/../utils.sh
|
||||
|
||||
TEST_ID=$(generate_test_id)
|
||||
@@ -51,13 +51,12 @@ get_archive_url_from_package() {
|
||||
url=`kubectl -n default get package $1 -ojsonpath='{.spec.deployment.url}'`
|
||||
}
|
||||
|
||||
urldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; }
|
||||
|
||||
get_archive_from_storage() {
|
||||
storage_service_url=$1
|
||||
controller_ip=$CONTROLLER_IP
|
||||
controller_proxy_url=`echo $storage_service_url | sed -e "s/storagesvc.$FISSION_NAMESPACE/$controller_ip\/proxy\/storage/"`
|
||||
log "controller_proxy_url=$controller_proxy_url"
|
||||
http_status=`curl --retry 5 -sw "%{http_code}" $controller_proxy_url -o /dev/null`
|
||||
echo "http_status: $http_status"
|
||||
# storage_service_url=$1
|
||||
archive_url=$( urldecode $1)
|
||||
fission archive list | grep $(echo "$archive_url" |cut -d= -f 2)| wc -l
|
||||
}
|
||||
|
||||
#1. declare trap to cleanup for EXIT
|
||||
@@ -94,18 +93,18 @@ main() {
|
||||
log "deleted packages : $pkg_1 $pkg_2"
|
||||
|
||||
# curl on the archive url
|
||||
get_archive_from_storage $url_1
|
||||
log "http_status for $url_1 : $http_status"
|
||||
if [ "$http_status" -ne "200" ]; then
|
||||
log "Archive $url_1 absent on storage, while expected to be present"
|
||||
archiveCount=$(get_archive_from_storage $url_1)
|
||||
log "recieved archive status for $url_1"
|
||||
if [[ $archiveCount -eq 0 ]]; then
|
||||
log "archive not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# curl on the archive url
|
||||
get_archive_from_storage $url_2
|
||||
log "http_status for $url_2 : $http_status"
|
||||
if [ "$http_status" -ne "200" ]; then
|
||||
log "Archive $url_2 absent on storage, while expected to be present"
|
||||
archiveCount=$(get_archive_from_storage $url_2)
|
||||
log "recieved archive status for $url_2 "
|
||||
if [[ $archiveCount -eq 0 ]]; then
|
||||
log "archive not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -114,20 +113,20 @@ main() {
|
||||
sleep 300
|
||||
|
||||
# curl on the archive url
|
||||
get_archive_from_storage $url_1
|
||||
log "http_status for $url_1 : $http_status"
|
||||
if [ "$http_status" -ne "404" ]; then
|
||||
log "Archive $url_1 should have been recycled, but curl returned $http_status, while expected status is 404."
|
||||
archiveCount=$(get_archive_from_storage $url_1)
|
||||
if [[ $archiveCount -ne 0 ]]; then
|
||||
log "archive found"
|
||||
exit 1
|
||||
fi
|
||||
log "archive pruned for $url_1 "
|
||||
|
||||
# curl on the archive url
|
||||
get_archive_from_storage $url_2
|
||||
log "http_status for $url_2 : $http_status"
|
||||
if [ "$http_status" -ne "404" ]; then
|
||||
log "Archive $url_2 should have been recycled, but curl returned $http_status, while expected status is 404."
|
||||
archiveCount=$(get_archive_from_storage $url_2)
|
||||
if [[ $archiveCount -ne 0 ]]; then
|
||||
log "archive found"
|
||||
exit 1
|
||||
fi
|
||||
log "archive pruned for $url_2 "
|
||||
|
||||
log "Test archive pruner PASSED"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user