-
Notifications
You must be signed in to change notification settings - Fork 205
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
KVL-914 Add unit test and fix trace context propagation from config management service #9694
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
// Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.daml.platform.apiserver.services.admin | ||
|
||
import java.time.{Duration => jDuration} | ||
import java.util.concurrent.{CompletableFuture, CompletionStage} | ||
|
||
import akka.stream.scaladsl.Source | ||
import com.daml.api.util.TimeProvider | ||
import com.daml.ledger.api.domain | ||
import com.daml.ledger.api.domain.LedgerOffset.Absolute | ||
import com.daml.ledger.api.testing.utils.AkkaBeforeAndAfterAll | ||
import com.daml.ledger.api.v1.admin.config_management_service.{SetTimeModelRequest, TimeModel} | ||
import com.daml.ledger.participant.state.index.v2.IndexConfigManagementService | ||
import com.daml.ledger.participant.state.v1 | ||
import com.daml.ledger.participant.state.v1.{ | ||
Configuration, | ||
SubmissionId, | ||
SubmissionResult, | ||
WriteConfigService, | ||
} | ||
import com.daml.lf.data.{Ref, Time} | ||
import com.daml.logging.LoggingContext | ||
import com.daml.platform.configuration.LedgerConfiguration | ||
import com.daml.telemetry.{TelemetryContext, TelemetrySpecBase} | ||
import com.google.protobuf.duration.Duration | ||
import com.google.protobuf.timestamp.Timestamp | ||
import org.mockito.{ArgumentMatchersSugar, MockitoSugar} | ||
import org.scalatest.matchers.should.Matchers | ||
import org.scalatest.wordspec.AsyncWordSpec | ||
|
||
import scala.concurrent.Future | ||
|
||
class ApiConfigManagementServiceSpec | ||
extends AsyncWordSpec | ||
with TelemetrySpecBase | ||
with MockitoSugar | ||
with Matchers | ||
with ArgumentMatchersSugar | ||
with AkkaBeforeAndAfterAll { | ||
|
||
import ApiConfigManagementServiceSpec._ | ||
|
||
private implicit val loggingContext: LoggingContext = LoggingContext.ForTesting | ||
|
||
"ApiConfigManagementService" should { | ||
"propagate trace context" in { | ||
val mockReadBackend = mockIndexConfigManagementService() | ||
|
||
val apiConfigManagementService = ApiConfigManagementService.createApiService( | ||
mockReadBackend, | ||
TestWriteConfigService, | ||
TimeProvider.UTC, | ||
LedgerConfiguration.defaultLocalLedger, | ||
) | ||
|
||
val span = anEmptySpan() | ||
val scope = span.makeCurrent() | ||
apiConfigManagementService | ||
.setTimeModel(aSetTimeModelRequest) | ||
.andThen { case _ => | ||
scope.close() | ||
span.end() | ||
} | ||
.map { _ => | ||
spanExporter.finishedSpanAttributes should contain(anApplicationIdSpanAttribute) | ||
} | ||
} | ||
} | ||
|
||
private def mockIndexConfigManagementService() = { | ||
val mockIndexConfigManagementService = mock[IndexConfigManagementService] | ||
when(mockIndexConfigManagementService.lookupConfiguration()(any[LoggingContext])) | ||
.thenReturn(Future.successful(None)) | ||
when( | ||
mockIndexConfigManagementService.configurationEntries(any[Option[Absolute]])( | ||
any[LoggingContext] | ||
) | ||
).thenReturn(configurationEntries) | ||
mockIndexConfigManagementService | ||
} | ||
|
||
private object TestWriteConfigService extends WriteConfigService { | ||
override def submitConfiguration( | ||
maxRecordTime: Time.Timestamp, | ||
submissionId: SubmissionId, | ||
config: Configuration, | ||
)(implicit telemetryContext: TelemetryContext): CompletionStage[SubmissionResult] = { | ||
telemetryContext.setAttribute( | ||
anApplicationIdSpanAttribute._1, | ||
anApplicationIdSpanAttribute._2, | ||
) | ||
CompletableFuture.completedFuture(SubmissionResult.Acknowledged) | ||
} | ||
} | ||
} | ||
Comment on lines
+72
to
+97
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not hugely important but, since you already have a twin object, it looks like you could move these two definitions to it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sadly I can't because:
|
||
|
||
object ApiConfigManagementServiceSpec { | ||
private val aSubmissionId = "aSubmission" | ||
|
||
private val aConfigurationGeneration = 0L | ||
|
||
private val configurationEntries = Source.single( | ||
Absolute(Ref.LedgerString.assertFromString("0")) -> domain.ConfigurationEntry.Accepted( | ||
aSubmissionId, | ||
Configuration( | ||
aConfigurationGeneration, | ||
v1.TimeModel.reasonableDefault, | ||
jDuration.ZERO, | ||
), | ||
) | ||
) | ||
|
||
private val aSetTimeModelRequest = SetTimeModelRequest( | ||
aSubmissionId, | ||
Some(Timestamp.defaultInstance), | ||
aConfigurationGeneration, | ||
Some( | ||
TimeModel( | ||
Some(Duration.defaultInstance), | ||
Some(Duration.defaultInstance), | ||
Some(Duration.defaultInstance), | ||
) | ||
), | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ import com.daml.ledger.participant.state.kvutils.{Envelope, KeyValueSubmission} | |
import com.daml.ledger.participant.state.v1._ | ||
import com.daml.lf.data.{Ref, Time} | ||
import com.daml.metrics.Metrics | ||
import com.daml.telemetry.{NoOpTelemetryContext, TelemetryContext} | ||
import com.daml.telemetry.TelemetryContext | ||
|
||
import scala.compat.java8.FutureConverters | ||
|
||
|
@@ -64,7 +64,7 @@ class KeyValueParticipantStateWriter(writer: LedgerWriter, metrics: Metrics) ext | |
val submission = | ||
keyValueSubmission | ||
.configurationToSubmission(maxRecordTime, submissionId, writer.participantId, config) | ||
commit(submissionId, submission)(NoOpTelemetryContext) | ||
commit(submissionId, submission) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And is it still working after this change? 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will have to test it e2e from the oem integration kit 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it works, as we do not create any new spans and attributes between this place and next gRPC calls. |
||
} | ||
|
||
override def allocateParty( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the sake of curiosity: was this test working with the
NoOp
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
ApiConfigManagementService
usesDefaultTelemetry
by default, so hard to tell, TBH. ThesetAttribute
method wouldn't work in theNoOp
. Not sure if this answers your question.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or you're asking about the change from
KeyValueParticipantStateWriter
? Then yes, as this test doesn't go that far.