This repository has been archived by the owner on Nov 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initiell test versjon av henting av record metadata basert på traceId
- Loading branch information
Showing
5 changed files
with
225 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
name: Build, push, and deploy | ||
|
||
on: [push] | ||
env: | ||
IMAGE: europe-north1-docker.pkg.dev/${{ vars.NAIS_MANAGEMENT_PROJECT_ID }}/paw/${{ github.event.repository.name }} | ||
jobs: | ||
build: | ||
name: Build and push Docker container | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
id-token: write | ||
packages: write | ||
outputs: | ||
image: ${{ steps.docker-build-push.outputs.image }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-java@v3 | ||
with: | ||
java-version: 21 | ||
distribution: temurin | ||
cache: gradle | ||
- name: Set version | ||
run: echo "VERSION=$(date +'%y.%m.%d').${{ github.run_number }}-${{ github.run_attempt }}" >> $GITHUB_ENV | ||
- name: Login GAR | ||
uses: nais/login@v0 | ||
with: | ||
project_id: ${{ vars.NAIS_MANAGEMENT_PROJECT_ID }} | ||
identity_provider: ${{ secrets.NAIS_WORKLOAD_IDENTITY_PROVIDER }} | ||
team: paw | ||
- name: Build and push image and artifacts with Gradle | ||
id: docker-build-push | ||
working-directory: ./ | ||
run: | | ||
echo "image=${{ env.IMAGE }}:${{ env.VERSION }}" >> $GITHUB_OUTPUT | ||
echo -Pversion=${{ env.VERSION }} -Pimage=${{ env.IMAGE }} build test jib | ||
./gradlew -Pversion=${{ env.VERSION }} -Pimage=${{ env.IMAGE }} build test jib | ||
echo "DIGEST=$(cat app/build/jib-image.digest)" >> $GITHUB_ENV | ||
env: | ||
ORG_GRADLE_PROJECT_githubPassword: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Attest and sign | ||
uses: nais/[email protected] | ||
with: | ||
image_ref: ${{ env.IMAGE }}@${{ env.DIGEST }} | ||
deploy-dev: | ||
name: Deploy to dev-gcp | ||
needs: build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: nais/deploy/actions/deploy@v2 | ||
env: | ||
CLUSTER: dev-gcp | ||
RESOURCE: nais/nais.yaml | ||
VAR: image=${{ needs.build.outputs.image }},kafka=nav-dev,domain=dev.nav.no | ||
|
||
deploy-prod: | ||
# if: github.ref == 'refs/heads/main' | ||
if: false | ||
name: Deploy to prod-gcp | ||
needs: [build, deploy-dev] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: nais/deploy/actions/deploy@v2 | ||
env: | ||
TEAM: paw | ||
CLUSTER: prod-gcp | ||
RESOURCE: nais/nais.yaml | ||
VAR: image=${{ needs.build.outputs.image }},kafka=nav-prod,domain=nav.no |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 81 additions & 2 deletions
83
kafka-app/src/main/kotlin/no/nav/paw/arbeidssokerregisteret/debug/app/App.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,88 @@ | ||
package no.nav.paw.arbeidssokerregisteret.debug.app | ||
|
||
import io.confluent.kafka.serializers.KafkaAvroDeserializer | ||
import io.ktor.http.* | ||
import io.ktor.server.application.* | ||
import io.ktor.server.engine.* | ||
import io.ktor.server.netty.* | ||
import io.ktor.server.response.* | ||
import io.ktor.server.routing.* | ||
import no.nav.paw.config.hoplite.loadNaisOrLocalConfiguration | ||
import no.nav.paw.config.kafka.KAFKA_CONFIG | ||
import no.nav.paw.config.kafka.KafkaConfig | ||
import no.nav.paw.config.kafka.KafkaFactory | ||
import org.apache.avro.generic.GenericRecord | ||
import org.apache.kafka.clients.consumer.Consumer | ||
import org.apache.kafka.clients.consumer.ConsumerRecord | ||
import org.apache.kafka.common.TopicPartition | ||
import org.apache.kafka.common.serialization.LongDeserializer | ||
import java.time.Duration | ||
import java.time.Instant | ||
import java.util.UUID | ||
|
||
const val OPPLYSNINGER_TOPIC = "paw.opplysninger-om-arbeidssoeker-beta-v7" | ||
const val PERIODE_TOPIC = "paw.arbeidssokerperioder-beta-v7" | ||
const val PROFILERING = "paw.arbeidssoker-profilering-beta-v2" | ||
|
||
val topics = listOf(OPPLYSNINGER_TOPIC, PERIODE_TOPIC, PROFILERING) | ||
|
||
fun main() { | ||
val kafkaConfig = loadNaisOrLocalConfiguration<KafkaConfig>(KAFKA_CONFIG) | ||
val kafkaConfig = loadNaisOrLocalConfiguration<KafkaConfig>("kafka") | ||
val kafkaFactory = KafkaFactory(kafkaConfig) | ||
|
||
fun consumer(): Consumer<Long, Any> = kafkaFactory.createConsumer( | ||
groupId = "paw-arbeidssokerregisteret-debug-app-${UUID.randomUUID()}", | ||
clientId = "paw-arbeidssokerregisteret-debug-app-${UUID.randomUUID()}", | ||
keyDeserializer = LongDeserializer::class, | ||
valueDeserializer = KafkaAvroDeserializer::class | ||
) | ||
|
||
embeddedServer(Netty, port = 8080) { | ||
routing { | ||
get("/isAlive") { | ||
call.respondText("I'm alive!") | ||
} | ||
get("/isReady") { | ||
call.respondText("I'm ready!") | ||
} | ||
get("api-topics/by-trace-id/{traceId}") { | ||
val traceId: String? = call.parameters["traceId"] | ||
val partition: Int? = call.request.queryParameters["partition"]?.toIntOrNull() | ||
if (traceId == null || partition == null) { | ||
call.respond(HttpStatusCode.BadRequest, "Missing params") | ||
return@get | ||
} else { | ||
val topicPartitions = topics.map { topic -> TopicPartition(topic, partition) } | ||
val records = consumer().use { consumer -> | ||
consumer.assign(topicPartitions) | ||
consumer.seekToBeginning(topicPartitions) | ||
consumer.asSequence() | ||
.filter { record -> | ||
val traceparent = record.headers() | ||
.lastHeader("traceparent")?.value() | ||
?.toString(Charsets.UTF_8) | ||
traceparent?.contains(traceId) == true | ||
}.map { record -> record.timestamp() to (record.value() as GenericRecord) } | ||
.map { (timestamp, generic) -> | ||
listOfNotNull( | ||
"schema" to generic.schema.name, | ||
"timestamp" to Instant.ofEpochMilli(timestamp) | ||
.toString(), | ||
"id" to generic.get("id")?.toString(), | ||
"ref:periodeId" to generic.get("periodeId") | ||
?.toString(), | ||
"ref:opplysningerOmArbeidssokerId" to generic.get("opplysningerOmArbeidssokerId") | ||
?.toString(), | ||
).toMap() | ||
}.toList() | ||
} | ||
call.respond(records) | ||
} | ||
} | ||
} | ||
}.start(wait = true) | ||
} | ||
|
||
fun <K, V> Consumer<K, V>.asSequence(): Sequence<ConsumerRecord<K, V>> = | ||
generateSequence { | ||
this.poll(Duration.ofSeconds(2)) | ||
}.flatten() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
apiVersion: nais.io/v1alpha1 | ||
kind: Application | ||
metadata: | ||
name: ppaw-arbeidssokerregisteret-feilsoeking | ||
namespace: paw | ||
labels: | ||
team: paw | ||
spec: | ||
image: {{ image }} | ||
port: 8080 | ||
replicas: | ||
min: 1 | ||
max: 1 | ||
liveness: | ||
path: /isAlive | ||
initialDelay: 10 | ||
readiness: | ||
path: /isReady | ||
initialDelay: 10 | ||
kafka: | ||
pool: {{ kafka }} | ||
resources: | ||
limits: | ||
memory: 3048Mi | ||
requests: | ||
memory: 2048Mi | ||
azure: | ||
application: | ||
enabled: true | ||
tenant: nav.no | ||
claims: | ||
groups: | ||
- id: 88b552ab-2cd9-41e1-bd44-3868605d6f6a | ||
ingresses: | ||
- https://paw-arbeidssoekerregisteret-feilsoeking.intern.{{ domain }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters