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

#245 Add the ability to query REST endpoints from Reader module #297

Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
b97b603
#244: Create the Info module
benedeki Aug 19, 2024
e623974
* fixed License headers
benedeki Aug 19, 2024
5e4eadb
* renamed to _Reader_
benedeki Aug 24, 2024
2e1e2ea
* README.md update
benedeki Aug 25, 2024
738c904
* fix
benedeki Aug 25, 2024
df8c9bd
* JaCoCO action update
benedeki Aug 26, 2024
5affd82
* added dummy code for testing coverage
benedeki Aug 26, 2024
0f1e121
* erroneous class renamed
benedeki Aug 26, 2024
d773a93
* Deleted wrong files
benedeki Aug 26, 2024
0776f9c
#245 Add the ability to query REST endpoints from Reader module
benedeki Sep 10, 2024
38fde1c
* Work still in progress
benedeki Sep 23, 2024
1ac2233
* the first working commit
benedeki Nov 1, 2024
e6dcb52
* Removed temporary notes
benedeki Nov 1, 2024
6968b02
* introduced `MonadError` into the `GenericServerConnection`
benedeki Nov 1, 2024
b9bacef
* Fixed UTs
benedeki Nov 1, 2024
bbb1e7f
* trying to get rid of Java 11 dependency
benedeki Nov 4, 2024
33e6628
* Downgraded sttpClient
benedeki Nov 4, 2024
f7ced56
* further downgrade
benedeki Nov 5, 2024
ca2116b
* Removed exceptions
benedeki Nov 6, 2024
e5e6f63
* commented out parts of README.md which are not yet part of the code
benedeki Nov 6, 2024
fe07272
- major rework
benedeki Nov 17, 2024
7656f6f
* doc fix
benedeki Nov 17, 2024
eb9a678
Merge branch 'master' into feature/245-add-the-ability-to-query-rest-…
benedeki Nov 17, 2024
7641c07
* disabled failing test
benedeki Nov 17, 2024
bc82a5b
* adjustments
benedeki Nov 18, 2024
0e7675e
- further cleaning
benedeki Nov 18, 2024
432716a
* tests progress
benedeki Nov 21, 2024
11b0a16
* several UTs added
benedeki Nov 22, 2024
2c3f145
Merge branch 'master' into feature/245-add-the-ability-to-query-rest-…
benedeki Nov 22, 2024
e07dffb
* last improvements before PR ready
benedeki Nov 24, 2024
3955a50
* description to class `ServerConfig`
benedeki Nov 25, 2024
b287a66
* removed empty line
benedeki Nov 25, 2024
d04d23b
* addressed PR comments
benedeki Nov 27, 2024
c344249
* just better implementation
benedeki Nov 30, 2024
a4759d1
Apply suggestions from code review
benedeki Dec 4, 2024
5ca4bd5
* small fixes
benedeki Dec 4, 2024
d5054b6
Merge branch 'master' into feature/245-add-the-ability-to-query-rest-…
benedeki Dec 4, 2024
f8c1d86
Apply suggestions from code review
benedeki Dec 4, 2024
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
3 changes: 2 additions & 1 deletion .github/workflows/test_filenames_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
excludes: |
server/src/test/scala/za/co/absa/atum/server/api/TestData.scala,
server/src/test/scala/za/co/absa/atum/server/api/TestTransactorProvider.scala,
server/src/test/scala/za/co/absa/atum/server/ConfigProviderTest.scala
server/src/test/scala/za/co/absa/atum/server/ConfigProviderTest.scala,
model/src/test/scala/za/co/absa/atum/model/testing/*
verbose-logging: 'false'
fail-on-violation: 'true'
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
- [Measurement](#measurement)
- [Checkpoint](#checkpoint)
- [Data Flow](#data-flow)
- [Usage](#usage)
- [Reader](#reader-usage)
- [How to generate Code coverage report](#how-to-generate-code-coverage-report)
- [How to Run in IntelliJ](#how-to-run-in-intellij)
- [How to Run Tests](#how-to-run-tests)
Expand Down Expand Up @@ -156,6 +158,65 @@ We can even say, that `Checkpoint` is a result of particular `Measurements` (ver
The journey of a dataset throughout various data transformations and pipelines. It captures the whole journey,
even if it involves multiple applications or ETL pipelines.

## Usage

### Reader usage
Reader module support several asynchronous http clients. The dependencies used for these clients are set as _optional_,
so the user of the module can decide which client to use and include only the necessary dependencies.

The clients are:

[//]: # (TODO #298 needs Java 11 cross-build)

[//]: # (#### Future based `HttpClientServerConnection`)

[//]: # (Uses `java.net.http.HttpClient` to send requests to the server, therefore requires no additional dependencies. But works )

[//]: # (only with Java 11 or higher. )

#### Future based `ArmeririaServerConnection`
Add
```scala
"com.softwaremill.sttp.client3" %% "armeria-backend" % "[version]"
```
to your dependencies.

#### Cats IO based `ArmeririaServerConnection`
Add
```scala
"org.typelevel." %% "cats-effect" % "[version]"
"com.softwaremill.sttp.client3" %% "armeria-backend-cats" % "[version]" // for cats-effect 3.x
// or
"com.softwaremill.sttp.client3" %% "armeria-backend-cats-ce2" % "[version]" // for cats-effect 2.x
```
"
to your dependencies.

[//]: # (TODO #298 needs Java 11 cross-build)

[//]: # (#### ZIO based `HttpClientServerConnection`)

[//]: # (Add)

[//]: # (```scala)

[//]: # ("com.softwaremill.sttp.client3" %% "zio" % "[version]" // for ZIO 2.x)

[//]: # ("com.softwaremill.sttp.client3" %% "zio1" % "[version]" // for ZIO 1.x)

[//]: # (```)

[//]: # (to your dependencies.)

#### ZIO based `ArmeririaServerConnection`
Add
```scala
"com.softwaremill.sttp.client3" %% "armeria-backend-zio" % "[version]" // for ZIO 2.x
"com.softwaremill.sttp.client3" %% "armeria-backend-zio1" % "[version]" // for ZIO 1.x
```
to your dependencies.



## How to generate Code coverage report
```sbt
Expand All @@ -172,6 +233,7 @@ Code coverage wil be generated on path:
To make this project runnable via IntelliJ, do the following:
- Make sure that your configuration in `server/src/main/resources/reference.conf`
is configured according to your needs
- When building within the UI be sure to have the option `-language:higherKinds` on in the compiler options
lsulak marked this conversation as resolved.
Show resolved Hide resolved

## How to Run Tests

Expand Down
10 changes: 6 additions & 4 deletions agent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,28 @@

## Usage

Create multiple `AtumContext` with different control measures to be applied
Create multiple `AtumContext` with different control measures to be applied

### Option 1
```scala
val atumContextInstanceWithRecordCount = AtumContext(processor = processor)
.withMeasureAdded(RecordCount(MockMeasureNames.recordCount1, controlCol = "id"))
.withMeasureAdded(RecordCount(MockMeasureNames.recordCount1, measuredColumn = "id"))

val atumContextWithSalaryAbsMeasure = atumContextInstanceWithRecordCount
.withMeasureAdded(AbsSumOfValuesOfColumn(controlCol = "salary"))
.withMeasureAdded(AbsSumOfValuesOfColumn(measuredColumn = "salary"))
```

### Option 2
### Option 2
Use `AtumPartitions` to get an `AtumContext` from the service using the `AtumAgent`.
```scala
val atumContext1 = AtumAgent.createAtumContext(atumPartition)
```

#### AtumPartitions
A list of key values that maintains the order of arrival of the items, the `AtumService`
is able to deliver the correct `AtumContext` according to the `AtumPartitions` we give it.
A list of key values that maintains the order of arrival of the items, the `AtumService`
is able to deliver the correct `AtumContext` according to the `AtumPartitions` we give it.
```scala
val atumPartitions = AtumPartitions().withPartitions(ListMap("name" -> "partition-name", "country" -> "SA", "gender" -> "female" ))

Expand Down
47 changes: 47 additions & 0 deletions database/src/main/postgres/runs/get_measurements.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2024 ABSA Group Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

CREATE OR REPLACE FUNCTION postgres.runs.get_measurements(
IN i_parameter TEXT,
OUT status INTEGER,
OUT status_text TEXT
) RETURNS record AS
$$
-------------------------------------------------------------------------------
--
-- Function: postgres.runs.get_measurements([Function_Param_Count])
-- [Description]
--
-- Parameters:
-- i_parameter -
--
-- Returns:
-- status - Status code
-- status_text - Status text
--
-- Status codes:
-- 10 - OK
--
-------------------------------------------------------------------------------
DECLARE
BEGIN

END;
$$
LANGUAGE plpgsql VOLATILE
SECURITY DEFINER;

GRANT EXECUTE ON FUNCTION postgres.runs.get_measurements() TO [user];
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2024 ABSA Group Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package za.co.absa.atum.model.testing.implicits

object StringImplicits {
implicit class StringLinearization(val str: String) extends AnyVal {
def linearize: String = {
str.stripMargin.replace("\r", "").replace("\n", "")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import za.co.absa.atum.model.ResultValueType
import za.co.absa.atum.model.dto.MeasureResultDTO.TypedValue
import za.co.absa.atum.model.dto._
import za.co.absa.atum.model.utils.JsonSyntaxExtensions._
import za.co.absa.atum.model.utils.SerializationUtilsTest.StringLinearization
import za.co.absa.atum.model.testing.implicits.StringImplicits.StringLinearization

import java.time.{ZoneId, ZoneOffset, ZonedDateTime}
import java.util.UUID
Expand Down Expand Up @@ -436,11 +436,3 @@ class SerializationUtilsUnitTests extends AnyFlatSpecLike {
}

}

object SerializationUtilsTest {
implicit class StringLinearization(val str: String) extends AnyVal {
def linearize: String = {
str.stripMargin.replace("\r", "").replace("\n", "")
}
}
}
49 changes: 44 additions & 5 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ object Dependencies {

val sparkCommons = "0.6.1"

val sttpClient = "3.5.2"
val sttpClient = "3.5.2" //last supported version for Java 8
val sttpCirceJson = "3.9.7"

val postgresql = "42.6.0"
Expand All @@ -64,6 +64,8 @@ object Dependencies {

val absaCommons = "2.0.0"

val catsEffect = "3.3.14"

def truncateVersion(version: String, parts: Int): String = {
version.split("\\.").take(parts).mkString(".")
}
Expand All @@ -90,9 +92,9 @@ object Dependencies {
private def jsonSerdeDependencies: Seq[ModuleID] = {

// Circe dependencies
lazy val circeCore = "io.circe" %% "circe-core" % Versions.circeJson
lazy val circeParser = "io.circe" %% "circe-parser" % Versions.circeJson
lazy val circeGeneric = "io.circe" %% "circe-generic" % Versions.circeJson
val circeCore = "io.circe" %% "circe-core" % Versions.circeJson
val circeParser = "io.circe" %% "circe-parser" % Versions.circeJson
val circeGeneric = "io.circe" %% "circe-generic" % Versions.circeJson

Seq(
circeCore,
Expand Down Expand Up @@ -236,9 +238,46 @@ object Dependencies {
}

def readerDependencies(scalaVersion: Version): Seq[ModuleID] = {
val zioOrg = "dev.zio"
val sbtOrg = "com.github.sbt"
val sttpClient3Org = "com.softwaremill.sttp.client3"
val typeLevelOrg = "org.typelevel"

// STTP core and Circe integration
lazy val sttpCore = sttpClient3Org %% "core" % Versions.sttpClient
lazy val sttpCirce = sttpClient3Org %% "circe" % Versions.sttpClient

// Armeria Future backend
lazy val sttpArmeririaFutureBackend = sttpClient3Org %% "armeria-backend" % Versions.sttpClient % Optional
// Armeria Cats backend
lazy val sttpArmeririaCatsBackend = sttpClient3Org %% "armeria-backend-cats" % Versions.sttpClient % Optional
lazy val catsEffect = typeLevelOrg %% "cats-effect" % Versions.catsEffect % Optional
// Armeria Zio backend
lazy val sttpArmeririaZioBackend = sttpClient3Org %% "armeria-backend-zio" % Versions.sttpClient % Optional
// HttpClient Zio backend
// lazy val sttpHttpClientZioBackend = sttpClient3Org %% "zio" % Versions.sttpClient % Optional TODO #298 needs Java 11 cross-build

// testing
lazy val zioTest = zioOrg %% "zio-test" % Versions.zio % Test
lazy val zioTestSbt = zioOrg %% "zio-test-sbt" % Versions.zio % Test
lazy val zioTestJunit = zioOrg %% "zio-test-junit" % Versions.zio % Test
lazy val sbtJunitInterface = sbtOrg % "junit-interface" % Versions.sbtJunitInterface % Test

Seq(
sttpCore,
sttpCirce,
sttpArmeririaFutureBackend,
sttpArmeririaCatsBackend,
catsEffect,
sttpArmeririaZioBackend,
// sttpHttpClientZioBackend, TODO #298 needs Java 11 cross-build
zioTest,
zioTestSbt,
zioTestJunit,
sbtJunitInterface
) ++
testDependencies
testDependencies ++
jsonSerdeDependencies
}

def databaseDependencies: Seq[ModuleID] = {
Expand Down
30 changes: 25 additions & 5 deletions project/Setup.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,37 @@ object Setup {
val serverAndDbScalaVersion: Version = scala213 //covers REST server and database modules
val clientSupportedScalaVersions: Seq[Version] = Seq(scala212, scala213)

val commonScalacOptions: Seq[String] = Seq("-unchecked", "-deprecation", "-feature", "-Xfatal-warnings")
val commonScalacOptions: Seq[String] = Seq(
"-unchecked",
"-deprecation",
"-feature",
"-Xfatal-warnings"
)

val serverAndDbJavacOptions: Seq[String] = Seq("-source", "11", "-target", "11", "-Xlint")
val serverAndDbScalacOptions: Seq[String] = Seq("-Ymacro-annotations")
val serverAndDbJavacOptions: Seq[String] = Seq(
"-source", "11",
"-target", "11",
"-Xlint"
)
val serverAndDbScalacOptions: Seq[String] = Seq(
"-language:higherKinds",
"-Ymacro-annotations"
)

val clientJavacOptions: Seq[String] = Seq("-source", "1.8", "-target", "1.8", "-Xlint")
def clientScalacOptions(scalaVersion: Version): Seq[String] = {
if (scalaVersion >= scala213) {
Seq("-release", "8", "-Ymacro-annotations")
Seq(
"-release", "8",
"-language:higherKinds",
"-Ymacro-annotations"
)
} else {
Seq("-release", "8", "-target:8")
Seq(
"-release", "8",
"-language:higherKinds",
"-target:8"
)
}
}

Expand Down
5 changes: 5 additions & 0 deletions project/VersionAxes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ object VersionAxes {
override val idSuffix: String = directorySuffix.replaceAll("""\W+""", "_")
}

case class JavaVersionAxis(javaVersion: String) extends sbt.VirtualAxis.WeakAxis {
override val directorySuffix = s"-jdk$javaVersion"
override val idSuffix: String = directorySuffix.replaceAll("""\W+""", "_")
}

private def camelCaseToLowerDashCase(origName: String): String = {
origName
.replaceAll("([A-Z])", "-$1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

package za.co.absa.atum.reader

class FlowReader {
import za.co.absa.atum.reader.basic.Reader
import za.co.absa.atum.reader.server.GenericServerConnection

class FlowReader[F[_]]()(override implicit val serverConnection: GenericServerConnection[F]) extends Reader[F]{
def foo(): String = {
// just to have some testable content
"bar"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

package za.co.absa.atum.reader

class PartitioningReader {
import za.co.absa.atum.reader.basic.Reader
import za.co.absa.atum.reader.server.GenericServerConnection

class PartitioningReader[F[_]]()(override implicit val serverConnection: GenericServerConnection[F]) extends Reader[F] {
def foo(): String = {
// just to have some testable content
"bar"
Expand Down
21 changes: 21 additions & 0 deletions reader/src/main/scala/za/co/absa/atum/reader/basic/Reader.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2021 ABSA Group Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package za.co.absa.atum.reader.basic

import za.co.absa.atum.reader.server.GenericServerConnection

abstract class Reader[F[_]](implicit val serverConnection: GenericServerConnection[F])
Loading
Loading