Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add o11y supports #118

Merged
merged 2 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 43 additions & 14 deletions all-in-one/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@ ARG BASE_VERSION=2022-10-27T19-02-22
ARG CORE_VERSION=2.0.4
ARG CONSOLE_VERSION=1.4.6
ARG APISERVER_VERSION=0.0.16
ARG PROMETHEUS_VERSION=v2.40.7
ARG PROMTAIL_VERSION=2.9.4
ARG LOKI_VERSION=2.9.4
ARG GRAFANA_VERSION=9.3.6

FROM ${HUB}/api-server:${APISERVER_VERSION} as apiserver
FROM ${HUB}/higress:${CORE_VERSION} as controller
FROM ${HUB}/pilot:${CORE_VERSION} as pilot
FROM ${HUB}/gateway:${CORE_VERSION} as gateway
FROM ${HUB}/console:${CONSOLE_VERSION} as console
FROM eclipse-temurin:21-jre as jdk
FROM ${HUB}/api-server:${APISERVER_VERSION} AS apiserver
FROM ${HUB}/higress:${CORE_VERSION} AS controller
FROM ${HUB}/pilot:${CORE_VERSION} AS pilot
FROM ${HUB}/gateway:${CORE_VERSION} AS gateway
FROM ${HUB}/console:${CONSOLE_VERSION} AS console
FROM ${HUB}/prometheus:${PROMETHEUS_VERSION} AS prometheus
FROM ${HUB}/promtail:${PROMTAIL_VERSION} AS promtail
FROM ${HUB}/loki:${LOKI_VERSION} AS loki
FROM ${HUB}/grafana:${GRAFANA_VERSION} AS grafana
FROM ${HUB}/eclipse-temurin:21-jre AS jdk

FROM ${HUB}/base:${BASE_VERSION}

Expand All @@ -21,12 +29,17 @@ COPY --from=controller /usr/local/bin/higress /usr/local/bin/higress

