Skip to content

Commit

Permalink
Merge pull request #42 from sustainable-computing-io/issue41
Browse files Browse the repository at this point in the history
Resolve issues 41 and 34
  • Loading branch information
trent-s authored Feb 21, 2024
2 parents 8b273a3 + 7feb404 commit 644806c
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 23 deletions.
12 changes: 3 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ SusQL is an operator that can be deployed in a Kubernetes/OpenShift cluster. You

### Prerequisites

Kepler is assumed to be installed in the cluster. `go`, `helm`, and `kubectl` are used to for deployment.
Kepler is assumed to be installed in the cluster. `helm` and `kubectl` are also required to deploy.

### Installation

Expand All @@ -31,16 +31,10 @@ To install SusQL go to the `deployment` directory and run the command `$ bash de
$ PROMETHEUS_SERVICE=<prometheus-service> PROMETHEUS_NAMESPACE=<prometheus-namespace> PROMETHEUS_DOMAIN=<prometheus-domain> bash deploy.sh
```
Alternatively, with a unique cluster such as a single node OpenShift local cluster, it may be necessary to set KEPLER_PROMETHEUS_URL directly such as:
Or for example, the following works for a 4.12 single node OpenShift local cluster:
```
$ KEPLER_PROMETHEUS_URL=http://prometheus-k8s-openshift-monitoring.apps-crc.testing/api:9091 bash deploy.sh
```
Alternatively, with a very unusual cluster such as a single node OpenShift local cluster, it may be necessary to set KEPLER_PROMETHEUS_URL directly such as:
```
$ KEPLER_PROMETHEUS_URL=http://prometheus-k8s-openshift-monitoring.apps-crc.testing/api:9091 bash deploy.sh
$ PROMETHEUS_PROTOCOL=https PROMETHEUS_PORT=9091 PROMETHEUS_NAMESPACE=openshift-monitoring PROMETHEUS_SERVICE=thanos-querier SUSQL_ENHANCED=true bash deploy.sh
```
* Create the namespace `openshift-kepler-operator`
Expand Down
30 changes: 23 additions & 7 deletions deployment/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ if ! command -v kubectl &> /dev/null; then
exit 1
fi

if [[ ! -z ${SUSQL_ENHANCED} ]]; then
echo "Deploying enhanced SusQL configuration."
fi

# Check if there is a current context
current_context=$(kubectl config current-context)
if [[ -z $current_context ]]; then # exit
Expand Down Expand Up @@ -72,9 +76,15 @@ fi

# Set SusQL installation variables
SUSQL_DIR=".."
SUSQL_REGISTRY="quay.io/sustainable_computing_io"
SUSQL_IMAGE_NAME="susql_operator"
SUSQL_IMAGE_TAG="latest"
if [[ -z ${SUSQL_REGISTRY} ]]; then
SUSQL_REGISTRY="quay.io/sustainable_computing_io"
fi
if [[ -z ${SUSQL_IMAGE_NAME} ]]; then
SUSQL_IMAGE_NAME="susql_operator"
fi
if [[ -z ${SUSQL_IMAGE_TAG} ]]; then
SUSQL_IMAGE_TAG="latest"
fi

# Actions to perform, separated by comma
actions=${1:-"kepler-check,prometheus-undeploy,prometheus-deploy,susql-undeploy,susql-deploy"}
Expand Down Expand Up @@ -126,7 +136,9 @@ do
fi

elif [[ ${action} = "susql-deploy" ]]; then
kubectl apply -f ../config/rbac/susql-rbac.yaml
if [[ ! -z ${SUSQL_ENHANCED} ]]; then
kubectl apply -f ../config/rbac/susql-rbac.yaml
fi

cd ${SUSQL_DIR} && make manifests && make install
cd -
Expand All @@ -136,7 +148,9 @@ do
--set susqlPrometheusMetricsUrl="http://0.0.0.0:8082" \
--set imagePullPolicy="Always" \
--set containerImage="${SUSQL_REGISTRY}/${SUSQL_IMAGE_NAME}:${SUSQL_IMAGE_TAG}"
kubectl apply -f ../config/servicemonitor/susql-smon.yaml
if [[ ! -z ${SUSQL_ENHANCED} ]]; then
kubectl apply -f ../config/servicemonitor/susql-smon.yaml
fi

elif [[ ${action} = "susql-undeploy" ]]; then
echo "Undeploying SusQL controller..."
Expand All @@ -149,8 +163,10 @@ do
fi

helm -n ${SUSQL_NAMESPACE} uninstall susql-controller
kubectl delete -f ../config/rbac/susql-rbac.yaml
kubectl delete -f ../config/servicemonitor/susql-smon.yaml
if [[ ! -z ${SUSQL_ENHANCED} ]]; then
kubectl delete -f ../config/rbac/susql-rbac.yaml
kubectl delete -f ../config/servicemonitor/susql-smon.yaml
fi

