forked from grafana/loki
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add storage size calculator (grafana#95)
* add storage size calculator * updated go.sum * updated size calculator manifest * updated storage size calculator * updated storage size calculator
- Loading branch information
Sashank Agarwal
authored
Nov 15, 2021
1 parent
c3e282e
commit 8d7b66f
Showing
20 changed files
with
630 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Build the calculator binary | ||
FROM golang:1.16 as builder | ||
|
||
WORKDIR /workspace | ||
# Copy the Go Modules manifests | ||
COPY go.mod go.mod | ||
COPY go.sum go.sum | ||
# cache deps before building and copying source so that we don't need to re-download as much | ||
# and so that source changes don't invalidate our downloaded layer | ||
RUN go mod download | ||
|
||
# Copy the go source | ||
COPY cmd/size-calculator/main.go main.go | ||
COPY internal/ internal/ | ||
|
||
# Build | ||
RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -a -o size-calculator main.go | ||
|
||
# Use distroless as minimal base image to package the size-calculator binary | ||
# Refer to https://github.com/GoogleContainerTools/distroless for more details | ||
FROM gcr.io/distroless/static:nonroot | ||
WORKDIR / | ||
COPY --from=builder /workspace/size-calculator . | ||
USER 65532:65532 | ||
|
||
ENTRYPOINT ["/size-calculator"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"math" | ||
"os" | ||
"time" | ||
|
||
"github.com/ViaQ/loki-operator/internal/sizes" | ||
"github.com/prometheus/common/model" | ||
|
||
"github.com/ViaQ/logerr/log" | ||
) | ||
|
||
const ( | ||
// defaultDuration is the time for which the metric needs to be predicted for. | ||
// It is passed as second parameter to predict_linear. | ||
defaultDuration string = "24h" | ||
// range1xSmall defines the range (in GB) | ||
// of t-shirt size 1x.small i.e., 0 <= 1x.small <= 500 | ||
range1xSmall int = 500 | ||
// sizeOneXSmall defines the size of a single Loki deployment | ||
// with small resources/limits requirements. This size is dedicated for setup **without** the | ||
// requirement for single replication factor and auto-compaction. | ||
sizeOneXSmall string = "1x.small" | ||
// sizeOneXMedium defines the size of a single Loki deployment | ||
// with small resources/limits requirements. This size is dedicated for setup **with** the | ||
// requirement for single replication factor and auto-compaction. | ||
sizeOneXMedium string = "1x.medium" | ||
) | ||
|
||
func init() { | ||
log.Init("size-calculator") | ||
} | ||
|
||
func main() { | ||
log.Info("starting storage size calculator...") | ||
|
||
for { | ||
duration, parseErr := model.ParseDuration(defaultDuration) | ||
if parseErr != nil { | ||
log.Error(parseErr, "failed to parse duration") | ||
os.Exit(1) | ||
} | ||
|
||
logsCollected, err := sizes.PredictFor(duration) | ||
if err != nil { | ||
log.Error(err, "Failed to collect metrics data") | ||
os.Exit(1) | ||
} | ||
|
||
logsCollectedInGB := int(math.Ceil(logsCollected / math.Pow(1024, 3))) | ||
log.Info(fmt.Sprintf("Amount of logs expected in 24 hours is %f Bytes or %dGB", logsCollected, logsCollectedInGB)) | ||
|
||
if logsCollectedInGB <= range1xSmall { | ||
log.Info(fmt.Sprintf("Recommended t-shirt size for %dGB is %s", logsCollectedInGB, sizeOneXSmall)) | ||
} else { | ||
log.Info(fmt.Sprintf("Recommended t-shirt size for %dGB is %s", logsCollectedInGB, sizeOneXMedium)) | ||
} | ||
|
||
time.Sleep(1 * time.Minute) | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
config/overlays/openshift/size-calculator/cluster_monitoring_config.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: cluster-monitoring-config | ||
namespace: openshift-monitoring | ||
data: | ||
config.yaml: | | ||
enableUserWorkload: true |
23 changes: 23 additions & 0 deletions
23
config/overlays/openshift/size-calculator/kustomization.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
resources: | ||
- logfile_metric_daemonset.yaml | ||
- logfile_metric_role.yaml | ||
- logfile_metric_role_binding.yaml | ||
- logfile_metric_scc.yaml | ||
- logfile_metric_service.yaml | ||
- logfile_metric_service_account.yaml | ||
- logfile_metric_service_monitor.yaml | ||
- storage_size_calculator_config.yaml | ||
- storage_size_calculator.yaml | ||
|
||
# Adds namespace to all resources. | ||
namespace: openshift-logging | ||
|
||
# Labels to add to all resources and selectors. | ||
# commonLabels: | ||
# someName: someValue | ||
commonLabels: | ||
app.kubernetes.io/name: storage-size-calculator | ||
app.kubernetes.io/instance: storage-size-calculator-v0.0.1 | ||
app.kubernetes.io/version: "0.0.1" | ||
app.kubernetes.io/part-of: loki-operator | ||
app.kubernetes.io/managed-by: kubectl-apply |
55 changes: 55 additions & 0 deletions
55
config/overlays/openshift/size-calculator/logfile_metric_daemonset.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
apiVersion: apps/v1 | ||
kind: DaemonSet | ||
metadata: | ||
name: log-file-metric-exporter | ||
labels: | ||
name: log-file-metric-exporter | ||
spec: | ||
selector: | ||
matchLabels: | ||
name: log-file-metric-exporter | ||
template: | ||
metadata: | ||
labels: | ||
name: log-file-metric-exporter | ||
spec: | ||
nodeSelector: | ||
kubernetes.io/os: linux | ||
containers: | ||
- name: log-file-metric-exporter | ||
image: quay.io/openshift-logging/log-file-metric-exporter:latest | ||
imagePullPolicy: IfNotPresent | ||
command: | ||
- /usr/local/bin/log-file-metric-exporter | ||
- -verbosity=2 | ||
- -dir=/var/log/containers | ||
- -http=:2112 | ||
- -keyFile=/var/run/secrets/serving-cert/tls.key | ||
- -crtFile=/var/run/secrets/serving-cert/tls.crt | ||
ports: | ||
- containerPort: 2112 | ||
name: logfile-metrics | ||
protocol: TCP | ||
volumeMounts: | ||
- mountPath: /var/run/secrets/serving-cert | ||
name: log-file-metric-exporter-metrics | ||
- mountPath: /var/log | ||
name: logfile-varlog | ||
securityContext: | ||
seLinuxOptions: | ||
type: spc_t | ||
readOnlyRootFilesystem: true | ||
allowPrivilegeEscalation: false | ||
serviceAccount: log-file-metric-exporter | ||
volumes: | ||
- name: log-file-metric-exporter-metrics | ||
secret: | ||
defaultMode: 420 | ||
optional: true | ||
secretName: log-file-metric-exporter-metrics | ||
- name: logfile-varlog | ||
hostPath: | ||
path: /var/log | ||
- name: storage-size-calculator-ca-bundle | ||
configMap: | ||
name: storage-size-calculator-ca-bundle |
13 changes: 13 additions & 0 deletions
13
config/overlays/openshift/size-calculator/logfile_metric_role.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
kind: Role | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
metadata: | ||
name: log-file-metric-exporter-privileged | ||
rules: | ||
- verbs: | ||
- use | ||
apiGroups: | ||
- security.openshift.io | ||
resources: | ||
- securitycontextconstraints | ||
resourceNames: | ||
- log-file-metric-exporter-scc |
11 changes: 11 additions & 0 deletions
11
config/overlays/openshift/size-calculator/logfile_metric_role_binding.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
kind: RoleBinding | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
metadata: | ||
name: log-file-metric-exporter-privileged-binding | ||
subjects: | ||
- kind: ServiceAccount | ||
name: log-file-metric-exporter | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: Role | ||
name: log-file-metric-exporter-privileged |
43 changes: 43 additions & 0 deletions
43
config/overlays/openshift/size-calculator/logfile_metric_scc.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
apiVersion: security.openshift.io/v1 | ||
kind: SecurityContextConstraints | ||
metadata: | ||
name: log-file-metric-exporter-scc | ||
allowPrivilegedContainer: true | ||
requiredDropCapabilities: | ||
- MKNOD | ||
- CHOWN | ||
- DAC_OVERRIDE | ||
- FSETID | ||
- FOWNER | ||
- SETGID | ||
- SETUID | ||
- SETPCAP | ||
- NET_BIND_SERVICE | ||
- KILL | ||
allowHostDirVolumePlugin: true | ||
allowHostPorts: false | ||
runAsUser: | ||
type: RunAsAny | ||
users: [] | ||
allowHostIPC: false | ||
seLinuxContext: | ||
type: RunAsAny | ||
readOnlyRootFilesystem: false | ||
fsGroup: | ||
type: RunAsAny | ||
groups: | ||
- 'system:cluster-admins' | ||
defaultAddCapabilities: null | ||
supplementalGroups: | ||
type: RunAsAny | ||
volumes: | ||
- configMap | ||
- downwardAPI | ||
- emptyDir | ||
- persistentVolumeClaim | ||
- projected | ||
- secret | ||
allowHostPID: false | ||
allowHostNetwork: false | ||
allowPrivilegeEscalation: true | ||
allowedCapabilities: null |
16 changes: 16 additions & 0 deletions
16
config/overlays/openshift/size-calculator/logfile_metric_service.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: log-file-metric-exporter-metrics | ||
labels: | ||
name: log-file-metric-exporter | ||
annotations: | ||
service.beta.openshift.io/serving-cert-secret-name: log-file-metric-exporter-metrics | ||
spec: | ||
ports: | ||
- name: logfile-metrics | ||
port: 2112 | ||
protocol: TCP | ||
targetPort: logfile-metrics | ||
selector: | ||
name: log-file-metric-exporter |
9 changes: 9 additions & 0 deletions
9
config/overlays/openshift/size-calculator/logfile_metric_service_account.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
kind: ServiceAccount | ||
apiVersion: v1 | ||
metadata: | ||
name: log-file-metric-exporter | ||
secrets: | ||
- name: logfile-metric-dockercfg | ||
- name: logfile-metric-token | ||
imagePullSecrets: | ||
- name: logfile-metric-dockercfg |
20 changes: 20 additions & 0 deletions
20
config/overlays/openshift/size-calculator/logfile_metric_service_monitor.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
apiVersion: monitoring.coreos.com/v1 | ||
kind: ServiceMonitor | ||
metadata: | ||
name: monitor-log-file-metric-exporter | ||
labels: | ||
name: log-file-metric-exporter | ||
spec: | ||
selector: | ||
matchLabels: | ||
name: log-file-metric-exporter | ||
endpoints: | ||
- bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token | ||
path: /metrics | ||
port: logfile-metrics | ||
scheme: https | ||
interval: 30s | ||
scrapeTimeout: 10s | ||
tlsConfig: | ||
caFile: /etc/prometheus/configmaps/serving-certs-ca-bundle/service-ca.crt | ||
serverName: log-file-metric-exporter-metrics.openshift-logging.svc |
Oops, something went wrong.