Add a research page, and keep the topics that views are rebuilt from

The mod sends the research state of a force (researched technologies,
levels, current research, progress and queue) whenever research changes,
and every minute for the progress. events-server-web keeps the latest state
and serves it at /kafkatorio/data/servers/{id}/research.

The web map has a research page (/servers/{id}/research, linked from the
header), with:
- progress, the current research and the queue
- the science packs needed for everything that's left
- every technology, filterable by status, science pack and name, with its
  cost (including levelled technologies' count formulas)
- details: the total cost to reach a technology, its prerequisites, what it
  leads to and what it unlocks

The technology tree comes from export_building_icons.py, which now also
exports technologies.json, items.json and technology/science pack icons.

Kafka deleted data older than 7 days, but the building, resource and
research views are rebuilt by reading their topics from the beginning, so
buildings disappeared after a restart. These topics are now kept forever.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Lazzexus 2026-11-03 10:46:09 +01:00
parent 4d02928081
commit e31971c58e
23 changed files with 1517 additions and 11 deletions

View file

@ -2,12 +2,17 @@ package dev.adamko.kafkatorio.processor.admin
import dev.adamko.kafkatorio.processor.config.ApplicationProperties
import dev.adamko.kafkatorio.processor.config.allTopics
import dev.adamko.kafkatorio.processor.config.retainedForeverTopics
import java.util.concurrent.TimeUnit
import mu.KotlinLogging
import org.apache.kafka.clients.admin.Admin
import org.apache.kafka.clients.admin.AlterConfigOp
import org.apache.kafka.clients.admin.ConfigEntry
import org.apache.kafka.clients.admin.CreateTopicsResult
import org.apache.kafka.clients.admin.NewTopic
import org.apache.kafka.clients.admin.TopicListing
import org.apache.kafka.common.config.ConfigResource
import org.apache.kafka.common.config.TopicConfig
class KafkatorioKafkaAdmin(
@ -49,6 +54,22 @@ class KafkatorioKafkaAdmin(
logger.info("Topic: $it")
}
}
retainTopicsForever()
}
/** Disable time-based deletion for [retainedForeverTopics] (including existing topics). */
private fun retainTopicsForever() {
val retainForever = AlterConfigOp(
ConfigEntry(TopicConfig.RETENTION_MS_CONFIG, "-1"),
AlterConfigOp.OpType.SET,
)
val configs = retainedForeverTopics.associate { topic ->
ConfigResource(ConfigResource.Type.TOPIC, topic) to listOf(retainForever)
}
kafkaAdmin.incrementalAlterConfigs(configs).all().get()
logger.info("Retaining topics forever: $retainedForeverTopics")
}
private fun Admin.createTopics(

View file

@ -11,6 +11,7 @@ import dev.adamko.kafkatorio.schema.packets.MapChunkResourceUpdate
import dev.adamko.kafkatorio.schema.packets.MapChunkTileUpdate
import dev.adamko.kafkatorio.schema.packets.PlayerUpdate
import dev.adamko.kafkatorio.schema.packets.PrototypesUpdate
import dev.adamko.kafkatorio.schema.packets.ResearchUpdate
import dev.adamko.kafkatorio.schema.packets.SurfaceUpdate
import kotlin.reflect.KClass
@ -75,6 +76,7 @@ val KafkatorioPacketData.topicName: String
is KafkatorioPacketDataError -> packetTopicNames.getValue(KafkatorioPacketDataError::class)
is MapChunkEntityUpdate -> packetTopicNames.getValue(MapChunkEntityUpdate::class)
is MapChunkResourceUpdate -> packetTopicNames.getValue(MapChunkResourceUpdate::class)
is ResearchUpdate -> packetTopicNames.getValue(ResearchUpdate::class)
}
@ -90,10 +92,23 @@ private val packetTopicNames: Map<KClass<out KafkatorioPacketData>, String> = ma
MapChunkEntityUpdate::class to "map-chunk-entity",
MapChunkResourceUpdate::class to "map-chunk-resource",
KafkatorioPacketDataError::class to "error",
ResearchUpdate::class to "research",
).mapValues { (_, v) ->
"$DOMAIN.packet.$v"
}
/**
* Topics that are read from the beginning to rebuild in-memory views (e.g. the buildings on the
* web map), so their data must never be deleted.
*/
val retainedForeverTopics: Set<String>
get() = setOf(
MapChunkEntityUpdate::class.topicName,
MapChunkResourceUpdate::class.topicName,
ResearchUpdate::class.topicName,
)
val KClass<out KafkatorioPacketData>.topicName: String
get() = packetTopicNames.getValue(this)