Skip to content

Commit

Permalink
BC-7882 fix resource definitions (#41)
Browse files Browse the repository at this point in the history
Co-authored-by: SevenWaysDP <[email protected]>
  • Loading branch information
Loki-Afro and SevenWaysDP authored Nov 27, 2024
1 parent 7cb44fc commit e6636e3
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 11 deletions.
22 changes: 15 additions & 7 deletions ansible/roles/tldraw-valkey/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,21 @@
defaultStorageClass: "{{ SC_DEFAULT_STORAGE_CLASS_NAME }}"
replica:
replicaCount: "{{ TLDRAW_VALKEY_REPLICAS }}"
resources:
limits:
cpu: "{{ TLDRAW_VALKEY_CPU_LIMITS|default('1000m', true) }}"
memory: "{{ TLDRAW_VALKEY_MEMORY_LIMITS|default('4Gi', true) }}"
requests:
cpu: "{{ TLDRAW_VALKEY_CPU_REQUESTS|default('100m', true) }}"
memory: "{{ TLDRAW_VALKEY_MEMORY_REQUESTS|default('1Gi', true) }}"
primary:
resources:
limits:
cpu: "{{ TLDRAW_VALKEY_CPU_LIMITS|default('1000m', true) }}"
memory: "{{ TLDRAW_VALKEY_MEMORY_LIMITS|default('4Gi', true) }}"
requests:
cpu: "{{ TLDRAW_VALKEY_CPU_REQUESTS|default('100m', true) }}"
memory: "{{ TLDRAW_VALKEY_MEMORY_REQUESTS|default('1Gi', true) }}"
auth:
existingSecret: tldraw-valkey-password
existingSecretPasswordKey: REDIS_SENTINEL_PASSWORD
Expand All @@ -45,12 +60,5 @@
create: false
# https://github.com/bitnami/charts/issues/9689
useHostnames: false
resources:
limits:
cpu: "{{ TLDRAW_VALKEY_CPU_LIMITS|default('1000m', true) }}"
memory: "{{ TLDRAW_VALKEY_MEMORY_LIMITS|default('4Gi', true) }}"
requests:
cpu: "{{ TLDRAW_VALKEY_CPU_REQUESTS|default('100m', true) }}"
memory: "{{ TLDRAW_VALKEY_MEMORY_REQUESTS|default('1Gi', true) }}"
tags:
- helm
8 changes: 8 additions & 0 deletions src/infra/metrics/metrics.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Transform } from 'class-transformer';
import { IsBoolean } from 'class-validator';

export class MetricConfig {
@IsBoolean()
@Transform(({ value }) => value === 'true')
public METRICS_COLLECT_DEFAULT = true;
}
4 changes: 3 additions & 1 deletion src/infra/metrics/metrics.module.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { Module } from '@nestjs/common';
import { ConfigurationModule } from '../configuration/configuration.module.js';
import { LoggerModule } from '../logger/logger.module.js';
import { MetricsController } from './api/metrics.controller.js';
import { MetricConfig } from './metrics.config.js';
import { MetricsService } from './metrics.service.js';

@Module({
imports: [LoggerModule],
imports: [LoggerModule, ConfigurationModule.register(MetricConfig)],
controllers: [MetricsController],
providers: [MetricsService],
})
Expand Down
15 changes: 12 additions & 3 deletions src/infra/metrics/metrics.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import { Injectable } from '@nestjs/common';
import { Gauge, Histogram, register } from 'prom-client';
import { Injectable, OnModuleInit } from '@nestjs/common';
import { collectDefaultMetrics, Gauge, Histogram, register } from 'prom-client';
import { MetricConfig } from './metrics.config.js';

@Injectable()
export class MetricsService {
export class MetricsService implements OnModuleInit {
public constructor(private config: MetricConfig) {}

public onModuleInit(): void {
if (this.config.METRICS_COLLECT_DEFAULT) {
collectDefaultMetrics();
}
}

public static readonly openConnectionsGauge = new Gauge({
name: 'tldraw_open_connections',
help: 'Number of open WebSocket connections on tldraw-server.',
Expand Down

0 comments on commit e6636e3

Please sign in to comment.