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

fix metrics-report-generator descriptors query #168

Merged
merged 3 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -2,4 +2,6 @@ package it.pagopa.interop.metricsreportgenerator.util

object Errors {
final case object InterfacePathNotFound extends Exception(s"Interface path not found in active descriptor")
final case class ChecksumNotFound(descriptorId: String)
extends Exception(s"Interface checksum not found in active descriptor $descriptorId")
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Jobs(config: Configuration, readModel: ReadModelService)(implicit
ReadModelQueries
.getAllDescriptors(config.collections, readModel)
.map(_.filter(_.isActive).toList)
.map(_.map(_.toMetric))
.flatMap(xs => Future.traverse(xs)(_.toMetric))
.map(asCsv)
.map(_.mkString("\n"))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ object ReadModelQueries {
include("name", "createdAt", "producerId"),
computed("descriptorId", "$descriptors.id"),
computed("state", "$descriptors.state"),
computed("interfacePath", "$descriptors.interfacePath"),
computed("checksum", "$descriptors.checksum"),
computed("producer", "$producerTenant.data.name")
)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package it.pagopa.interop.metricsreportgenerator.util.models

import java.time.LocalDate
import cats.syntax.all._
import it.pagopa.interop.commons.utils.errors.GenericComponentErrors.GenericError
import scala.util._
import it.pagopa.interop.metricsreportgenerator.util.Errors.ChecksumNotFound
import spray.json.DefaultJsonProtocol._
import spray.json._
import cats.syntax.all._
import java.time.Instant
import java.time.ZoneId

import java.time.{Instant, LocalDate, ZoneId}
import scala.concurrent.Future
import scala.util._

final case class Agreement(
activationDate: Option[String],
Expand Down Expand Up @@ -36,12 +37,15 @@ final case class Descriptor(
producer: String,
descriptorId: String,
state: String,
checksum: String
checksum: Option[String]
) {
def isActive: Boolean = state == "Suspended" || state == "Published" || state == "Deprecated"

def toMetric: MetricDescriptor =
MetricDescriptor(name, createdAt, producerId, producer, descriptorId, state, checksum)
def toMetric: Future[MetricDescriptor] = checksum
.fold[Future[MetricDescriptor]](Future.failed(ChecksumNotFound(descriptorId)))(chs =>
Future.successful(MetricDescriptor(name, createdAt, producerId, producer, descriptorId, state, chs))
)

}

object Descriptor {
Expand Down
Loading