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: enabledFeatures on self-hosted instances & Sentry false positives #2787

Merged
merged 4 commits into from
Dec 18, 2024
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
@@ -1,5 +1,8 @@
package io.tolgee.hateoas.ee

import com.fasterxml.jackson.annotation.JsonGetter
import com.fasterxml.jackson.annotation.JsonIgnore
import com.fasterxml.jackson.annotation.JsonSetter
import io.tolgee.constants.Feature
import org.springframework.hateoas.RepresentationModel
import org.springframework.hateoas.server.core.Relation
Expand All @@ -10,10 +13,26 @@ open class SelfHostedEePlanModel(
val id: Long = 0,
var name: String = "",
val public: Boolean = true,
val enabledFeatures: Array<Feature> = arrayOf(),
@JsonIgnore
var enabledFeatures: Array<Feature> = arrayOf(),
val prices: PlanPricesModel,
val includedUsage: PlanIncludedUsageModel = PlanIncludedUsageModel(),
val hasYearlyPrice: Boolean = false,
val free: Boolean,
val nonCommercial: Boolean,
) : RepresentationModel<SelfHostedEePlanModel>()
) : RepresentationModel<SelfHostedEePlanModel>() {
/**
* We need to provide this setter so unrecognized features are ignored in situation
* that self-hosted instance is not upgraded to version containing the new features introduced
* in Tolgee cloud.
*/
@JsonSetter("enabledFeatures")
fun setJsonEnabledFeatures(features: Set<String>) {
this.enabledFeatures = features.mapNotNull { Feature.findByName(it) }.toTypedArray()
}

@JsonGetter("enabledFeatures")
fun getJsonEnabledFeatures(): Array<Feature> {
return this.enabledFeatures
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class SentryBeforeSendCallback : SentryOptions.BeforeSendCallback {
listOf(
"FailedDontRequeueException",
"ClientAbortException",
"AsyncRequestNotUsableException",
)
}

Expand Down
8 changes: 8 additions & 0 deletions backend/data/src/main/kotlin/io/tolgee/constants/Feature.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,12 @@ enum class Feature {
TASKS,
SSO,
ORDER_TRANSLATION,

;

companion object {
fun findByName(name: String): Feature? {
return entries.find { it.name == name }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,13 @@ class ApiKeyService(
}

private fun logTransactionIsolation() {
val isolationLevel =
entityManager.createNativeQuery("show transaction_isolation")
.singleResult as String
val message = "Transaction isolation level: $isolationLevel"
Sentry.addBreadcrumb(message)
if (logger.isDebugEnabled) {
val isolationLevel =
entityManager.createNativeQuery("show transaction_isolation")
.singleResult as String
logger.debug("Transaction isolation level: $isolationLevel")
logger.debug(message)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package io.tolgee.ee.unit

import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import io.tolgee.constants.Feature
import io.tolgee.hateoas.ee.PlanPricesModel
import io.tolgee.hateoas.ee.SelfHostedEePlanModel
import io.tolgee.testing.assert
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest

@SpringBootTest
class SelfHostedEePlanModelTest {
@Autowired
private lateinit var objectMapper: ObjectMapper

@Test
fun `parses plan response with unknown features`() {
val parsed =
objectMapper.readValue<SelfHostedEePlanModel>(
"""
{
"enabledFeatures": ["I've made this up", "ASSISTED_UPDATES"],
"prices": $pricesJson,
"free": false,
"nonCommercial": false
}
""".trimIndent(),
)

parsed.enabledFeatures.toList().assert.containsExactly(Feature.ASSISTED_UPDATES)
}

val pricesJson: String
get() {
return objectMapper.writeValueAsString(PlanPricesModel())
}
}
Loading