-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1653 from CreditMutuelArkea/feature/langfuse/develop
Observability integration for Gen AI orchestrator
- Loading branch information
Showing
86 changed files
with
3,342 additions
and
1,024 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
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
59 changes: 59 additions & 0 deletions
59
bot/admin/server/src/main/kotlin/model/BotObservabilityConfigurationDTO.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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright (C) 2017/2021 e-voyageurs technologies | ||
* | ||
* 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 ai.tock.bot.admin.model | ||
|
||
|
||
import ai.tock.bot.admin.bot.observability.BotObservabilityConfiguration | ||
import ai.tock.genai.orchestratorcore.mappers.ObservabilitySettingMapper | ||
import ai.tock.genai.orchestratorcore.models.Constants | ||
import ai.tock.genai.orchestratorcore.models.observability.ObservabilitySettingDTO | ||
import ai.tock.genai.orchestratorcore.utils.SecurityUtils | ||
import org.litote.kmongo.newId | ||
import org.litote.kmongo.toId | ||
|
||
data class BotObservabilityConfigurationDTO( | ||
val id: String? = null, | ||
val namespace: String, | ||
val botId: String, | ||
val enabled: Boolean = false, | ||
val setting: ObservabilitySettingDTO, | ||
) { | ||
constructor(configuration: BotObservabilityConfiguration) : this( | ||
configuration._id.toString(), | ||
configuration.namespace, | ||
configuration.botId, | ||
configuration.enabled, | ||
ObservabilitySettingMapper.toDTO(configuration.setting), | ||
) | ||
|
||
fun toBotObservabilityConfiguration(): BotObservabilityConfiguration = | ||
BotObservabilityConfiguration( | ||
id?.toId() ?: newId(), | ||
namespace, | ||
botId, | ||
enabled, | ||
ObservabilitySettingMapper.toEntity( | ||
setting, | ||
SecurityUtils.generateAwsSecretName( | ||
namespace, botId, Constants.GEN_AI_OBSERVABILITY | ||
) | ||
), | ||
) | ||
} | ||
|
||
|
||
|
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
94 changes: 94 additions & 0 deletions
94
bot/admin/server/src/main/kotlin/service/ObservabilityService.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 |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* Copyright (C) 2017/2021 e-voyageurs technologies | ||
* | ||
* 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 ai.tock.bot.admin.service | ||
|
||
import ai.tock.bot.admin.BotAdminService | ||
import ai.tock.bot.admin.bot.observability.BotObservabilityConfiguration | ||
import ai.tock.bot.admin.bot.observability.BotObservabilityConfigurationDAO | ||
import ai.tock.bot.admin.model.BotObservabilityConfigurationDTO | ||
import ai.tock.shared.exception.rest.BadRequestException | ||
import ai.tock.shared.injector | ||
import ai.tock.shared.provide | ||
import ai.tock.shared.vertx.WebVerticle | ||
import com.mongodb.MongoWriteException | ||
import mu.KLogger | ||
import mu.KotlinLogging | ||
|
||
/** | ||
* Service that manage the observability functionality | ||
*/ | ||
object ObservabilityService { | ||
|
||
private val logger: KLogger = KotlinLogging.logger {} | ||
private val observabilityConfigurationDAO: BotObservabilityConfigurationDAO get() = injector.provide() | ||
/** | ||
* Get the Observability configuration | ||
*/ | ||
fun getObservabilityConfiguration(namespace: String, botId: String): BotObservabilityConfiguration? { | ||
return observabilityConfigurationDAO.findByNamespaceAndBotId(namespace, botId) | ||
} | ||
|
||
/** | ||
* Get the Observability configuration | ||
* @param namespace: the namespace | ||
* @param botId: the botId | ||
* @param enabled: the observability activation (enabled or not) | ||
*/ | ||
fun getObservabilityConfiguration(namespace: String, botId: String, enabled: Boolean): BotObservabilityConfiguration? { | ||
return observabilityConfigurationDAO.findByNamespaceAndBotIdAndEnabled(namespace, botId, enabled) | ||
} | ||
|
||
/** | ||
* Save Observability configuration and filter errors | ||
* @param observabilityConfig : the observability configuration to create or update | ||
* @throws [BadRequestException] if the observability configuration is invalid | ||
* @return [BotObservabilityConfiguration] | ||
*/ | ||
fun saveObservability( | ||
observabilityConfig: BotObservabilityConfigurationDTO | ||
): BotObservabilityConfiguration { | ||
BotAdminService.getBotConfigurationsByNamespaceAndBotId(observabilityConfig.namespace, observabilityConfig.botId).firstOrNull() | ||
?: WebVerticle.badRequest("No bot configuration is defined yet [namespace: ${observabilityConfig.namespace}, botId = ${observabilityConfig.botId}]") | ||
return saveObservabilityConfiguration(observabilityConfig) | ||
} | ||
|
||
/** | ||
* Save the Observability configuration | ||
* @param observabilityConfiguration [BotObservabilityConfigurationDTO] | ||
*/ | ||
private fun saveObservabilityConfiguration( | ||
observabilityConfiguration: BotObservabilityConfigurationDTO | ||
): BotObservabilityConfiguration { | ||
val observabilityConfig = observabilityConfiguration.toBotObservabilityConfiguration() | ||
|
||
// Check validity of the observability configuration | ||
ObservabilityValidationService.validate(observabilityConfig).let { errors -> | ||
if (errors.isNotEmpty()) { | ||
throw BadRequestException(errors) | ||
} | ||
} | ||
|
||
return try { | ||
observabilityConfigurationDAO.save(observabilityConfig) | ||
} catch (e: MongoWriteException) { | ||
throw BadRequestException(e.message ?: "Observability Configuration: registration failed on mongo ") | ||
} catch (e: Exception) { | ||
throw BadRequestException(e.message ?: "Observability Configuration: registration failed ") | ||
} | ||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
bot/admin/server/src/main/kotlin/service/ObservabilityValidationService.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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright (C) 2017/2021 e-voyageurs technologies | ||
* | ||
* 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 ai.tock.bot.admin.service | ||
|
||
import ai.tock.bot.admin.bot.observability.BotObservabilityConfiguration | ||
import ai.tock.genai.orchestratorclient.requests.ObservabilityProviderSettingStatusQuery | ||
import ai.tock.genai.orchestratorclient.responses.ProviderSettingStatusResponse | ||
import ai.tock.genai.orchestratorclient.services.ObservabilityProviderService | ||
import ai.tock.shared.exception.error.ErrorMessage | ||
import ai.tock.shared.injector | ||
import ai.tock.shared.provide | ||
|
||
|
||
object ObservabilityValidationService { | ||
|
||
private val observabilityProviderService: ObservabilityProviderService get() = injector.provide() | ||
|
||
fun validate(ragConfig: BotObservabilityConfiguration): Set<ErrorMessage> { | ||
return mutableSetOf<ErrorMessage>().apply { | ||
addAll( | ||
observabilityProviderService | ||
.checkSetting(ObservabilityProviderSettingStatusQuery(ragConfig.setting)) | ||
.getErrors("Observability setting check failed") | ||
) | ||
} | ||
} | ||
|
||
private fun ProviderSettingStatusResponse?.getErrors(message: String): Set<ErrorMessage> = | ||
this?.errors?.map { ErrorMessage(message = message, params = errors) }?.toSet() ?: emptySet() | ||
|
||
} |
Oops, something went wrong.