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

option to use nginx cache #3590

Draft
wants to merge 8 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,35 @@ data:
text/x-component
text/x-cross-domain-policy;

{{- if (.Values.kubecostFrontend.cache).enabled -}}
# this is the name of the cache
proxy_cache kubecost_cache;
# this is the path where the cache will be stored
proxy_cache_path {{ (.Values.kubecostFrontend.cache).proxyCachePath }};
# this is the key that will be used to identify the cache
proxy_cache_key "$request_method|$host|$request_uri|$is_args$args";
# this is the time to live for the cache
proxy_cache_valid 200 {{ (.Values.kubecostFrontend.cache).cacheTTL }};
proxy_cache_valid any 10m;
# this allows Nginx to ignore the headers that are set by the upstream server
proxy_ignore_headers Expires Cache-Control X-Accel-Expires Set-Cookie;
# only cache GET and POST requests
proxy_cache_methods {{ (.Values.kubecostFrontend.cache).proxyCacheMethods }};
# this allows Nginx to try the next upstream server in case of an error on the current one
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
add_header X-Cache-Status $upstream_cache_status;
add_header X-Upstream-Server $upstream_addr;
# this allows Nginx to serve stale cached content in various error scenarios or when the upstream server is having issues
proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
proxy_cache_revalidate on;
proxy_cache_background_update on;

log_format cache_status '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" $bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" "$upstream_cache_status"';
access_log /var/log/nginx/access.log cache_status;
{{- end }}

upstream api {
{{- if .Values.kubecostFrontend.useDefaultFqdn }}
server {{ $serviceName }}.{{ .Release.Namespace }}.svc.cluster.local:9001;
Expand Down Expand Up @@ -128,6 +157,10 @@ data:
server {{ .Release.Name }}-aggregator.{{ .Release.Namespace }}:9004;
{{- end }}
{{- end }}
{{- if (.Values.kubecostFrontend.aggregatorFailoverSvc) -}}
# this allows Nginx to try the next upstream server in case of an error on the primary
server {{ .Values.kubecostFrontend.aggregatorFailoverSvc }} backup;
{{- end }}
}
upstream cloudCost {
{{- if .Values.kubecostFrontend.useDefaultFqdn }}
Expand Down
13 changes: 13 additions & 0 deletions cost-analyzer/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,19 @@ kubecostFrontend:
# clusterController:
# fqdn: cluster-controller.kubecost.svc.cluster.local:9731

# Cache configuration
# caching is experimental and only supported with Kubecost Enterprise
cache:
enabled: false
cacheSize: 2000m
cacheTTL: 1h
proxyCachePath: "/tmp/cache levels=1:2:2 keys_zone=kubecost_cache:2g max_size=10g inactive=6h use_temp_path=off"
proxyCacheMethods: "GET POST HEAD"

# aggregatorFailoverSvc is experimental and only supported with Kubecost Enterprise
# location of the aggregator service to use as a failover
# aggregatorFailoverSvc: kubecost2-aggregator.kubecost2.svc.cluster.local:9004
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be uncommented and just add a section for "aggregatorFailover.enabled"?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably have both an enabled field as well as a service address field.


# Kubecost Metrics deploys a separate pod which will emit kubernetes specific metrics required
# by the cost-model. This pod is designed to remain active and decoupled from the cost-model itself.
# However, disabling this service/pod deployment will flag the cost-model to emit the metrics instead.
Expand Down