Skip to content

Commit

Permalink
Update EventGroup resource pattern in Reporting v2 API.
Browse files Browse the repository at this point in the history
  • Loading branch information
SanjayVas committed Jun 14, 2023
1 parent 7943b20 commit 697fce3
Show file tree
Hide file tree
Showing 15 changed files with 75 additions and 185 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ class ReportingSetReader(private val readContext: ReadContext) {
reportingSetInfo.cmmsEventGroupIdsSet.forEach {
eventGroupKeys +=
ReportingSetKt.PrimitiveKt.eventGroupKey {
cmmsMeasurementConsumerId = reportingSetInfo.cmmsMeasurementConsumerId
cmmsDataProviderId = it.cmmsDataProviderId
cmmsEventGroupId = it.cmmsEventGroupId
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,39 +19,30 @@ package org.wfanet.measurement.reporting.service.api.v2alpha
import org.wfanet.measurement.common.ResourceNameParser
import org.wfanet.measurement.common.api.ResourceKey

private val parser =
ResourceNameParser(
"measurementConsumers/{measurement_consumer}" +
"/dataProviders/{data_provider}/eventGroups/{event_group}"
)

/** [ResourceKey] of an EventGroup. */
class EventGroupKey(
val cmmsMeasurementConsumerId: String,
val cmmsDataProviderId: String,
val cmmsEventGroupId: String
) : ResourceKey {
class EventGroupKey(val cmmsMeasurementConsumerId: String, val cmmsEventGroupId: String) :
ResourceKey {
override fun toName(): String {
return parser.assembleName(
mapOf(
IdVariable.MEASUREMENT_CONSUMER to cmmsMeasurementConsumerId,
IdVariable.DATA_PROVIDER to cmmsDataProviderId,
IdVariable.EVENT_GROUP to cmmsEventGroupId
)
)
}

companion object FACTORY : ResourceKey.Factory<EventGroupKey> {
val defaultValue = EventGroupKey("", "", "")
private val parser =
ResourceNameParser("measurementConsumers/{measurement_consumer}/eventGroups/{event_group}")

val defaultValue = EventGroupKey("", "")

override fun fromName(resourceName: String): EventGroupKey? {
return parser.parseIdVars(resourceName)?.let {
EventGroupKey(
it.getValue(IdVariable.MEASUREMENT_CONSUMER),
it.getValue(IdVariable.DATA_PROVIDER),
it.getValue(IdVariable.EVENT_GROUP)
)
}
val idVars: Map<IdVariable, String> = parser.parseIdVars(resourceName) ?: return null
return EventGroupKey(
idVars.getValue(IdVariable.MEASUREMENT_CONSUMER),
idVars.getValue(IdVariable.EVENT_GROUP)
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -513,9 +513,8 @@ class MetricsService(
)

internalPrimitiveReportingSet.primitive.eventGroupKeysList.map { internalEventGroupKey ->
val eventGroupKey =
EventGroupKey(
internalEventGroupKey.cmmsMeasurementConsumerId,
val cmmsEventGroupKey =
CmmsEventGroupKey(
internalEventGroupKey.cmmsDataProviderId,
internalEventGroupKey.cmmsEventGroupId
)
Expand All @@ -524,14 +523,9 @@ class MetricsService(
.filter { !it.isNullOrBlank() }
val filter: String? = if (filtersList.isEmpty()) null else buildConjunction(filtersList)

eventGroupKey to
cmmsEventGroupKey to
RequisitionSpecKt.eventGroupEntry {
key =
CmmsEventGroupKey(
internalEventGroupKey.cmmsDataProviderId,
internalEventGroupKey.cmmsEventGroupId
)
.toName()
key = cmmsEventGroupKey.toName()
value =
RequisitionSpecKt.EventGroupEntryKt.value {
collectionInterval = measurement.timeInterval.toCmmsTimeInterval()
Expand All @@ -543,7 +537,7 @@ class MetricsService(
}
}
.groupBy(
{ (eventGroupKey, _) -> DataProviderKey(eventGroupKey.cmmsDataProviderId) },
{ (cmmsEventGroupKey, _) -> DataProviderKey(cmmsEventGroupKey.dataProviderId) },
{ (_, eventGroupEntry) -> eventGroupEntry }
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package org.wfanet.measurement.reporting.service.api.v2alpha

import com.google.protobuf.util.Timestamps
import org.wfanet.measurement.api.v2alpha.DifferentialPrivacyParams
import org.wfanet.measurement.api.v2alpha.EventGroupKey as CmmsEventGroupKey
import org.wfanet.measurement.api.v2alpha.Measurement
import org.wfanet.measurement.api.v2alpha.MeasurementConsumerKey
import org.wfanet.measurement.api.v2alpha.MeasurementSpec
Expand Down Expand Up @@ -544,14 +545,9 @@ fun InternalReportingSet.SetExpression.Operand.toOperand(
fun InternalReportingSet.Primitive.toPrimitive(): ReportingSet.Primitive {
val source = this
return ReportingSetKt.primitive {
eventGroups +=
cmmsEventGroups +=
source.eventGroupKeysList.map { eventGroupKey ->
EventGroupKey(
eventGroupKey.cmmsMeasurementConsumerId,
eventGroupKey.cmmsDataProviderId,
eventGroupKey.cmmsEventGroupId
)
.toName()
CmmsEventGroupKey(eventGroupKey.cmmsDataProviderId, eventGroupKey.cmmsEventGroupId).toName()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import io.grpc.Status
import io.grpc.StatusException
import kotlin.math.min
import kotlinx.coroutines.flow.toList
import org.wfanet.measurement.api.v2alpha.EventGroupKey as CmmsEventGroupKey
import org.wfanet.measurement.api.v2alpha.MeasurementConsumerKey
import org.wfanet.measurement.common.base64UrlDecode
import org.wfanet.measurement.common.base64UrlEncode
Expand Down Expand Up @@ -116,7 +117,7 @@ class ReportingSetsService(private val internalReportingSetsStub: ReportingSetsC
@Suppress("WHEN_ENUM_CAN_BE_NULL_IN_JAVA")
when (reportingSet.valueCase) {
ReportingSet.ValueCase.PRIMITIVE -> {
primitive = reportingSet.primitive.toInternal(cmmsMeasurementConsumerId)
primitive = reportingSet.primitive.toInternal()
}
ReportingSet.ValueCase.COMPOSITE -> {
grpcRequire(reportingSet.composite.hasExpression()) {
Expand Down Expand Up @@ -506,30 +507,22 @@ private fun ReportingSet.SetExpression.Operand.toInternal():
}

/** Converts a [ReportingSet.Primitive] to an [InternalReportingSet.Primitive]. */
private fun ReportingSet.Primitive.toInternal(
cmmsMeasurementConsumerId: String
): InternalReportingSet.Primitive {
private fun ReportingSet.Primitive.toInternal(): InternalReportingSet.Primitive {
val source = this

grpcRequire(source.eventGroupsList.isNotEmpty()) { "No event group specified." }
grpcRequire(source.cmmsEventGroupsList.isNotEmpty()) { "No event group specified." }

return InternalReportingSetKt.primitive {
eventGroupKeys +=
source.eventGroupsList.map { eventGroup ->
val eventGroupKey =
grpcRequireNotNull(EventGroupKey.fromName(eventGroup)) {
"Invalid event group name $eventGroup."
source.cmmsEventGroupsList.map { cmmsEventGroup ->
val cmmsEventGroupKey =
grpcRequireNotNull(CmmsEventGroupKey.fromName(cmmsEventGroup)) {
"Invalid event group name $cmmsEventGroup."
}
if (eventGroupKey.cmmsMeasurementConsumerId != cmmsMeasurementConsumerId) {
failGrpc(Status.PERMISSION_DENIED) {
"Event group [$eventGroup] doesn't belong to the caller."
}
}

InternalReportingSetKt.PrimitiveKt.eventGroupKey {
this.cmmsMeasurementConsumerId = eventGroupKey.cmmsMeasurementConsumerId
this.cmmsDataProviderId = eventGroupKey.cmmsDataProviderId
this.cmmsEventGroupId = eventGroupKey.cmmsEventGroupId
cmmsDataProviderId = cmmsEventGroupKey.dataProviderId
cmmsEventGroupId = cmmsEventGroupKey.eventGroupId
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1315,7 +1315,6 @@ abstract class MeasurementsServiceTest<T : MeasurementsGrpcKt.MeasurementsCorout
ReportingSetKt.primitive {
eventGroupKeys +=
ReportingSetKt.PrimitiveKt.eventGroupKey {
this.cmmsMeasurementConsumerId = cmmsMeasurementConsumerId
cmmsDataProviderId = "1235"
cmmsEventGroupId = cmmsMeasurementConsumerId + "123"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2266,7 +2266,6 @@ abstract class MetricsServiceTest<T : MetricsCoroutineImplBase> {
ReportingSetKt.primitive {
eventGroupKeys +=
ReportingSetKt.PrimitiveKt.eventGroupKey {
this.cmmsMeasurementConsumerId = cmmsMeasurementConsumerId
cmmsDataProviderId = "1235"
cmmsEventGroupId = cmmsMeasurementConsumerId + "123"
}
Expand Down
Loading

0 comments on commit 697fce3

Please sign in to comment.