else
echo "Nothing to do"
Expand Down
30 changes: 25 additions & 5 deletions internal/controller/prometheus_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,20 @@ var (
// Functions to get data from the cluster
func (r *LabelGroupReconciler) GetMostRecentValue(susqlPrometheusQuery string) (float64, error) {
// Return the most recent value found in the table
rttls := &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}
var roundtripper http.RoundTripper = nil
if strings.HasPrefix(r.KeplerPrometheusUrl, "https://") {
rttls := &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}
roundtripper = config.NewAuthorizationCredentialsFileRoundTripper("Bearer", "/var/run/secrets/kubernetes.io/serviceaccount/token", rttls)
}
client, err := api.NewClient(api.Config{
Address: r.SusQLPrometheusDatabaseUrl,
RoundTripper: config.NewAuthorizationCredentialsFileRoundTripper("Bearer", "/var/run/secrets/kubernetes.io/serviceaccount/token", rttls),
RoundTripper: roundtripper,
})

if err != nil {
fmt.Printf("ERROR [GetMostRecentValue]: Couldn't create HTTP client: %v\n", err)
fmt.Printf("Query: %s\n", susqlPrometheusQuery)
fmt.Printf("SusQLPrometheusDatabaseUrl: %s\n", r.SusQLPrometheusDatabaseUrl)
os.Exit(1)
}

Expand All @@ -62,10 +68,14 @@ func (r *LabelGroupReconciler) GetMostRecentValue(susqlPrometheusQuery string) (

if len(warnings) > 0 {
fmt.Printf("WARNING [GetMostRecentValue]: %v\n", warnings)
fmt.Printf("Query: %s\n", susqlPrometheusQuery)
fmt.Printf("SusQLPrometheusDatabaseUrl: %s\n", r.SusQLPrometheusDatabaseUrl)
}

if err != nil {
fmt.Printf("ERROR [GetMostRecentValue]: Querying Prometheus didn't work: %v\n", err)
fmt.Printf("Query: %s\n", susqlPrometheusQuery)
fmt.Printf("SusQLPrometheusDatabaseUrl: %s\n", r.SusQLPrometheusDatabaseUrl)
return 0.0, err
}

Expand All @@ -77,14 +87,20 @@ func (r *LabelGroupReconciler) GetMostRecentValue(susqlPrometheusQuery string) (
}

func (r *LabelGroupReconciler) GetMetricValuesForPodNames(metricName string, podNames []string) (map[string]float64, error) {
rttls := &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}
var roundtripper http.RoundTripper = nil
if strings.HasPrefix(r.KeplerPrometheusUrl, "https://") {
rttls := &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}
roundtripper = config.NewAuthorizationCredentialsFileRoundTripper("Bearer", "/var/run/secrets/kubernetes.io/serviceaccount/token", rttls)
}
client, err := api.NewClient(api.Config{
Address: r.KeplerPrometheusUrl,
RoundTripper: config.NewAuthorizationCredentialsFileRoundTripper("Bearer", "/var/run/secrets/kubernetes.io/serviceaccount/token", rttls),
RoundTripper: roundtripper,
})

if err != nil {
fmt.Printf("ERROR [GetMetricValuesForPodNames]: Couldn't created an HTTP client: %v\n", err)
fmt.Printf("ERROR [GetMetricValuesForPodNames]: Couldn't create an HTTP client: %v\n", err)
fmt.Printf("metricName: %s\n", metricName)
fmt.Printf("KeplerPrometheusUrl: %s\n", r.KeplerPrometheusUrl)
os.Exit(1)
}

Expand All @@ -97,11 +113,15 @@ func (r *LabelGroupReconciler) GetMetricValuesForPodNames(metricName string, pod

if err != nil {
fmt.Printf("ERROR [GetMetricValuesForPodNames]: Querying Prometheus didn't work: %v\n", err)
fmt.Printf("metricName: %s\n", metricName)
fmt.Printf("KeplerPrometheusUrl: %s\n", r.KeplerPrometheusUrl)
return nil, err
}

if len(warnings) > 0 {
fmt.Printf("WARNING [GetMetricValuesForPodNames]: %v\n", warnings)
fmt.Printf("metricName: %s\n", metricName)
fmt.Printf("KeplerPrometheusUrl: %s\n", r.KeplerPrometheusUrl)
}

metricValues := make(map[string]float64, len(results.(model.Vector)))
Expand Down
6 changes: 4 additions & 2 deletions test/susqltopmon
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/bash

echo gathering data... Then updating every 5 seconds
INTERVAL=2

echo gathering data... Then updating every ${INTERVAL} seconds

d=$(dirname ${0})
watch -n 5 --no-title "${d}/susqltop ${1} ${2}"
watch -n ${INTERVAL} --no-title "${d}/susqltop ${1} ${2}"

0 comments on commit 644806c

Please sign in to comment.