Skip to content

Commit

Permalink
[CHANGE] Use OpenSource datasource plugin for connecting to back-end …
Browse files Browse the repository at this point in the history
…log message store (#679)
  • Loading branch information
gsmith-sas authored Sep 30, 2024
1 parent de0f3d0 commit f2dd0f5
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 24 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/build-artifact/ARTIFACT_INVENTORY.template
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,11 @@ This table identifies the Helm charts used by SAS Viya Monitoring for Kubernetes
| Metrics | Kube Prometheus Stack| __KUBE_PROM_STACK_CHART_REPO__ | __KUBE_PROM_STACK_CHART_NAME__ | __KUBE_PROM_STACK_CHART_VERSION__ | __KUBE_PROM_STACK_CHART_ARCHIVE__ |
| Metrics | Prometheus Pushgateway| __PUSHGATEWAY_CHART_REPO__ | __PUSHGATEWAY_CHART_NAME__ | __PUSHGATEWAY_CHART_VERSION__ | __PUSHGATEWAY_CHART_ARCHIVE__ |
| Metrics | Tempo | __TEMPO_CHART_REPO__ | __TEMPO_CHART_NAME__ | __TEMPO_CHART_VERSION__ | __TEMPO_CHART_ARCHIVE__ |

## Table 4. Miscellaneous Component Version Information
This table provides version information for some miscellaneous components deployed by SAS Viya Monitoring for Kubernetes.

| Component | Version | Project Repository | Notes |
|--|--|--|--|
| OpenSearch Datasource Plugin (Grafana) | __GRAFANA_DATASOURCE_PLUGIN_VERSION__ | https://github.com/grafana/opensearch-datasource/releases |Allows Grafana to surface log messages stored in OpenSearch |

12 changes: 12 additions & 0 deletions .github/workflows/build-artifact/generate_inventory.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ function buildHelmArchiveFilename {

}

##
## Helm Chart (Table #3)
##
buildHelmArchiveFilename "ESEXPORTER_HELM"
buildHelmArchiveFilename "FLUENTBIT_HELM"
buildHelmArchiveFilename "OPENSEARCH_HELM"
Expand All @@ -45,6 +48,10 @@ buildHelmArchiveFilename "KUBE_PROM_STACK"
buildHelmArchiveFilename "PUSHGATEWAY"
buildHelmArchiveFilename "TEMPO"


##
## Container Images (Table #1)
##
parseFullImage "$ALERTMANAGER_FULL_IMAGE"
v4m_replace "__ALERTMANAGER_FULL_IMAGE__" "$FULL_IMAGE_ESCAPED" "$file"

Expand Down Expand Up @@ -96,4 +103,9 @@ v4m_replace "__TEMPO_FULL_IMAGE__" "$FULL_IMAGE_ESCAPED" "$file"
parseFullImage "$PUSHGATEWAY_FULL_IMAGE"
v4m_replace "__PUSHGATEWAY_FULL_IMAGE__" "$FULL_IMAGE_ESCAPED" "$file"

##
## Misc components (Table #4)
##
v4m_replace "__GRAFANA_DATASOURCE_PLUGIN_VERSION__" "$GRAFANA_DATASOURCE_PLUGIN_VERSION" "$file"

log_notice "Be sure to review the generated file [$file] prior to adding/committing it to the repo"
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased
* **Metrics**
* [CHANGE] The `create_logging_datasource.sh` script now uses the OpenSearch datasource plugin
rather the Elasticsearch datasource plugin when creating the **ViyaLogs** datasource in Grafana.
The plugin is downloaded and installed if it is not already in place.
* [UPGRADE] Kube-Prometheus Stack Helm chart has been upgraded from 61.1.1 to 62.7.0.
* [UPGRADE] Grafana Helm Chart (for OpenShift deployments) has been upgraded from 8.2.1 to 8.5.1.
* [UPGRADE] Prometheus Pushgateway Helm chart has been upgraded from 2.13.0 to 2.14.0.
Expand All @@ -14,6 +17,7 @@
* [UPGRADE] Prometheus Operator has been upgraded from 0.75.0 to 0.76.1.
* [UPGRADE] Prometheus Pushgateway has been upgraded from 1.8.0 to 1.9.0.


## Version 1.2.29 (16SEP2024)
* **Overall**
* [DOCUMENTATION] Reorganization of content to improve readability and flow.
Expand Down
2 changes: 1 addition & 1 deletion component_versions.env
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ OPENSHIFT_OAUTHPROXY_FULL_IMAGE="registry.redhat.io/openshift4/ose-oauth-proxy:l
#Grafana (everywhere)
GRAFANA_FULL_IMAGE="docker.io/grafana/grafana:11.2.0"
GRAFANA_SIDECAR_FULL_IMAGE="quay.io/kiwigrid/k8s-sidecar:1.27.4"
GRAFANA_DATASOURCE_PLUGIN_VERSION="2.17.4"
GRAFANA_DATASOURCE_PLUGIN_VERSION="2.18.0"

#Kube-Prometheus Stack
KUBE_PROM_STACK_CHART_REPO=prometheus-community
Expand Down
69 changes: 50 additions & 19 deletions monitoring/bin/create_logging_datasource.sh
Original file line number Diff line number Diff line change
Expand Up @@ -151,24 +151,24 @@ else
./logging/bin/user.sh CREATE -ns $tenantNS -t $tenant -u $grfds_user -p "$grfds_passwd" -g
fi

# Create temporary directory for string replacement in the grafana-datasource-es.yaml file
# Create temporary directory for string replacement in the grafana-datasource-opensearch.yaml file
monDir=$TMP_DIR/$MON_NS
mkdir -p $monDir
cp monitoring/grafana-datasource-es.yaml $monDir/grafana-datasource-es.yaml
cp monitoring/grafana-datasource-opensearch.yaml $monDir/grafana-datasource-opensearch.yaml

#Determine OpenSearch version programatically
parseFullImage "$OS_FULL_IMAGE"
opensearch_version="${VERSION:-2.12.0}"
log_debug "OpenSearch version [$opensearch_version] will be specified in datasource definition."

# Replace placeholders
log_debug "Replacing variables in $monDir/grafana-datasource-es.yaml file"
if echo "$OSTYPE" | grep 'darwin' > /dev/null 2>&1; then
sed -i '' "s/__namespace__/$LOG_NS/g" $monDir/grafana-datasource-es.yaml
sed -i '' "s/__ES_SERVICENAME__/$ES_SERVICENAME/g" $monDir/grafana-datasource-es.yaml
sed -i '' "s/__userID__/$grfds_user/g" $monDir/grafana-datasource-es.yaml
sed -i '' "s/__passwd__/$grfds_passwd/g" $monDir/grafana-datasource-es.yaml
else
sed -i "s/__namespace__/$LOG_NS/g" $monDir/grafana-datasource-es.yaml
sed -i "s/__ES_SERVICENAME__/$ES_SERVICENAME/g" $monDir/grafana-datasource-es.yaml
sed -i "s/__userID__/$grfds_user/g" $monDir/grafana-datasource-es.yaml
sed -i "s/__passwd__/$grfds_passwd/g" $monDir/grafana-datasource-es.yaml
fi
log_debug "Replacing variables in $monDir/grafana-datasource-opensearch.yaml file"
v4m_replace "__namespace__" "$LOG_NS" "$monDir/grafana-datasource-opensearch.yaml"
v4m_replace "__ES_SERVICENAME__" "$ES_SERVICENAME" "$monDir/grafana-datasource-opensearch.yaml"
v4m_replace "__userID__" "$grfds_user" "$monDir/grafana-datasource-opensearch.yaml"
v4m_replace "__passwd__" "$grfds_passwd" "$monDir/grafana-datasource-opensearch.yaml"
v4m_replace "__opensearch_version__" "$opensearch_version" "$monDir/grafana-datasource-opensearch.yaml"


# Removes old Elasticsearch data source if one exists
if [ "$cluster" == "true" ]; then
Expand All @@ -183,14 +183,45 @@ else
fi
fi

# Install OpenSearch datasource plug-in to Grafana
grafanaPod=$(kubectl -n $MON_NS get pods -l app.kubernetes.io/name=grafana -o jsonpath='{.items[0].metadata.name}')
log_debug "Grafana Pod [$grafanaPod]"

pluginInstalled=$(kubectl exec -n $MON_NS $grafanaPod -- bash -c "grafana cli plugins ls |grep -c opensearch-datasource|| true")
log_debug "Grafana OpenSearch Datasource Plugin installed? [$pluginInstalled]"

if [ "$pluginInstalled" == "0" ]; then

log_info "Installing OpenSearch Datasource plugin"
pluginVersion="${GRAFANA_DATASOURCE_PLUGIN_VERSION:-2.17.4}"
pluginFile="grafana-opensearch-datasource-$pluginVersion.linux_amd64.zip"

if [ -n "$AIRGAP_HELM_REPO" ]; then
log_debug "Air-gapped deployment detected; loading OpenSearch Datasource plugin from USER_DIR/monitoring directory"

userPluginFile="$USER_DIR/monitoring/$pluginFile"
if [ -f "$userPluginFile" ]; then
kubectl cp $userPluginFile $MON_NS/$grafanaPod:/var/lib/grafana/plugins
kubectl exec -n $MON_NS $grafanaPod -- unzip -o /var/lib/grafana/plugins/$pluginFile -d /var/lib/grafana/plugins/
else
log_error "The OpenSearch datasource plugin to Grafana zip file was NOT found in the expected location [$userPluginFile]"
exit 1
fi
else
log_debug "Using Grafana CLI to install plugin (version [$pluginVersion])"
kubectl exec -n $MON_NS $grafanaPod -- grafana cli plugins install grafana-opensearch-datasource $pluginVersion
log_info "You may ignore any previous messages regarding restarting the Grafana pod; it will be restarted automatically."
fi
else
log_debug "The OpenSearch datasource plugin is already installed; skipping installation."
fi

# Adds the logging data source to Grafana
log_info "Provisioning logging data source in Grafana"
if [ "$cluster" == "true" ]; then
kubectl create secret generic -n $MON_NS grafana-datasource-es --from-file $monDir/grafana-datasource-es.yaml
kubectl label secret -n $MON_NS grafana-datasource-es grafana_datasource=1 sas.com/monitoring-base=kube-viya-monitoring
else
kubectl create secret generic -n $tenantNS v4m-grafana-datasource-es-$tenant --from-file $monDir/grafana-datasource-es.yaml
kubectl label secret -n $tenantNS v4m-grafana-datasource-es-$tenant grafana_datasource-$tenant=true sas.com/monitoring-base=kube-viya-monitoring
kubectl delete secret generic -n $MON_NS grafana-datasource-opensearch --ignore-not-found
kubectl create secret generic -n $MON_NS grafana-datasource-opensearch --from-file $monDir/grafana-datasource-opensearch.yaml
kubectl label secret -n $MON_NS grafana-datasource-opensearch grafana_datasource=1 sas.com/monitoring-base=kube-viya-monitoring
fi

# Deploy the log-enabled Viya dashboards
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ apiVersion: 1

datasources:
- name: ViyaLogs
type: elasticsearch
type: grafana-opensearch-datasource
access: proxy
database: viya_logs-*
url: https://__ES_SERVICENAME__.__namespace__:9200
basicAuth: true
basicAuthUser: __userID__
jsonData:
database: viya_logs-*
tlsSkipVerify: true
timeField: "@timestamp"
esVersion: '7.10.0'
version: __opensearch_version__
logMessageField: message
logLevelField: level.keyword
secureJsonData:
# Change this value
basicAuthPassword: __passwd__
editable: true
editable: true

0 comments on commit f2dd0f5

Please sign in to comment.