diff --git a/src/main/kotlin/io/meshcloud/dockerosb/metrics/MetricType.kt b/src/main/kotlin/io/meshcloud/dockerosb/metrics/MetricType.kt deleted file mode 100644 index 2f1bc49..0000000 --- a/src/main/kotlin/io/meshcloud/dockerosb/metrics/MetricType.kt +++ /dev/null @@ -1,7 +0,0 @@ -package io.meshcloud.dockerosb.metrics - -enum class MetricType { - GAUGE, - PERIODIC, - SAMPLING -} \ No newline at end of file diff --git a/src/main/kotlin/io/meshcloud/dockerosb/metrics/MetricsProvider.kt b/src/main/kotlin/io/meshcloud/dockerosb/metrics/MetricsProvider.kt deleted file mode 100644 index 15e9e33..0000000 --- a/src/main/kotlin/io/meshcloud/dockerosb/metrics/MetricsProvider.kt +++ /dev/null @@ -1,25 +0,0 @@ -package io.meshcloud.dockerosb.metrics - -import io.meshcloud.dockerosb.findServiceByDefinitionId -import io.meshcloud.dockerosb.persistence.ServiceInstanceRepository -import org.springframework.cloud.servicebroker.model.catalog.Catalog -import java.time.Instant - -abstract class MetricsProvider( - val catalog: Catalog, - val serviceInstanceRepository: ServiceInstanceRepository -) { - - abstract fun getMetrics(serviceDefinitionId: String, from: Instant, to: Instant, index: Int): List> - - fun canHandle(serviceDefinitionId: String): Boolean { - return catalog.findServiceByDefinitionId(serviceDefinitionId) != null - } - - /** - * Total count of instances for which this provider provides metrics - */ - fun totalInstanceCount(serviceDefinitionId: String): Int { - return serviceInstanceRepository.findInstancesByServiceId(serviceDefinitionId).count() - } -} \ No newline at end of file diff --git a/src/main/kotlin/io/meshcloud/dockerosb/metrics/MetricsResponse.kt b/src/main/kotlin/io/meshcloud/dockerosb/metrics/MetricsResponse.kt deleted file mode 100644 index 0c6f321..0000000 --- a/src/main/kotlin/io/meshcloud/dockerosb/metrics/MetricsResponse.kt +++ /dev/null @@ -1,8 +0,0 @@ -package io.meshcloud.dockerosb.metrics - -import org.springframework.hateoas.RepresentationModel - - -data class MetricsResponse( - val dataPoints: List> -) : RepresentationModel>() diff --git a/src/main/kotlin/io/meshcloud/dockerosb/metrics/ServiceInstanceDatapoints.kt b/src/main/kotlin/io/meshcloud/dockerosb/metrics/ServiceInstanceDatapoints.kt deleted file mode 100644 index add7329..0000000 --- a/src/main/kotlin/io/meshcloud/dockerosb/metrics/ServiceInstanceDatapoints.kt +++ /dev/null @@ -1,7 +0,0 @@ -package io.meshcloud.dockerosb.metrics - -data class ServiceInstanceDatapoints( - val serviceInstanceId: String, - val resource: String, - var values: List -) \ No newline at end of file diff --git a/src/main/kotlin/io/meshcloud/dockerosb/metrics/gauge/GaugeMetricModel.kt b/src/main/kotlin/io/meshcloud/dockerosb/metrics/gauge/GaugeMetricModel.kt deleted file mode 100644 index 70deca8..0000000 --- a/src/main/kotlin/io/meshcloud/dockerosb/metrics/gauge/GaugeMetricModel.kt +++ /dev/null @@ -1,10 +0,0 @@ -package io.meshcloud.dockerosb.metrics.gauge - -import java.math.BigDecimal -import java.time.Instant - -data class GaugeMetricModel( - val writtenAt: Instant, - val observedAt: Instant, - val value: BigDecimal -) \ No newline at end of file diff --git a/src/main/kotlin/io/meshcloud/dockerosb/metrics/gauge/GaugeMetricProvider.kt b/src/main/kotlin/io/meshcloud/dockerosb/metrics/gauge/GaugeMetricProvider.kt deleted file mode 100644 index 8941914..0000000 --- a/src/main/kotlin/io/meshcloud/dockerosb/metrics/gauge/GaugeMetricProvider.kt +++ /dev/null @@ -1,30 +0,0 @@ -package io.meshcloud.dockerosb.metrics.gauge - -import io.meshcloud.dockerosb.findServiceByDefinitionId -import io.meshcloud.dockerosb.metrics.MetricType -import io.meshcloud.dockerosb.metrics.MetricsProvider -import io.meshcloud.dockerosb.metrics.ServiceInstanceDatapoints -import io.meshcloud.dockerosb.persistence.ServiceInstanceRepository -import org.springframework.cloud.servicebroker.model.catalog.Catalog -import org.springframework.stereotype.Service -import java.time.Instant - -/** - * Sends the metrics of each instance in a paged fashion - */ -@Service -class GaugeMetricProvider( - catalog: Catalog, - serviceInstanceRepository: ServiceInstanceRepository -) : MetricsProvider(catalog, serviceInstanceRepository) { - - override fun getMetrics(serviceDefinitionId: String, from: Instant, to: Instant, index: Int): List> { - val instances = serviceInstanceRepository.findInstancesByServiceId(serviceDefinitionId) - - return if (instances.size > index) { - serviceInstanceRepository.tryGetServiceInstanceGaugeMetrics(instances[index].serviceInstanceId, from, to) - } else { - listOf() - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/io/meshcloud/dockerosb/metrics/gauge/PagedGaugeController.kt b/src/main/kotlin/io/meshcloud/dockerosb/metrics/gauge/PagedGaugeController.kt deleted file mode 100644 index f7ef953..0000000 --- a/src/main/kotlin/io/meshcloud/dockerosb/metrics/gauge/PagedGaugeController.kt +++ /dev/null @@ -1,54 +0,0 @@ -package io.meshcloud.dockerosb.metrics.gauge - -import io.meshcloud.dockerosb.metrics.MetricsProvider -import io.meshcloud.dockerosb.metrics.MetricsResponse -import org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo -import org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn -import org.springframework.http.HttpStatus -import org.springframework.http.ResponseEntity -import org.springframework.web.bind.annotation.GetMapping -import org.springframework.web.bind.annotation.PathVariable -import org.springframework.web.bind.annotation.RequestParam -import org.springframework.web.bind.annotation.RestController -import java.time.Instant - - -@RestController -class PagedGaugeController( - private val metricsProviders: List> -) { - - @GetMapping("/metrics/gauges/{serviceDefinitionId}") - fun getGaugeMetricValues( - @PathVariable("serviceDefinitionId") serviceDefinitionId: String, - @RequestParam from: Instant, - @RequestParam to: Instant - ): ResponseEntity> { - return getResponse(serviceDefinitionId, from, to, 0) - } - - @GetMapping("/metrics/gauges/{serviceDefinitionId}/{index}") - fun getGaugeMetricValues( - @PathVariable("serviceDefinitionId") serviceDefinitionId: String, - @PathVariable(name = "index", required = false) index: Int, - @RequestParam from: Instant, - @RequestParam to: Instant - ): ResponseEntity> { - return getResponse(serviceDefinitionId, from, to, index) - } - - private fun getResponse(serviceDefinitionId: String, from: Instant, to: Instant, instanceIndex: Int): ResponseEntity> { - val provider = metricsProviders.firstOrNull { it.canHandle(serviceDefinitionId) } - ?: throw IllegalArgumentException("Could not find a matching provider for service id $serviceDefinitionId!") - if (instanceIndex < 0) throw IllegalArgumentException("Instance Index cannot be lower than 0!") - val dataPoints = provider.getMetrics(serviceDefinitionId, from, to, instanceIndex) - val response = MetricsResponse(dataPoints) - val hasMorePages = instanceIndex < provider.totalInstanceCount(serviceDefinitionId) - 1 - if (hasMorePages) { - val nextLink = linkTo(methodOn(PagedGaugeController::class.java).getGaugeMetricValues( - serviceDefinitionId, instanceIndex + 1, from, to)) - response.add(nextLink.withRel("next")) - } - return ResponseEntity(response, HttpStatus.OK) - } -} diff --git a/src/main/kotlin/io/meshcloud/dockerosb/metrics/periodiccounter/PeriodicCounterController.kt b/src/main/kotlin/io/meshcloud/dockerosb/metrics/periodiccounter/PeriodicCounterController.kt deleted file mode 100644 index db712e3..0000000 --- a/src/main/kotlin/io/meshcloud/dockerosb/metrics/periodiccounter/PeriodicCounterController.kt +++ /dev/null @@ -1,53 +0,0 @@ -package io.meshcloud.dockerosb.metrics.periodiccounter - -import io.meshcloud.dockerosb.metrics.MetricsResponse -import org.springframework.hateoas.server.mvc.WebMvcLinkBuilder -import org.springframework.http.HttpStatus -import org.springframework.http.ResponseEntity -import org.springframework.web.bind.annotation.GetMapping -import org.springframework.web.bind.annotation.PathVariable -import org.springframework.web.bind.annotation.RequestParam -import org.springframework.web.bind.annotation.RestController -import java.time.Instant - - -@RestController -class PeriodicCounterController( - private val metricsProviders: List -) { - - @GetMapping("/metrics/periodicCounters/{serviceDefinitionId}") - fun getPeriodicCounterMetricValues( - @PathVariable("serviceDefinitionId") serviceDefinitionId: String, - @RequestParam from: Instant, - @RequestParam to: Instant - ): ResponseEntity> { - return getResponse(serviceDefinitionId, from, to, 0) - } - - @GetMapping("/metrics/periodicCounters/{serviceDefinitionId}/{index}") - fun getPeriodicCounterMetricValues( - @PathVariable("serviceDefinitionId") serviceDefinitionId: String, - @PathVariable(name = "index", required = false) index: Int, - @RequestParam from: Instant, - @RequestParam to: Instant - ): ResponseEntity> { - return getResponse(serviceDefinitionId, from, to, index) - } - - private fun getResponse(serviceDefinitionId: String, from: Instant, to: Instant, instanceIndex: Int): ResponseEntity> { - val provider = metricsProviders.firstOrNull { it.canHandle(serviceDefinitionId) } - ?: throw IllegalArgumentException("Could not find a matching provider for service id $serviceDefinitionId!") - if (instanceIndex < 0) throw IllegalArgumentException("Instance Index cannot be lower than 0!") - val dataPoints = provider.getMetrics(serviceDefinitionId, from, to, instanceIndex) - val response = MetricsResponse(dataPoints) - val hasMorePages = instanceIndex < provider.totalInstanceCount(serviceDefinitionId) - 1 - if (hasMorePages) { - val nextLink = WebMvcLinkBuilder.linkTo(WebMvcLinkBuilder.methodOn(PeriodicCounterController::class.java).getPeriodicCounterMetricValues( - serviceDefinitionId, instanceIndex + 1, from, to)) - response.add(nextLink.withRel("next")) - } - return ResponseEntity(response, HttpStatus.OK) - } - -} diff --git a/src/main/kotlin/io/meshcloud/dockerosb/metrics/periodiccounter/PeriodicCounterMetricModel.kt b/src/main/kotlin/io/meshcloud/dockerosb/metrics/periodiccounter/PeriodicCounterMetricModel.kt deleted file mode 100644 index dcfe751..0000000 --- a/src/main/kotlin/io/meshcloud/dockerosb/metrics/periodiccounter/PeriodicCounterMetricModel.kt +++ /dev/null @@ -1,11 +0,0 @@ -package io.meshcloud.dockerosb.metrics.periodiccounter - -import java.math.BigDecimal -import java.time.Instant - -data class PeriodicCounterMetricModel( - val writtenAt: Instant, - val periodStart: Instant, - val periodEnd: Instant, - val countedValue: BigDecimal -) diff --git a/src/main/kotlin/io/meshcloud/dockerosb/metrics/periodiccounter/PeriodicCounterMetricProvider.kt b/src/main/kotlin/io/meshcloud/dockerosb/metrics/periodiccounter/PeriodicCounterMetricProvider.kt deleted file mode 100644 index 5bb6507..0000000 --- a/src/main/kotlin/io/meshcloud/dockerosb/metrics/periodiccounter/PeriodicCounterMetricProvider.kt +++ /dev/null @@ -1,27 +0,0 @@ -package io.meshcloud.dockerosb.metrics.periodiccounter - -import io.meshcloud.dockerosb.findServiceByDefinitionId -import io.meshcloud.dockerosb.metrics.MetricType -import io.meshcloud.dockerosb.metrics.MetricsProvider -import io.meshcloud.dockerosb.metrics.ServiceInstanceDatapoints -import io.meshcloud.dockerosb.persistence.ServiceInstanceRepository -import org.springframework.cloud.servicebroker.model.catalog.Catalog -import org.springframework.stereotype.Service -import java.time.Instant - -@Service -class PeriodicCounterMetricProvider( - catalog: Catalog, - serviceInstanceRepository: ServiceInstanceRepository -) : MetricsProvider(catalog, serviceInstanceRepository) { - - override fun getMetrics(serviceDefinitionId: String, from: Instant, to: Instant, index: Int): List> { - val instances = serviceInstanceRepository.findInstancesByServiceId(serviceDefinitionId) - - return if (instances.size > index) { - serviceInstanceRepository.tryGetServiceInstancePeriodicCounterMetrics(instances[index].serviceInstanceId, from, to) - } else { - listOf() - } - } -} diff --git a/src/main/kotlin/io/meshcloud/dockerosb/metrics/samplingcounter/SamplingCounterController.kt b/src/main/kotlin/io/meshcloud/dockerosb/metrics/samplingcounter/SamplingCounterController.kt deleted file mode 100644 index bb4e342..0000000 --- a/src/main/kotlin/io/meshcloud/dockerosb/metrics/samplingcounter/SamplingCounterController.kt +++ /dev/null @@ -1,54 +0,0 @@ -package io.meshcloud.dockerosb.metrics.samplingcounter - -import io.meshcloud.dockerosb.metrics.MetricsResponse -import io.meshcloud.dockerosb.metrics.periodiccounter.PeriodicCounterController -import io.meshcloud.dockerosb.metrics.periodiccounter.PeriodicCounterMetricModel -import org.springframework.hateoas.server.mvc.WebMvcLinkBuilder -import org.springframework.http.HttpStatus -import org.springframework.http.ResponseEntity -import org.springframework.web.bind.annotation.GetMapping -import org.springframework.web.bind.annotation.PathVariable -import org.springframework.web.bind.annotation.RequestParam -import org.springframework.web.bind.annotation.RestController -import java.time.Instant - -@RestController -class SamplingCounterController( - private val metricsProviders: List -) { - - @GetMapping("/metrics/samplingCounters/{serviceDefinitionId}") - fun getSamplingCounterMetricValues( - @PathVariable("serviceDefinitionId") serviceDefinitionId: String, - @RequestParam from: Instant, - @RequestParam to: Instant - ): ResponseEntity> { - return getResponse(serviceDefinitionId, from, to, 0) - } - - @GetMapping("/metrics/samplingCounters/{serviceDefinitionId}/{index}") - fun getSamplingCounterMetricValues( - @PathVariable("serviceDefinitionId") serviceDefinitionId: String, - @PathVariable(name = "index", required = false) index: Int, - @RequestParam from: Instant, - @RequestParam to: Instant - ): ResponseEntity> { - return getResponse(serviceDefinitionId, from, to, index) - } - - private fun getResponse(serviceDefinitionId: String, from: Instant, to: Instant, instanceIndex: Int): ResponseEntity> { - val provider = metricsProviders.firstOrNull { it.canHandle(serviceDefinitionId) } - ?: throw IllegalArgumentException("Could not find a matching provider for service id $serviceDefinitionId!") - if (instanceIndex < 0) throw IllegalArgumentException("Instance Index cannot be lower than 0!") - val dataPoints = provider.getMetrics(serviceDefinitionId, from, to, instanceIndex) - val response = MetricsResponse(dataPoints) - val hasMorePages = instanceIndex < provider.totalInstanceCount(serviceDefinitionId) - 1 - if (hasMorePages) { - val nextLink = WebMvcLinkBuilder.linkTo(WebMvcLinkBuilder.methodOn(SamplingCounterController::class.java).getSamplingCounterMetricValues( - serviceDefinitionId, instanceIndex + 1, from, to)) - response.add(nextLink.withRel("next")) - } - return ResponseEntity(response, HttpStatus.OK) - } - -} diff --git a/src/main/kotlin/io/meshcloud/dockerosb/metrics/samplingcounter/SamplingCounterMetricModel.kt b/src/main/kotlin/io/meshcloud/dockerosb/metrics/samplingcounter/SamplingCounterMetricModel.kt deleted file mode 100644 index 8ed7e84..0000000 --- a/src/main/kotlin/io/meshcloud/dockerosb/metrics/samplingcounter/SamplingCounterMetricModel.kt +++ /dev/null @@ -1,10 +0,0 @@ -package io.meshcloud.dockerosb.metrics.samplingcounter - -import java.math.BigDecimal -import java.time.Instant - -class SamplingCounterMetricModel( - val writtenAt: Instant, - val observedAt: Instant, - val value: BigDecimal -) diff --git a/src/main/kotlin/io/meshcloud/dockerosb/metrics/samplingcounter/SamplingCounterMetricProvider.kt b/src/main/kotlin/io/meshcloud/dockerosb/metrics/samplingcounter/SamplingCounterMetricProvider.kt deleted file mode 100644 index 3b7caea..0000000 --- a/src/main/kotlin/io/meshcloud/dockerosb/metrics/samplingcounter/SamplingCounterMetricProvider.kt +++ /dev/null @@ -1,25 +0,0 @@ -package io.meshcloud.dockerosb.metrics.samplingcounter - -import io.meshcloud.dockerosb.metrics.MetricsProvider -import io.meshcloud.dockerosb.metrics.ServiceInstanceDatapoints -import io.meshcloud.dockerosb.persistence.ServiceInstanceRepository -import org.springframework.cloud.servicebroker.model.catalog.Catalog -import org.springframework.stereotype.Service -import java.time.Instant - -@Service -class SamplingCounterMetricProvider( - catalog: Catalog, - serviceInstanceRepository: ServiceInstanceRepository -) : MetricsProvider(catalog, serviceInstanceRepository) { - - override fun getMetrics(serviceDefinitionId: String, from: Instant, to: Instant, index: Int): List> { - val instances = serviceInstanceRepository.findInstancesByServiceId(serviceDefinitionId) - - return if (instances.size > index) { - serviceInstanceRepository.tryGetServiceInstanceSamplingCounterMetrics(instances[index].serviceInstanceId, from, to) - } else { - listOf() - } - } -} diff --git a/src/main/kotlin/io/meshcloud/dockerosb/persistence/ServiceInstanceRepository.kt b/src/main/kotlin/io/meshcloud/dockerosb/persistence/ServiceInstanceRepository.kt index 89a603b..04998ba 100644 --- a/src/main/kotlin/io/meshcloud/dockerosb/persistence/ServiceInstanceRepository.kt +++ b/src/main/kotlin/io/meshcloud/dockerosb/persistence/ServiceInstanceRepository.kt @@ -1,13 +1,9 @@ package io.meshcloud.dockerosb.persistence -import io.meshcloud.dockerosb.metrics.MetricType -import io.meshcloud.dockerosb.metrics.ServiceInstanceDatapoints -import io.meshcloud.dockerosb.metrics.gauge.GaugeMetricModel -import io.meshcloud.dockerosb.metrics.periodiccounter.PeriodicCounterMetricModel -import io.meshcloud.dockerosb.metrics.samplingcounter.SamplingCounterMetricModel import io.meshcloud.dockerosb.model.ServiceInstance import io.meshcloud.dockerosb.model.Status import org.springframework.cloud.servicebroker.model.instance.OperationState +import org.springframework.jmx.support.MetricType import org.springframework.stereotype.Component import java.io.File import java.time.Instant @@ -89,83 +85,6 @@ class ServiceInstanceRepository(private val yamlHandler: YamlHandler, private va return yamlHandler.readObject(instanceYml, ServiceInstance::class.java) } - fun tryGetServiceInstanceGaugeMetrics(serviceInstanceId: String, from: Instant, to: Instant): List> { - val instanceMetricsYmlFiles = serviceInstanceMetricsYmlFiles(serviceInstanceId, MetricType.GAUGE) - val serviceInstanceDatapointsList: MutableList> = mutableListOf() - val combinedInstanceMetricsList = instanceMetricsYmlFiles.map{yamlHandler.readGeneric>(it)} - val serviceInstanceIdGroup = combinedInstanceMetricsList.groupBy { it.serviceInstanceId } - - for (uniqueServiceInstance in serviceInstanceIdGroup){ - val resourceGroup = uniqueServiceInstance.value.groupBy { it.resource } - for (uniqueResource in resourceGroup ){ - val filteredValues = uniqueResource.value - .flatMap { serviceInstanceDatapoints: ServiceInstanceDatapoints -> serviceInstanceDatapoints.values } - .filterNot { gaugeMetricModel: GaugeMetricModel -> gaugeMetricModel.observedAt < from || gaugeMetricModel.observedAt > to } - .sortedBy { gaugeMetricModel: GaugeMetricModel -> gaugeMetricModel.observedAt } - if (filteredValues.isNotEmpty()) - serviceInstanceDatapointsList += ServiceInstanceDatapoints(uniqueServiceInstance.key,uniqueResource.key,filteredValues) - } - } - - return serviceInstanceDatapointsList - } - - fun tryGetServiceInstancePeriodicCounterMetrics(serviceInstanceId: String, from: Instant, to: Instant): List> { - val instanceMetricsYmlFiles = serviceInstanceMetricsYmlFiles(serviceInstanceId, MetricType.PERIODIC) - // PERIODIC METRIC TYPE HAS DIFFERENT PARAMETER TO DECIDE TIME-FILTERING - val serviceInstanceDatapointsList: MutableList> = mutableListOf() - val combinedInstanceMetricsList = instanceMetricsYmlFiles.map{yamlHandler.readGeneric>(it)} - val serviceInstanceIdGroup = combinedInstanceMetricsList.groupBy { it.serviceInstanceId } - - for (uniqueServiceInstance in serviceInstanceIdGroup){ - val resourceGroup = uniqueServiceInstance.value.groupBy { it.resource } - for (uniqueResource in resourceGroup ){ - val filteredValues = uniqueResource.value - .flatMap { serviceInstanceDatapoints: ServiceInstanceDatapoints -> serviceInstanceDatapoints.values } - .filterNot { periodicCounterMetricModel: PeriodicCounterMetricModel -> periodicCounterMetricModel.periodStart < from || periodicCounterMetricModel.periodEnd > to } - .sortedBy { periodicCounterMetricModel: PeriodicCounterMetricModel -> periodicCounterMetricModel.periodStart } - if (filteredValues.isNotEmpty()) - serviceInstanceDatapointsList += ServiceInstanceDatapoints(uniqueServiceInstance.key,uniqueResource.key,filteredValues) - } - } - - return serviceInstanceDatapointsList - } - - fun tryGetServiceInstanceSamplingCounterMetrics(serviceInstanceId: String, from: Instant, to: Instant): List> { - val instanceMetricsYmlFiles = serviceInstanceMetricsYmlFiles(serviceInstanceId, MetricType.SAMPLING) - val serviceInstanceDatapointsList: MutableList> = mutableListOf() - val combinedInstanceMetricsList = instanceMetricsYmlFiles.map{yamlHandler.readGeneric>(it)} - val serviceInstanceIdGroup = combinedInstanceMetricsList.groupBy { it.serviceInstanceId } - - for (uniqueServiceInstance in serviceInstanceIdGroup){ - val resourceGroup = uniqueServiceInstance.value.groupBy { it.resource } - for (uniqueResource in resourceGroup ){ - val filteredValues = uniqueResource.value - .flatMap { serviceInstanceDatapoints: ServiceInstanceDatapoints -> serviceInstanceDatapoints.values } - .filterNot { samplingCounterMetricModel: SamplingCounterMetricModel -> samplingCounterMetricModel.observedAt < from || samplingCounterMetricModel.observedAt > to } - .sortedBy { samplingCounterMetricModel: SamplingCounterMetricModel -> samplingCounterMetricModel.observedAt } - if (filteredValues.isNotEmpty()) - serviceInstanceDatapointsList += ServiceInstanceDatapoints(uniqueServiceInstance.key,uniqueResource.key,filteredValues) - } - } - - return serviceInstanceDatapointsList - } - - - fun findInstancesByServiceId(serviceDefinitionId: String): List { - val files = gitHandler.instancesDirectory().listFiles() - ?: return emptyList() - - return files - .map { gitHandler.fileInRepo(gitHandler.instanceYmlRelativePath(it.name)) } - .filter { it.exists() } - .sortedBy { it.lastModified() } - .map { yamlHandler.readObject(it, ServiceInstance::class.java) } - .filter { it.serviceDefinitionId == serviceDefinitionId } - } - fun getServiceInstanceStatus(serviceInstanceId: String): Status { val statusYml = serviceInstanceStatusYmlFile(serviceInstanceId) @@ -178,11 +97,6 @@ class ServiceInstanceRepository(private val yamlHandler: YamlHandler, private va } } - private fun serviceInstanceMetricsYmlFiles(serviceInstanceId: String, metricType: MetricType): List { - return gitHandler.filesInRepo(instanceFolderPath(serviceInstanceId)).filter { it.name.startsWith(metricType.name.first().lowercase() + "-metrics") && - it.name.endsWith(".yml") }.toList() - } - private fun serviceInstanceYmlFile(serviceInstanceId: String): File { val instanceYmlPath = instanceFolderPath(serviceInstanceId) + "/instance.yml" diff --git a/src/test/kotlin/io/meshcloud/dockerosb/metrics/GaugeMetricsServiceTest.kt b/src/test/kotlin/io/meshcloud/dockerosb/metrics/GaugeMetricsServiceTest.kt deleted file mode 100644 index 3b8d4e8..0000000 --- a/src/test/kotlin/io/meshcloud/dockerosb/metrics/GaugeMetricsServiceTest.kt +++ /dev/null @@ -1,97 +0,0 @@ -package io.meshcloud.dockerosb.metrics - -import io.meshcloud.dockerosb.ServiceBrokerFixture -import io.meshcloud.dockerosb.metrics.gauge.GaugeMetricProvider -import io.meshcloud.dockerosb.metrics.gauge.PagedGaugeController -import io.meshcloud.dockerosb.persistence.ServiceInstanceRepository -import io.meshcloud.dockerosb.service.GenericCatalogService -import org.apache.commons.io.FileUtils -import org.junit.* -import org.springframework.cloud.servicebroker.model.catalog.Catalog -import java.io.File -import java.time.Instant - -class GaugeMetricsServiceTest { - private val serviceDefinitionId = "d40133dd-8373-4c25-8014-fde98f38a728" - private val serviceInstanceId = "testInstanceID" - private val serviceInstanceId2 = "testInstanceID2" - private val resource1 = "test" - private val resource2 = "testSecond" - private val firstStartDate = Instant.parse("2018-01-01T12:00:00Z") - private val secondStartDate = Instant.parse("2020-01-01T12:00:00Z") - private val endDate = Instant.parse("2022-12-01T12:00:00Z") - - companion object { - private lateinit var gaugeController:PagedGaugeController - private var fixture: ServiceBrokerFixture = ServiceBrokerFixture("src/test/resources/catalog.yml") - var serviceInstanceRepository: ServiceInstanceRepository = ServiceInstanceRepository(fixture.yamlHandler, fixture.gitHandler) - var catalogService: GenericCatalogService = GenericCatalogService(fixture.contextFactory) - - @BeforeClass - @JvmStatic - fun beforeClass() { - FileUtils.copyDirectory(File("src/test/resources/instances"), File("${fixture.localGitPath}/instances")) - gaugeController = PagedGaugeController(listOf(GaugeMetricProvider(catalogService.catalog.block() as Catalog, serviceInstanceRepository))) - } - - @AfterClass - @JvmStatic - fun afterClass() { - fixture.close() - FileUtils.deleteDirectory(File(fixture.localGitPath)) - } - } - - @Test - fun canReadMultipleFiles(){ - // can read multiple files for the same serviceInstanceId - val test1 = gaugeController.getGaugeMetricValues(serviceDefinitionId, firstStartDate, endDate).body?.dataPoints?.find { serviceInstanceDatapoints -> (serviceInstanceDatapoints.serviceInstanceId == serviceInstanceId && serviceInstanceDatapoints.resource==resource1 )} - Assert.assertEquals(serviceInstanceId,test1?.serviceInstanceId) - Assert.assertEquals(resource1, test1?.resource) - Assert.assertEquals(10, test1?.values?.count()) - } - - @Test - fun canReadMultipleFilesWithTimeFilter(){ - val test2 = gaugeController.getGaugeMetricValues(serviceDefinitionId, secondStartDate, endDate).body?.dataPoints?.find { serviceInstanceDatapoints -> (serviceInstanceDatapoints.serviceInstanceId == serviceInstanceId && serviceInstanceDatapoints.resource==resource1 ) } - Assert.assertEquals(serviceInstanceId,test2?.serviceInstanceId) - Assert.assertEquals(resource1, test2?.resource) - Assert.assertEquals(6, test2?.values?.count()) - } - - @Test - fun canSeparateOtherServiceInstanceIds(){ - // can separate other serviceInstanceIds - val test3 = gaugeController.getGaugeMetricValues(serviceDefinitionId, firstStartDate, endDate).body?.dataPoints?.find { serviceInstanceDatapoints -> (serviceInstanceDatapoints.serviceInstanceId == serviceInstanceId2 && serviceInstanceDatapoints.resource==resource1 ) } - Assert.assertEquals(serviceInstanceId2,test3?.serviceInstanceId) - Assert.assertEquals(resource1, test3?.resource) - Assert.assertEquals(5, test3?.values?.count()) - } - - @Test - fun canSeparateOtherServiceInstanceIdsWithTimeFilter(){ - // can separate other serviceInstanceIds and time filter works - val test4 = gaugeController.getGaugeMetricValues(serviceDefinitionId, secondStartDate, endDate).body?.dataPoints?.find { serviceInstanceDatapoints -> (serviceInstanceDatapoints.serviceInstanceId == serviceInstanceId2 && serviceInstanceDatapoints.resource==resource1 ) } - Assert.assertEquals(serviceInstanceId2,test4?.serviceInstanceId) - Assert.assertEquals(resource1, test4?.resource) - Assert.assertEquals(3, test4?.values?.count()) - } - - @Test - fun canSeparateDifferentResources(){ - // can separate different resources for the serviceInstanceId - val test5 = gaugeController.getGaugeMetricValues(serviceDefinitionId, firstStartDate, endDate).body?.dataPoints?.find { serviceInstanceDatapoints -> (serviceInstanceDatapoints.serviceInstanceId == serviceInstanceId && serviceInstanceDatapoints.resource==resource2 ) } - Assert.assertEquals(serviceInstanceId,test5?.serviceInstanceId) - Assert.assertEquals(resource2, test5?.resource) - Assert.assertEquals(6, test5?.values?.count()) - } - - @Test - fun canSeparateDifferentResourcesWithTimeFilter(){ - // can separate different resources for the serviceInstanceId and time filter works - val test6 = gaugeController.getGaugeMetricValues(serviceDefinitionId, secondStartDate, endDate).body?.dataPoints?.find { serviceInstanceDatapoints -> (serviceInstanceDatapoints.serviceInstanceId == serviceInstanceId && serviceInstanceDatapoints.resource==resource2 ) } - Assert.assertEquals(serviceInstanceId,test6?.serviceInstanceId) - Assert.assertEquals(resource2, test6?.resource) - Assert.assertEquals(4, test6?.values?.count()) - } -} diff --git a/src/test/kotlin/io/meshcloud/dockerosb/metrics/GetServiceInstanceMetricsTest.kt b/src/test/kotlin/io/meshcloud/dockerosb/metrics/GetServiceInstanceMetricsTest.kt deleted file mode 100644 index 2882ea1..0000000 --- a/src/test/kotlin/io/meshcloud/dockerosb/metrics/GetServiceInstanceMetricsTest.kt +++ /dev/null @@ -1,38 +0,0 @@ -package io.meshcloud.dockerosb.metrics - -import io.meshcloud.dockerosb.metrics.gauge.GaugeMetricModel -import io.meshcloud.dockerosb.persistence.YamlHandler -import org.assertj.core.api.Assertions.assertThat -import org.junit.Assert -import org.junit.Test -import java.io.File -import java.math.BigDecimal -import java.time.Instant - -class GetServiceInstanceMetricsTest { - private val uut = YamlHandler() - - @Test - fun canReadGenericMetrics() { - - val gaugeMetrics = uut.readGeneric>( - File("src/test/resources/metrics/gauge-test.yml") - ) - - Assert.assertEquals(gaugeMetrics.serviceInstanceId, "test") - Assert.assertEquals(gaugeMetrics.resource, "test-resource") - assertThat(gaugeMetrics.values).containsExactlyInAnyOrderElementsOf(listOf( - GaugeMetricModel( - writtenAt = Instant.parse("2021-12-01T16:37:23Z"), - observedAt = Instant.parse("2021-12-01T16:37:23Z"), - value = BigDecimal.valueOf(1.0) - ), - GaugeMetricModel( - writtenAt = Instant.parse("2021-12-02T16:37:23Z"), - observedAt = Instant.parse("2021-12-02T16:37:23Z"), - value = BigDecimal.valueOf(2.0) - ), - )) - } -} - diff --git a/src/test/kotlin/io/meshcloud/dockerosb/metrics/PeriodicCounterMetricsServiceTest.kt b/src/test/kotlin/io/meshcloud/dockerosb/metrics/PeriodicCounterMetricsServiceTest.kt deleted file mode 100644 index 9d676ce..0000000 --- a/src/test/kotlin/io/meshcloud/dockerosb/metrics/PeriodicCounterMetricsServiceTest.kt +++ /dev/null @@ -1,97 +0,0 @@ -package io.meshcloud.dockerosb.metrics - -import io.meshcloud.dockerosb.ServiceBrokerFixture -import io.meshcloud.dockerosb.metrics.periodiccounter.PeriodicCounterController -import io.meshcloud.dockerosb.metrics.periodiccounter.PeriodicCounterMetricProvider -import io.meshcloud.dockerosb.persistence.ServiceInstanceRepository -import io.meshcloud.dockerosb.service.GenericCatalogService -import org.apache.commons.io.FileUtils -import org.junit.* -import org.springframework.cloud.servicebroker.model.catalog.Catalog -import java.io.File -import java.time.Instant - -class PeriodicCounterMetricsServiceTest { - private val serviceDefinitionId = "d40133dd-8373-4c25-8014-fde98f38a728" - private val serviceInstanceId = "testInstanceID" - private val serviceInstanceId2 = "testInstanceID2" - private val resource1 = "test" - private val resource2 = "testSecond" - private val firstStartDate = Instant.parse("2018-01-01T12:00:00Z") - private val secondStartDate = Instant.parse("2020-01-01T12:00:00Z") - private val endDate = Instant.parse("2022-12-01T12:00:00Z") - - companion object { - private lateinit var periodicCounterController: PeriodicCounterController - private var fixture: ServiceBrokerFixture = ServiceBrokerFixture("src/test/resources/catalog.yml") - var serviceInstanceRepository: ServiceInstanceRepository = ServiceInstanceRepository(fixture.yamlHandler, fixture.gitHandler) - var catalogService: GenericCatalogService = GenericCatalogService(fixture.contextFactory) - - @BeforeClass - @JvmStatic - fun beforeClass() { - FileUtils.copyDirectory(File("src/test/resources/instances"), File("${fixture.localGitPath}/instances")) - periodicCounterController = PeriodicCounterController(listOf(PeriodicCounterMetricProvider(catalogService.catalog.block() as Catalog, serviceInstanceRepository))) - } - - @AfterClass - @JvmStatic - fun afterClass() { - fixture.close() - FileUtils.deleteDirectory(File(fixture.localGitPath)) - } - } - - @Test - fun canReadMultipleFiles(){ - // can read multiple files for the same serviceInstanceId - val test1 = periodicCounterController.getPeriodicCounterMetricValues(serviceDefinitionId, firstStartDate, endDate).body?.dataPoints?.find { serviceInstanceDatapoints -> (serviceInstanceDatapoints.serviceInstanceId == serviceInstanceId && serviceInstanceDatapoints.resource==resource1 )} - Assert.assertEquals(serviceInstanceId,test1?.serviceInstanceId) - Assert.assertEquals(resource1, test1?.resource) - Assert.assertEquals(6, test1?.values?.count()) - } - - @Test - fun canReadMultipleFilesWithTimeFilter(){ - val test2 = periodicCounterController.getPeriodicCounterMetricValues(serviceDefinitionId, secondStartDate, endDate).body?.dataPoints?.find { serviceInstanceDatapoints -> (serviceInstanceDatapoints.serviceInstanceId == serviceInstanceId && serviceInstanceDatapoints.resource==resource1 ) } - Assert.assertEquals(serviceInstanceId,test2?.serviceInstanceId) - Assert.assertEquals(resource1, test2?.resource) - Assert.assertEquals(2, test2?.values?.count()) - } - - @Test - fun canSeparateOtherServiceInstanceIds(){ - // can separate other serviceInstanceIds - val test3 = periodicCounterController.getPeriodicCounterMetricValues(serviceDefinitionId, firstStartDate, endDate).body?.dataPoints?.find { serviceInstanceDatapoints -> (serviceInstanceDatapoints.serviceInstanceId == serviceInstanceId2 && serviceInstanceDatapoints.resource==resource1 ) } - Assert.assertEquals(serviceInstanceId2,test3?.serviceInstanceId) - Assert.assertEquals(resource1, test3?.resource) - Assert.assertEquals(3, test3?.values?.count()) - } - - @Test - fun canSeparateOtherServiceInstanceIdsWithTimeFilter(){ - // can separate other serviceInstanceIds and time filter works - val test4 = periodicCounterController.getPeriodicCounterMetricValues(serviceDefinitionId, secondStartDate, endDate).body?.dataPoints?.find { serviceInstanceDatapoints -> (serviceInstanceDatapoints.serviceInstanceId == serviceInstanceId2 && serviceInstanceDatapoints.resource==resource1 ) } - Assert.assertEquals(serviceInstanceId2,test4?.serviceInstanceId) - Assert.assertEquals(resource1, test4?.resource) - Assert.assertEquals(1, test4?.values?.count()) - } - - @Test - fun canSeparateDifferentResources(){ - // can separate different resources for the serviceInstanceId - val test5 = periodicCounterController.getPeriodicCounterMetricValues(serviceDefinitionId, firstStartDate, endDate).body?.dataPoints?.find { serviceInstanceDatapoints -> (serviceInstanceDatapoints.serviceInstanceId == serviceInstanceId && serviceInstanceDatapoints.resource==resource2 ) } - Assert.assertEquals(serviceInstanceId,test5?.serviceInstanceId) - Assert.assertEquals(resource2, test5?.resource) - Assert.assertEquals(4, test5?.values?.count()) - } - - @Test - fun canSeparateDifferentResourcesWithTimeFilter(){ - // can separate different resources for the serviceInstanceId and time filter works - val test6 = periodicCounterController.getPeriodicCounterMetricValues(serviceDefinitionId, secondStartDate, endDate).body?.dataPoints?.find { serviceInstanceDatapoints -> (serviceInstanceDatapoints.serviceInstanceId == serviceInstanceId && serviceInstanceDatapoints.resource==resource2 ) } - Assert.assertEquals(serviceInstanceId,test6?.serviceInstanceId) - Assert.assertEquals(resource2, test6?.resource) - Assert.assertEquals(2, test6?.values?.count()) - } -} diff --git a/src/test/kotlin/io/meshcloud/dockerosb/metrics/SamplingCounterMetricsServiceTest.kt b/src/test/kotlin/io/meshcloud/dockerosb/metrics/SamplingCounterMetricsServiceTest.kt deleted file mode 100644 index ba705e4..0000000 --- a/src/test/kotlin/io/meshcloud/dockerosb/metrics/SamplingCounterMetricsServiceTest.kt +++ /dev/null @@ -1,97 +0,0 @@ -package io.meshcloud.dockerosb.metrics - -import io.meshcloud.dockerosb.ServiceBrokerFixture -import io.meshcloud.dockerosb.metrics.samplingcounter.SamplingCounterController -import io.meshcloud.dockerosb.metrics.samplingcounter.SamplingCounterMetricProvider -import io.meshcloud.dockerosb.persistence.ServiceInstanceRepository -import io.meshcloud.dockerosb.service.GenericCatalogService -import org.apache.commons.io.FileUtils -import org.junit.* -import org.springframework.cloud.servicebroker.model.catalog.Catalog -import java.io.File -import java.time.Instant - -class SamplingCounterMetricsServiceTest { - private val serviceDefinitionId = "d40133dd-8373-4c25-8014-fde98f38a728" - private val serviceInstanceId = "testInstanceID" - private val serviceInstanceId2 = "testInstanceID2" - private val resource1 = "test" - private val resource2 = "testSecond" - private val firstStartDate = Instant.parse("2018-01-01T12:00:00Z") - private val secondStartDate = Instant.parse("2020-01-01T12:00:00Z") - private val endDate = Instant.parse("2022-12-01T12:00:00Z") - - companion object { - private lateinit var samplingCounterController:SamplingCounterController - private var fixture: ServiceBrokerFixture = ServiceBrokerFixture("src/test/resources/catalog.yml") - var serviceInstanceRepository: ServiceInstanceRepository = ServiceInstanceRepository(fixture.yamlHandler, fixture.gitHandler) - var catalogService: GenericCatalogService = GenericCatalogService(fixture.contextFactory) - - @BeforeClass - @JvmStatic - fun beforeClass() { - FileUtils.copyDirectory(File("src/test/resources/instances"), File("${fixture.localGitPath}/instances")) - samplingCounterController = SamplingCounterController(listOf(SamplingCounterMetricProvider(catalogService.catalog.block() as Catalog, serviceInstanceRepository))) - } - - @AfterClass - @JvmStatic - fun afterClass() { - fixture.close() - FileUtils.deleteDirectory(File(fixture.localGitPath)) - } - } - - @Test - fun canReadMultipleFiles(){ - // can read multiple files for the same serviceInstanceId - val test1 = samplingCounterController.getSamplingCounterMetricValues(serviceDefinitionId, firstStartDate, endDate).body?.dataPoints?.find { serviceInstanceDatapoints -> (serviceInstanceDatapoints.serviceInstanceId == serviceInstanceId && serviceInstanceDatapoints.resource==resource1 )} - Assert.assertEquals(serviceInstanceId,test1?.serviceInstanceId) - Assert.assertEquals(resource1, test1?.resource) - Assert.assertEquals(10, test1?.values?.count()) - } - - @Test - fun canReadMultipleFilesWithTimeFilter(){ - val test2 = samplingCounterController.getSamplingCounterMetricValues(serviceDefinitionId, secondStartDate, endDate).body?.dataPoints?.find { serviceInstanceDatapoints -> (serviceInstanceDatapoints.serviceInstanceId == serviceInstanceId && serviceInstanceDatapoints.resource==resource1 ) } - Assert.assertEquals(serviceInstanceId,test2?.serviceInstanceId) - Assert.assertEquals(resource1, test2?.resource) - Assert.assertEquals(6, test2?.values?.count()) - } - - @Test - fun canSeparateOtherServiceInstanceIds(){ - // can separate other serviceInstanceIds - val test3 = samplingCounterController.getSamplingCounterMetricValues(serviceDefinitionId, firstStartDate, endDate).body?.dataPoints?.find { serviceInstanceDatapoints -> (serviceInstanceDatapoints.serviceInstanceId == serviceInstanceId2 && serviceInstanceDatapoints.resource==resource1 ) } - Assert.assertEquals(serviceInstanceId2,test3?.serviceInstanceId) - Assert.assertEquals(resource1, test3?.resource) - Assert.assertEquals(5, test3?.values?.count()) - } - - @Test - fun canSeparateOtherServiceInstanceIdsWithTimeFilter(){ - // can separate other serviceInstanceIds and time filter works - val test4 = samplingCounterController.getSamplingCounterMetricValues(serviceDefinitionId, secondStartDate, endDate).body?.dataPoints?.find { serviceInstanceDatapoints -> (serviceInstanceDatapoints.serviceInstanceId == serviceInstanceId2 && serviceInstanceDatapoints.resource==resource1 ) } - Assert.assertEquals(serviceInstanceId2,test4?.serviceInstanceId) - Assert.assertEquals(resource1, test4?.resource) - Assert.assertEquals(3, test4?.values?.count()) - } - - @Test - fun canSeparateDifferentResources(){ - // can separate different resources for the serviceInstanceId - val test5 = samplingCounterController.getSamplingCounterMetricValues(serviceDefinitionId, firstStartDate, endDate).body?.dataPoints?.find { serviceInstanceDatapoints -> (serviceInstanceDatapoints.serviceInstanceId == serviceInstanceId && serviceInstanceDatapoints.resource==resource2 ) } - Assert.assertEquals(serviceInstanceId,test5?.serviceInstanceId) - Assert.assertEquals(resource2, test5?.resource) - Assert.assertEquals(6, test5?.values?.count()) - } - - @Test - fun canSeparateDifferentResourcesWithTimeFilter(){ - // can separate different resources for the serviceInstanceId and time filter works - val test6 = samplingCounterController.getSamplingCounterMetricValues(serviceDefinitionId, secondStartDate, endDate).body?.dataPoints?.find { serviceInstanceDatapoints -> (serviceInstanceDatapoints.serviceInstanceId == serviceInstanceId && serviceInstanceDatapoints.resource==resource2 ) } - Assert.assertEquals(serviceInstanceId,test6?.serviceInstanceId) - Assert.assertEquals(resource2, test6?.resource) - Assert.assertEquals(4, test6?.values?.count()) - } -} diff --git a/src/test/kotlin/io/meshcloud/dockerosb/persistence/YamlHandlerTest.kt b/src/test/kotlin/io/meshcloud/dockerosb/persistence/YamlHandlerTest.kt deleted file mode 100644 index bff8aad..0000000 --- a/src/test/kotlin/io/meshcloud/dockerosb/persistence/YamlHandlerTest.kt +++ /dev/null @@ -1,39 +0,0 @@ -package io.meshcloud.dockerosb.persistence - -import io.meshcloud.dockerosb.metrics.ServiceInstanceDatapoints -import io.meshcloud.dockerosb.metrics.gauge.GaugeMetricModel -import org.assertj.core.api.Assertions.assertThat -import org.junit.Assert -import org.junit.Test -import java.io.File -import java.math.BigDecimal -import java.time.Instant - - -class YamlHandlerTest { - - private val uut = YamlHandler() - - @Test - fun canReadGenericMetrics() { - - val gaugeMetrics = uut.readGeneric>( - File("src/test/resources/metrics/gauge-test.yml") - ) - - Assert.assertEquals(gaugeMetrics.serviceInstanceId, "test") - Assert.assertEquals(gaugeMetrics.resource, "test-resource") - assertThat(gaugeMetrics.values).containsExactlyInAnyOrderElementsOf(listOf( - GaugeMetricModel( - writtenAt = Instant.parse("2021-12-01T16:37:23Z"), - observedAt = Instant.parse("2021-12-01T16:37:23Z"), - value = BigDecimal.valueOf(1.0) - ), - GaugeMetricModel( - writtenAt = Instant.parse("2021-12-02T16:37:23Z"), - observedAt = Instant.parse("2021-12-02T16:37:23Z"), - value = BigDecimal.valueOf(2.0) - ), - )) - } -} \ No newline at end of file