# Install pilot
COPY --from=pilot /usr/local/bin/pilot-discovery /usr/local/bin/pilot-discovery
COPY --from=pilot /var/lib/istio/envoy/*.json /var/lib/istio/envoy/
COPY --from=pilot /usr/local/bin/higress-pilot-start.sh /usr/local/bin/higress-pilot-start.sh

# Install gateway
COPY --from=gateway /var/lib/istio/envoy/*.json /var/lib/istio/envoy/
COPY --from=gateway /usr/local/bin/pilot-agent /usr/local/bin/pilot-agent
COPY --from=gateway /usr/local/bin/envoy /usr/local/bin/envoy
COPY --from=gateway /usr/local/bin/higress-proxy-*.sh /usr/local/bin/
RUN chmod a+x /usr/local/bin/higress-proxy-container-init.sh; \
sed -i 's/1337/0/g' /usr/local/bin/higress-proxy-container-init.sh; \
/usr/local/bin/higress-proxy-container-init.sh
COPY --from=gateway /usr/local/bin/supercronic* /usr/local/bin/

# Install console
COPY --from=console /app /app
Expand All @@ -36,16 +49,28 @@ ENV JAVA_HOME=/opt/java/openjdk
COPY --from=jdk $JAVA_HOME $JAVA_HOME
ENV PATH="${JAVA_HOME}/bin:${PATH}"

# Install supervisord and initialize related folders
RUN apt-get update && \
apt-get install --no-install-recommends -y \
supervisor \
# Install Prometheus
COPY --from=prometheus /bin/prometheus /usr/local/bin/prometheus

# Install Promtail
COPY --from=promtail /usr/bin/promtail /usr/local/bin/promtail

# Install Loki
COPY --from=loki /usr/bin/loki /usr/local/bin/loki

# Install Grafana
COPY --from=grafana /usr/share/grafana /usr/share/grafana
COPY --from=grafana /run.sh /usr/local/bin/grafana.sh

# Install supervisord, logrotate, cron and initialize related folders
RUN apt-get update --allow-unauthenticated && \
apt-get install --no-install-recommends -y --allow-unauthenticated \
supervisor logrotate cron \
&& apt-get upgrade -y --allow-unauthenticated \
&& apt-get clean \
&& rm -rf /var/log/*log /var/lib/apt/lists/* /var/log/apt/* /var/lib/dpkg/*-old /var/cache/debconf/*-old \
&& mkdir -p /var/log/higress \
&& chown 1337:1337 -R /var/log/higress \
&& mkdir /data \
&& chown 1337:1337 -R /data
&& mkdir /data
COPY ./supervisord/supervisord.conf /etc/supervisor/conf.d/supervisord.conf

# Initialize configurations
Expand All @@ -54,6 +79,10 @@ COPY ./gateway/podinfo /etc/istio/pod
COPY ./scripts /usr/local/bin
COPY ./apiserver/config /app/kubeconfig
COPY ./config /opt/data/defaultConfig
COPY ./prometheus /etc/prometheus
COPY ./promtail /etc/promtail
COPY ./loki /etc/loki
COPY ./grafana /etc/grafana

EXPOSE 8080 8443 8001

Expand Down
21 changes: 21 additions & 0 deletions all-in-one/config/configmaps/higress-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: higress-config
namespace: higress-system
creationTimestamp: "2000-01-01T00:00:00Z"
resourceVersion: "1"
data:
higress: |-
downstream:
connectionBufferLimits: 32768
http2:
initialConnectionWindowSize: 1048576
initialStreamWindowSize: 65535
maxConcurrentStreams: 100
idleTimeout: 180
maxRequestHeadersKb: 60
routeTimeout: 0
upstream:
connectionBufferLimits: 10485760
idleTimeout: 10
3 changes: 2 additions & 1 deletion all-in-one/get-ai-gateway.sh
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ runConfigWizard() {
"Zhipu AI|ZHIPUAI"
"Ollama|OLLAMA|configureOllamaProvider"
"Claude|CLAUDE|configureClaudeProvider"
"Baidu AI Cloud|BAIDU"
# "Baidu AI Cloud|BAIDU"
# "Tencent Hunyuan|HUNYUAN"
"Stepfun|STEPFUN"
"Minimax|MINIMAX|configureMinimaxProvider"
Expand Down Expand Up @@ -324,6 +324,7 @@ ${env}=${!env}"
done
cat <<EOF >$DATA_FOLDER/$CONFIG_FILENAME
MODE=full
o11y=on
CONFIG_TEMPLATE=ai-gateway
GATEWAY_HTTP_PORT=${GATEWAY_HTTP_PORT}
GATEWAY_HTTPS_PORT=${GATEWAY_HTTPS_PORT}
Expand Down
21 changes: 21 additions & 0 deletions all-in-one/grafana/grafana.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[server]
protocol=http
domain=localhost
root_url="%(protocol)s://%(domain)s/grafana"
serve_from_sub_path=true

[auth]
disable_login_form=true
disable_signout_menu=true

[auth.anonymous]
enabled=true
org_name=Main Org.
org_role=Viewer

[users]
default_theme=light
viewers_can_edit=true

[security]
allow_embedding=true
49 changes: 49 additions & 0 deletions all-in-one/loki/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
auth_enabled: false
common:
compactor_address: 'loki'
path_prefix: /var/loki
replication_factor: 1
storage:
filesystem:
chunks_directory: /var/loki/chunks
rules_directory: /var/loki/rules
frontend:
scheduler_address: ""
frontend_worker:
scheduler_address: ""
index_gateway:
mode: simple
limits_config:
max_cache_freshness_per_query: 10m
reject_old_samples: true
reject_old_samples_max_age: 168h
split_queries_by_interval: 15m
memberlist:
join_members:
- localhost
query_range:
align_queries_with_step: true
ruler:
storage:
type: local
runtime_config:
file: /etc/loki/runtime-config.yaml
schema_config:
configs:
- from: "2022-01-11"
index:
period: 24h
prefix: loki_index_
object_store: filesystem
schema: v12
store: boltdb-shipper
server:
http_listen_port: 3100
grpc_listen_port: 9095
storage_config:
hedging:
at: 250ms
max_per_second: 20
up_to: 3
tracing:
enabled: false
1 change: 1 addition & 0 deletions all-in-one/loki/runtime-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
3 changes: 3 additions & 0 deletions all-in-one/meshConfig/mesh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ dnsRefreshRate: 200s
enableAutoMtls: false
enablePrometheusMerge: true
ingressControllerMode: "OFF"
mseIngressGlobalConfig:
enableH3: false
enableProxyProtocol: false
protocolDetectionTimeout: 100ms
rootNamespace: higress-system
trustDomain: cluster.local
17 changes: 17 additions & 0 deletions all-in-one/prometheus/prometheus.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_configs:
- job_name: 'prometheus'
metrics_path: /prometheus/metrics
static_configs:
- targets: ['localhost:9090']
- job_name: 'gateway'
metrics_path: /stats/prometheus
static_configs:
- targets: ['localhost:15020']
labels:
container: 'higress-gateway'
namespace: 'higress-system'
higress: 'higress-system-higress-gateway'
pod: 'higress'
54 changes: 54 additions & 0 deletions all-in-one/promtail/promtail.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
server:
log_level: info
http_listen_port: 3101
grpc_listen_port: 9096

clients:
- url: http://localhost:3100/loki/api/v1/push

positions:
filename: /var/promtail/promtail-positions.yaml
target_config:
sync_period: 10s
scrape_configs:
- job_name: access-logs
static_configs:
- targets:
- localhost
labels:
__path__: /var/log/proxy/access.log
pipeline_stages:
- json:
expressions:
authority:
method:
path:
protocol:
request_id:
response_code:
response_flags:
route_name:
trace_id:
upstream_cluster:
upstream_host:
upstream_transport_failure_reason:
user_agent:
x_forwarded_for:
- labels:
authority:
method:
path:
protocol:
request_id:
response_code:
response_flags:
route_name:
trace_id:
upstream_cluster:
upstream_host:
upstream_transport_failure_reason:
user_agent:
x_forwarded_for:
- timestamp:
source: timestamp
format: RFC3339Nano
13 changes: 11 additions & 2 deletions all-in-one/scripts/base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ function readinessCheck() {

function createDir() {
sudo mkdir -p "$1"
sudo chown 1337:1337 "$1"
}

case $MODE in
Expand All @@ -39,9 +38,19 @@ case $MODE in
MODE=full
;;
esac

echo "Mode=$MODE"

case $O11Y in
true|TRUE|on|ON|yes|YES)
O11Y=on
;;
*)
# Default to full mode
O11Y=off
;;
esac
echo "O11Y=$O11Y"

CONSOLE_USED_MARKER='/data/.console-used'
CONSOLE_USED='false'
if [ -f "$CONSOLE_USED_MARKER" ]; then
Expand Down
2 changes: 1 addition & 1 deletion all-in-one/scripts/config-template/ai-gateway.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function initializeLlmProviderConfigs() {
initializeLlmProviderConfig yi yi YI api.lingyiwanwu.com
initializeLlmProviderConfig deepseek deepseek DEEPSEEK api.deepseek.com
initializeLlmProviderConfig zhipuai zhipuai ZHIPUAI open.bigmodel.cn
initializeLlmProviderConfig baidu baidu BAIDU aip.baidubce.com
# initializeLlmProviderConfig baidu baidu BAIDU aip.baidubce.com
# initializeLlmProviderConfig hunyuan hunyuan HUNYUAN hunyuan.tencentcloudapi.com 443 "https" "" "${EXTRA_CONFIGS[@]}"
initializeLlmProviderConfig stepfun stepfun STEPFUN api.stepfun.com
# initializeLlmProviderConfig cloudflare cloudflare CLOUDFLARE api.cloudflare.com 443 "https" "" "${EXTRA_CONFIGS[@]}"
Expand Down
9 changes: 8 additions & 1 deletion all-in-one/scripts/start-console.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,12 @@ touch "$CONSOLE_USED_MARKER"

set -e

HIGRESS_CONSOLE_KUBE_CONFIG="/app/kubeconfig" SERVER_PORT="$CONSOLE_PORT" \
if [ "$O11Y" == "on" ]; then
export HIGRESS_CONSOLE_DASHBOARD_BASE_URL="http://localhost:3000/grafana"
export HIGRESS_CONSOLE_DASHBOARD_DATASOURCE_PROM_URL="http://localhost:9090/prometheus"
export HIGRESS_CONSOLE_DASHBOARD_DATASOURCE_LOKI_URL="http://localhost:3100"
fi

HIGRESS_CONSOLE_KUBE_CONFIG="/app/kubeconfig" \
SERVER_PORT="$CONSOLE_PORT" \
bash /app/start.sh
10 changes: 9 additions & 1 deletion all-in-one/scripts/start-gateway.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,16 @@ set -e

createDir /etc/istio/proxy
createDir /var/lib/istio/data
createDir /var/log/proxy
touch /var/log/proxy/access.log

/usr/local/bin/pilot-agent proxy router \
if [ "$O11Y" == "on" ]; then
sed -i -E 's/^accessLogFile: .+$/accessLogFile: \/var\/log\/proxy\/access.log/' /etc/istio/config/mesh
else
sed -i -E 's/^accessLogFile: .+$/accessLogFile: \/dev\/stdout/' /etc/istio/config/mesh
fi

/usr/local/bin/higress-proxy-start.sh proxy router \
--domain=higress-system.svc.cluster.local \
--proxyLogLevel=${GATEWAY_LOG_LEVEL:-warning} \
--proxyComponentLogLevel=${GATEWAY_COMPONENT_LOG_LEVEL:-misc:error} \
Expand Down
26 changes: 26 additions & 0 deletions all-in-one/scripts/start-grafana.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

cd "$(dirname -- "$0")"
ROOT=$(pwd)
cd - >/dev/null
source $ROOT/base.sh

if [ "$O11Y" != "on" ]; then
echo "Grafana won't run when o11y is not turned on."
sleep 2
exit 0
fi

set -e

createDir /var/lib/grafana
createDir /var/log/grafana

GF_PATHS_CONFIG="/etc/grafana/grafana.ini" \
GF_PATHS_DATA="/var/lib/grafana" \
GF_PATHS_HOME="/usr/share/grafana" \
GF_PATHS_LOGS="/var/log/grafana" \
GF_PATHS_PLUGINS="/var/lib/grafana/plugins" \
GF_PATHS_PROVISIONING="/etc/grafana/provisioning" \
PATH="/usr/share/grafana/bin:$PATH" \
bash /usr/local/bin/grafana.sh
Loading
Loading