Skip to content

Instantly share code, notes, and snippets.

View mathias21's full-sized avatar

Jorge mathias21

View GitHub Profile
@mathias21
mathias21 / CalculateEdgeTest
Last active April 3, 2023 20:56
Symmetric points exercise
import org.junit.jupiter.api.Test
class CalculateEdgeTest {
@Test
fun `given two positive x points, calculate edge should return correct value`() {
val result1 = calculateEdge(listOf(Point(105, 0), Point(101, 0)))
assert(result1 == 103)
}
@mathias21
mathias21 / Application.kt
Created October 7, 2020 21:48
KtorEasy: PrometheusRegistry dependency setup
fun main(args: Array<String>) {
[...]
embeddedServer(Netty, port = config.port) {
println("Starting instance in ${config.host}:${config.port}")
module {
install(Koin) {
modules(
module {
[...]
single { PrometheusMeterRegistry(PrometheusConfig.DEFAULT) }
@mathias21
mathias21 / Module.kt
Last active October 7, 2020 21:41
KtorEasy: modules for monitoring
fun Application.module() {
[...]
// Metrics feature installation, adding Micrometer as the preferred lib
install(MicrometerMetrics) {
registry = get<PrometheusMeterRegistry>()
meterBinders = listOf(
ClassLoaderMetrics(),
JvmMemoryMetrics(),
JvmGcMetrics(),
ProcessorMetrics(),
@mathias21
mathias21 / build.gradle
Created October 7, 2020 21:24
KtorEasy: build.gradle for monitoring
apply plugin: 'kotlin'
apply plugin: 'application'
apply plugin: 'com.github.johnrengelman.shadow'
[...]
dependencies {
[...]
implementation "io.ktor:ktor-metrics:$ktor_version"
@mathias21
mathias21 / MetricsModule.kt
Created October 7, 2020 18:09
KtorEasy: metrics route config
fun Routing.metrics() {
val registry = get<PrometheusMeterRegistry>()
get("/metrics") {
call.respondText {
registry.scrape()
}
}
}
@mathias21
mathias21 / prometheus.yml
Created October 7, 2020 17:57
KtorEasy: Prometheus configuration
scrape_configs:
- job_name: 'KtorEasy'
metrics_path: /metrics
scrape_interval: 5s
static_configs:
- targets: ['backend:3500']
@mathias21
mathias21 / docker-compose.yml
Created October 7, 2020 17:30
KtorEasy: monitoring compose
version: '2.1'
services:
db:
image: mariadb:latest
restart: always
environment:
- MYSQL_ROOT_PASSWORD=mypassword
- MYSQL_DATABASE=ktoreasydb
- MYSQL_USER=ktoreasyuser
- MYSQL_PASSWORD=ktoreasypassword
@mathias21
mathias21 / docker-compose.yml
Last active September 20, 2020 21:28
KtorEasy: Automatic Database backup
###################### PREVIOUS DOCKER-COMPOSE FILE ###############
version: '2.1'
services:
db:
image: mariadb:latest
restart: always
volumes:
- ./db/KtorEasyDBSnap:/var/lib/mysql
- ./db/dbConfig:/etc/mysql/conf.d
environment:
@mathias21
mathias21 / docker-compose.yml
Created September 18, 2020 10:07
KtorEasy: Docker compose example
version: '2.1'
# Services we are going to use when running
services:
# Database instance we need to store data
db:
image: mariadb:latest
restart: always
environment:
- MYSQL_ROOT_PASSWORD=mypassword
@mathias21
mathias21 / application.conf
Created September 18, 2020 09:41
KtorEasy: Application configurations file
ktor {
deployment {
dev {
host = "localhost"
port = 3500
databaseHost = "db"
databasePort = "3306"
}
uat {
host = "myhost.com"