From cd23432045cd73b513ead662a8187930026d0838 Mon Sep 17 00:00:00 2001 From: Sanjay Vasandani Date: Wed, 14 Jun 2023 11:01:32 -0700 Subject: [PATCH] Update EventGroup resource pattern in Reporting v2 API. --- .../v2/postgres/readers/ReportingSetReader.kt | 1 - .../service/api/v2alpha/EventGroupKey.kt | 33 ++++------- .../service/api/v2alpha/MetricsService.kt | 16 ++--- .../service/api/v2alpha/ProtoConversions.kt | 10 +--- .../api/v2alpha/ReportingSetsService.kt | 27 ++++----- .../testing/v2/MeasurementsServiceTest.kt | 1 - .../internal/testing/v2/MetricsServiceTest.kt | 1 - .../testing/v2/ReportingSetsServiceTest.kt | 31 ---------- .../internal/reporting/v2/reporting_set.proto | 6 +- .../reporting/v2alpha/event_group.proto | 26 ++++---- .../v2alpha/event_groups_service.proto | 6 +- .../reporting/v2alpha/reporting_set.proto | 7 +-- .../service/api/v2alpha/MetricsServiceTest.kt | 34 +++++------ .../api/v2alpha/ReportingSetsServiceTest.kt | 59 ++++--------------- .../service/api/v2alpha/ReportsServiceTest.kt | 4 +- 15 files changed, 77 insertions(+), 185 deletions(-) diff --git a/src/main/kotlin/org/wfanet/measurement/reporting/deploy/v2/postgres/readers/ReportingSetReader.kt b/src/main/kotlin/org/wfanet/measurement/reporting/deploy/v2/postgres/readers/ReportingSetReader.kt index 8a527729d67..0e1599f85d1 100644 --- a/src/main/kotlin/org/wfanet/measurement/reporting/deploy/v2/postgres/readers/ReportingSetReader.kt +++ b/src/main/kotlin/org/wfanet/measurement/reporting/deploy/v2/postgres/readers/ReportingSetReader.kt @@ -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 } diff --git a/src/main/kotlin/org/wfanet/measurement/reporting/service/api/v2alpha/EventGroupKey.kt b/src/main/kotlin/org/wfanet/measurement/reporting/service/api/v2alpha/EventGroupKey.kt index 85c1cdcbea2..ec685999c9c 100644 --- a/src/main/kotlin/org/wfanet/measurement/reporting/service/api/v2alpha/EventGroupKey.kt +++ b/src/main/kotlin/org/wfanet/measurement/reporting/service/api/v2alpha/EventGroupKey.kt @@ -19,39 +19,32 @@ 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 ) ) } + @Deprecated(message = "Broken") val cmmsDataProviderId: String = "" + companion object FACTORY : ResourceKey.Factory { - 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 = parser.parseIdVars(resourceName) ?: return null + return EventGroupKey( + idVars.getValue(IdVariable.MEASUREMENT_CONSUMER), + idVars.getValue(IdVariable.EVENT_GROUP) + ) } } } diff --git a/src/main/kotlin/org/wfanet/measurement/reporting/service/api/v2alpha/MetricsService.kt b/src/main/kotlin/org/wfanet/measurement/reporting/service/api/v2alpha/MetricsService.kt index b51891a74d9..181f907fd8a 100644 --- a/src/main/kotlin/org/wfanet/measurement/reporting/service/api/v2alpha/MetricsService.kt +++ b/src/main/kotlin/org/wfanet/measurement/reporting/service/api/v2alpha/MetricsService.kt @@ -513,9 +513,8 @@ class MetricsService( ) internalPrimitiveReportingSet.primitive.eventGroupKeysList.map { internalEventGroupKey -> - val eventGroupKey = - EventGroupKey( - internalEventGroupKey.cmmsMeasurementConsumerId, + val cmmsEventGroupKey = + CmmsEventGroupKey( internalEventGroupKey.cmmsDataProviderId, internalEventGroupKey.cmmsEventGroupId ) @@ -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() @@ -543,7 +537,7 @@ class MetricsService( } } .groupBy( - { (eventGroupKey, _) -> DataProviderKey(eventGroupKey.cmmsDataProviderId) }, + { (cmmsEventGroupKey, _) -> DataProviderKey(cmmsEventGroupKey.dataProviderId) }, { (_, eventGroupEntry) -> eventGroupEntry } ) } diff --git a/src/main/kotlin/org/wfanet/measurement/reporting/service/api/v2alpha/ProtoConversions.kt b/src/main/kotlin/org/wfanet/measurement/reporting/service/api/v2alpha/ProtoConversions.kt index 8192e6a16d5..22facbc4cb0 100644 --- a/src/main/kotlin/org/wfanet/measurement/reporting/service/api/v2alpha/ProtoConversions.kt +++ b/src/main/kotlin/org/wfanet/measurement/reporting/service/api/v2alpha/ProtoConversions.kt @@ -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 @@ -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() } } } diff --git a/src/main/kotlin/org/wfanet/measurement/reporting/service/api/v2alpha/ReportingSetsService.kt b/src/main/kotlin/org/wfanet/measurement/reporting/service/api/v2alpha/ReportingSetsService.kt index 85e9aa4d6d8..8c8d6deff75 100644 --- a/src/main/kotlin/org/wfanet/measurement/reporting/service/api/v2alpha/ReportingSetsService.kt +++ b/src/main/kotlin/org/wfanet/measurement/reporting/service/api/v2alpha/ReportingSetsService.kt @@ -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 @@ -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()) { @@ -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 } } } diff --git a/src/main/kotlin/org/wfanet/measurement/reporting/service/internal/testing/v2/MeasurementsServiceTest.kt b/src/main/kotlin/org/wfanet/measurement/reporting/service/internal/testing/v2/MeasurementsServiceTest.kt index a2a63f5722e..4e61e11fd98 100644 --- a/src/main/kotlin/org/wfanet/measurement/reporting/service/internal/testing/v2/MeasurementsServiceTest.kt +++ b/src/main/kotlin/org/wfanet/measurement/reporting/service/internal/testing/v2/MeasurementsServiceTest.kt @@ -1315,7 +1315,6 @@ abstract class MeasurementsServiceTest { ReportingSetKt.primitive { eventGroupKeys += ReportingSetKt.PrimitiveKt.eventGroupKey { - this.cmmsMeasurementConsumerId = cmmsMeasurementConsumerId cmmsDataProviderId = "1235" cmmsEventGroupId = cmmsMeasurementConsumerId + "123" } diff --git a/src/main/kotlin/org/wfanet/measurement/reporting/service/internal/testing/v2/ReportingSetsServiceTest.kt b/src/main/kotlin/org/wfanet/measurement/reporting/service/internal/testing/v2/ReportingSetsServiceTest.kt index 6a84fe6532c..b305521642c 100644 --- a/src/main/kotlin/org/wfanet/measurement/reporting/service/internal/testing/v2/ReportingSetsServiceTest.kt +++ b/src/main/kotlin/org/wfanet/measurement/reporting/service/internal/testing/v2/ReportingSetsServiceTest.kt @@ -83,14 +83,12 @@ abstract class ReportingSetsServiceTest { ReportingSetKt.primitive { eventGroupKeys += ReportingSetKt.PrimitiveKt.eventGroupKey { - cmmsMeasurementConsumerId = CMMS_MEASUREMENT_CONSUMER_ID cmmsDataProviderId = "1235" cmmsEventGroupId = "1236" } eventGroupKeys += ReportingSetKt.PrimitiveKt.eventGroupKey { - cmmsMeasurementConsumerId = CMMS_MEASUREMENT_CONSUMER_ID cmmsDataProviderId = "2235" cmmsEventGroupId = "2236" } @@ -128,21 +126,18 @@ abstract class ReportingSetsServiceTest { ReportingSetKt.primitive { eventGroupKeys += ReportingSetKt.PrimitiveKt.eventGroupKey { - cmmsMeasurementConsumerId = CMMS_MEASUREMENT_CONSUMER_ID cmmsDataProviderId = "1235" cmmsEventGroupId = "1236" } eventGroupKeys += ReportingSetKt.PrimitiveKt.eventGroupKey { - cmmsMeasurementConsumerId = CMMS_MEASUREMENT_CONSUMER_ID cmmsDataProviderId = "1235" cmmsEventGroupId = "1236" } eventGroupKeys += ReportingSetKt.PrimitiveKt.eventGroupKey { - cmmsMeasurementConsumerId = CMMS_MEASUREMENT_CONSUMER_ID cmmsDataProviderId = "2235" cmmsEventGroupId = "2236" } @@ -180,7 +175,6 @@ abstract class ReportingSetsServiceTest { ReportingSetKt.primitive { eventGroupKeys += ReportingSetKt.PrimitiveKt.eventGroupKey { - cmmsMeasurementConsumerId = CMMS_MEASUREMENT_CONSUMER_ID cmmsDataProviderId = "1235" cmmsEventGroupId = "1236" } @@ -196,7 +190,6 @@ abstract class ReportingSetsServiceTest { ReportingSetKt.primitive { eventGroupKeys += ReportingSetKt.PrimitiveKt.eventGroupKey { - cmmsMeasurementConsumerId = CMMS_MEASUREMENT_CONSUMER_ID cmmsDataProviderId = "1235" cmmsEventGroupId = "1236" } @@ -224,7 +217,6 @@ abstract class ReportingSetsServiceTest { ReportingSetKt.primitive { eventGroupKeys += ReportingSetKt.PrimitiveKt.eventGroupKey { - cmmsMeasurementConsumerId = CMMS_MEASUREMENT_CONSUMER_ID cmmsDataProviderId = "1235" cmmsEventGroupId = "1236" } @@ -321,7 +313,6 @@ abstract class ReportingSetsServiceTest { ReportingSetKt.primitive { eventGroupKeys += ReportingSetKt.PrimitiveKt.eventGroupKey { - cmmsMeasurementConsumerId = CMMS_MEASUREMENT_CONSUMER_ID cmmsDataProviderId = "1235" cmmsEventGroupId = "1236" } @@ -463,14 +454,12 @@ abstract class ReportingSetsServiceTest { ReportingSetKt.primitive { eventGroupKeys += ReportingSetKt.PrimitiveKt.eventGroupKey { - cmmsMeasurementConsumerId = CMMS_MEASUREMENT_CONSUMER_ID cmmsDataProviderId = "1235" cmmsEventGroupId = "1236" } eventGroupKeys += ReportingSetKt.PrimitiveKt.eventGroupKey { - cmmsMeasurementConsumerId = CMMS_MEASUREMENT_CONSUMER_ID cmmsDataProviderId = "2235" cmmsEventGroupId = "2236" } @@ -507,7 +496,6 @@ abstract class ReportingSetsServiceTest { ReportingSetKt.primitive { eventGroupKeys += ReportingSetKt.PrimitiveKt.eventGroupKey { - cmmsMeasurementConsumerId = CMMS_MEASUREMENT_CONSUMER_ID cmmsDataProviderId = "1235" cmmsEventGroupId = "1236" } @@ -616,7 +604,6 @@ abstract class ReportingSetsServiceTest { ReportingSetKt.primitive { eventGroupKeys += ReportingSetKt.PrimitiveKt.eventGroupKey { - cmmsMeasurementConsumerId = CMMS_MEASUREMENT_CONSUMER_ID cmmsDataProviderId = "1235" cmmsEventGroupId = "1236" } @@ -678,7 +665,6 @@ abstract class ReportingSetsServiceTest { ReportingSetKt.primitive { eventGroupKeys += ReportingSetKt.PrimitiveKt.eventGroupKey { - cmmsMeasurementConsumerId = CMMS_MEASUREMENT_CONSUMER_ID cmmsDataProviderId = "1235" cmmsEventGroupId = "1236" } @@ -824,14 +810,12 @@ abstract class ReportingSetsServiceTest { ReportingSetKt.primitive { eventGroupKeys += ReportingSetKt.PrimitiveKt.eventGroupKey { - cmmsMeasurementConsumerId = CMMS_MEASUREMENT_CONSUMER_ID cmmsDataProviderId = "1235" cmmsEventGroupId = "1236" } eventGroupKeys += ReportingSetKt.PrimitiveKt.eventGroupKey { - cmmsMeasurementConsumerId = CMMS_MEASUREMENT_CONSUMER_ID cmmsDataProviderId = "2235" cmmsEventGroupId = "2236" } @@ -883,7 +867,6 @@ abstract class ReportingSetsServiceTest { ReportingSetKt.primitive { eventGroupKeys += ReportingSetKt.PrimitiveKt.eventGroupKey { - cmmsMeasurementConsumerId = CMMS_MEASUREMENT_CONSUMER_ID cmmsDataProviderId = "1235" cmmsEventGroupId = "1236" } @@ -997,7 +980,6 @@ abstract class ReportingSetsServiceTest { ReportingSetKt.primitive { eventGroupKeys += ReportingSetKt.PrimitiveKt.eventGroupKey { - cmmsMeasurementConsumerId = CMMS_MEASUREMENT_CONSUMER_ID cmmsDataProviderId = "1235" cmmsEventGroupId = "1236" } @@ -1125,7 +1107,6 @@ abstract class ReportingSetsServiceTest { ReportingSetKt.primitive { eventGroupKeys += ReportingSetKt.PrimitiveKt.eventGroupKey { - cmmsMeasurementConsumerId = CMMS_MEASUREMENT_CONSUMER_ID cmmsDataProviderId = "1235" cmmsEventGroupId = "1236" } @@ -1201,7 +1182,6 @@ abstract class ReportingSetsServiceTest { ReportingSetKt.primitive { eventGroupKeys += ReportingSetKt.PrimitiveKt.eventGroupKey { - cmmsMeasurementConsumerId = CMMS_MEASUREMENT_CONSUMER_ID cmmsDataProviderId = "1235" cmmsEventGroupId = "1236" } @@ -1244,7 +1224,6 @@ abstract class ReportingSetsServiceTest { ReportingSetKt.primitive { eventGroupKeys += ReportingSetKt.PrimitiveKt.eventGroupKey { - cmmsMeasurementConsumerId = CMMS_MEASUREMENT_CONSUMER_ID cmmsDataProviderId = "1235" cmmsEventGroupId = "1236" } @@ -1307,7 +1286,6 @@ abstract class ReportingSetsServiceTest { ReportingSetKt.primitive { eventGroupKeys += ReportingSetKt.PrimitiveKt.eventGroupKey { - cmmsMeasurementConsumerId = CMMS_MEASUREMENT_CONSUMER_ID cmmsDataProviderId = "1235" cmmsEventGroupId = "1236" } @@ -1323,7 +1301,6 @@ abstract class ReportingSetsServiceTest { ReportingSetKt.primitive { eventGroupKeys += ReportingSetKt.PrimitiveKt.eventGroupKey { - cmmsMeasurementConsumerId = CMMS_MEASUREMENT_CONSUMER_ID cmmsDataProviderId = "1235" cmmsEventGroupId = "1237" } @@ -1378,14 +1355,12 @@ abstract class ReportingSetsServiceTest { ReportingSetKt.primitive { eventGroupKeys += ReportingSetKt.PrimitiveKt.eventGroupKey { - cmmsMeasurementConsumerId = CMMS_MEASUREMENT_CONSUMER_ID cmmsDataProviderId = "1235" cmmsEventGroupId = "1236" } eventGroupKeys += ReportingSetKt.PrimitiveKt.eventGroupKey { - cmmsMeasurementConsumerId = CMMS_MEASUREMENT_CONSUMER_ID cmmsDataProviderId = "2235" cmmsEventGroupId = "2236" } @@ -1401,14 +1376,12 @@ abstract class ReportingSetsServiceTest { ReportingSetKt.primitive { eventGroupKeys += ReportingSetKt.PrimitiveKt.eventGroupKey { - cmmsMeasurementConsumerId = CMMS_MEASUREMENT_CONSUMER_ID cmmsDataProviderId = "1235" cmmsEventGroupId = "1236" } eventGroupKeys += ReportingSetKt.PrimitiveKt.eventGroupKey { - cmmsMeasurementConsumerId = CMMS_MEASUREMENT_CONSUMER_ID cmmsDataProviderId = "2235" cmmsEventGroupId = "2236" } @@ -1486,14 +1459,12 @@ abstract class ReportingSetsServiceTest { ReportingSetKt.primitive { eventGroupKeys += ReportingSetKt.PrimitiveKt.eventGroupKey { - cmmsMeasurementConsumerId = CMMS_MEASUREMENT_CONSUMER_ID cmmsDataProviderId = "1235" cmmsEventGroupId = "1236" } eventGroupKeys += ReportingSetKt.PrimitiveKt.eventGroupKey { - cmmsMeasurementConsumerId = CMMS_MEASUREMENT_CONSUMER_ID cmmsDataProviderId = "2235" cmmsEventGroupId = "2236" } @@ -1509,14 +1480,12 @@ abstract class ReportingSetsServiceTest { ReportingSetKt.primitive { eventGroupKeys += ReportingSetKt.PrimitiveKt.eventGroupKey { - cmmsMeasurementConsumerId = CMMS_MEASUREMENT_CONSUMER_ID cmmsDataProviderId = "1235" cmmsEventGroupId = "1236" } eventGroupKeys += ReportingSetKt.PrimitiveKt.eventGroupKey { - cmmsMeasurementConsumerId = CMMS_MEASUREMENT_CONSUMER_ID cmmsDataProviderId = "2235" cmmsEventGroupId = "2236" } diff --git a/src/main/proto/wfa/measurement/internal/reporting/v2/reporting_set.proto b/src/main/proto/wfa/measurement/internal/reporting/v2/reporting_set.proto index 1f1436cca7d..f7c5f6057d9 100644 --- a/src/main/proto/wfa/measurement/internal/reporting/v2/reporting_set.proto +++ b/src/main/proto/wfa/measurement/internal/reporting/v2/reporting_set.proto @@ -30,12 +30,10 @@ message ReportingSet { message Primitive { message EventGroupKey { - // `MeasurementConsumer` ID from the CMMS public API. - string cmms_measurement_consumer_id = 1; // `DataProvider` ID from the CMMS public API. - string cmms_data_provider_id = 2; + string cmms_data_provider_id = 1; // `EventGroup` ID from the CMMS public API. - string cmms_event_group_id = 3; + string cmms_event_group_id = 2; } repeated EventGroupKey event_group_keys = 1; } diff --git a/src/main/proto/wfa/measurement/reporting/v2alpha/event_group.proto b/src/main/proto/wfa/measurement/reporting/v2alpha/event_group.proto index 36e8b0835b2..88fd811aa5d 100644 --- a/src/main/proto/wfa/measurement/reporting/v2alpha/event_group.proto +++ b/src/main/proto/wfa/measurement/reporting/v2alpha/event_group.proto @@ -29,25 +29,27 @@ option java_outer_classname = "EventGroupProto"; message EventGroup { option (google.api.resource) = { type: "reporting.halo-cmm.org/EventGroup" - pattern: "measurementConsumers/{measurement_consumer}/dataProviders/{data_provider}/eventGroups/{event_group}" + pattern: "measurementConsumers/{measurement_consumer}/eventGroups/{event_group}" }; // Resource name. string name = 1; - // Kingdom resource name of the `DataProvider` associated with this - // `EventGroup`. - string data_provider = 2 [ - (google.api.field_behavior) = IMMUTABLE, - (google.api.resource_reference).type = "halo.wfanet.org/DataProvider" + // Resource name of the corresponding `EventGroup` in the CMMS API. + string cmms_event_group = 2 [ + (google.api.resource_reference).type = "halo.wfanet.org/EventGroup", + (google.api.field_behavior) = OUTPUT_ONLY + ]; + + // Resource name of the parent `DataProvider` in the CMMS API. + string cmms_data_provider = 3 [ + (google.api.resource_reference).type = "halo.wfanet.org/DataProvider", + (google.api.field_behavior) = OUTPUT_ONLY ]; // ID referencing the `EventGroup` in an external system, provided by the // `DataProvider`. - // - // If set, this value must be unique among `EventGroup`s for the parent - // `DataProvider`. - string event_group_reference_id = 3; + string event_group_reference_id = 4; // The template that events associated with this `EventGroup` conform to. message EventTemplate { @@ -59,7 +61,7 @@ message EventGroup { } // The `EventTemplate`s that events associated with this `EventGroup` conform // to. - repeated EventTemplate event_templates = 4; + repeated EventTemplate event_templates = 5; // Wrapper for per-EDP Event Group metadata. message Metadata { @@ -73,5 +75,5 @@ message EventGroup { } // The metadata of the event group. - Metadata metadata = 5; + Metadata metadata = 6; } diff --git a/src/main/proto/wfa/measurement/reporting/v2alpha/event_groups_service.proto b/src/main/proto/wfa/measurement/reporting/v2alpha/event_groups_service.proto index 8369e544878..c8de9b661cf 100644 --- a/src/main/proto/wfa/measurement/reporting/v2alpha/event_groups_service.proto +++ b/src/main/proto/wfa/measurement/reporting/v2alpha/event_groups_service.proto @@ -41,11 +41,7 @@ service EventGroups { // Request message for `ListEventGroups` method. message ListEventGroupsRequest { - // Resource name of the parent `DataProvider` under a given - // `MeasurementConsumer`, in the form - // `measurementConsumers/{measurement_consumer}/dataProviders/{data_provider}`. - // The wildcard ID (`-`) may be used in place of the `DataProvider` ID to list - // across `DataProvider`s, in which case a filter should be specified. + // Resource name of the parent `MeasurementConsumer`. string parent = 1 [ (google.api.field_behavior) = REQUIRED, (google.api.resource_reference) = { diff --git a/src/main/proto/wfa/measurement/reporting/v2alpha/reporting_set.proto b/src/main/proto/wfa/measurement/reporting/v2alpha/reporting_set.proto index e32346900f4..39922caf051 100644 --- a/src/main/proto/wfa/measurement/reporting/v2alpha/reporting_set.proto +++ b/src/main/proto/wfa/measurement/reporting/v2alpha/reporting_set.proto @@ -44,10 +44,9 @@ message ReportingSet { // // It's the minimum building block of a set expression. message Primitive { - // Set of EventGroup resource names. - repeated string event_groups = 1 [ - (google.api.resource_reference).type = - "reporting.halo-cmm.org/EventGroup", + // Set of EventGroup resource names from the CMMS API. + repeated string cmms_event_groups = 1 [ + (google.api.resource_reference).type = "halo.wfanet.org/EventGroup", (google.api.field_behavior) = REQUIRED, (google.api.field_behavior) = IMMUTABLE ]; diff --git a/src/test/kotlin/org/wfanet/measurement/reporting/service/api/v2alpha/MetricsServiceTest.kt b/src/test/kotlin/org/wfanet/measurement/reporting/service/api/v2alpha/MetricsServiceTest.kt index 5573d774659..ff1267fe28c 100644 --- a/src/test/kotlin/org/wfanet/measurement/reporting/service/api/v2alpha/MetricsServiceTest.kt +++ b/src/test/kotlin/org/wfanet/measurement/reporting/service/api/v2alpha/MetricsServiceTest.kt @@ -406,14 +406,9 @@ private val DATA_PROVIDERS_LIST = DATA_PROVIDERS.values.toList() // Event group keys -private val EVENT_GROUP_KEYS = +private val CMMS_EVENT_GROUP_KEYS = DATA_PROVIDERS.keys.mapIndexed { index, dataProviderKey -> - val measurementConsumerKey = MEASUREMENT_CONSUMERS.keys.first() - EventGroupKey( - measurementConsumerKey.measurementConsumerId, - dataProviderKey.dataProviderId, - ExternalId(index + 660L).apiId.value - ) + CmmsEventGroupKey(dataProviderKey.dataProviderId, ExternalId(index + 660L).apiId.value) } // Event filters @@ -429,7 +424,9 @@ private val INTERNAL_UNION_ALL_REPORTING_SET = internalReportingSet { cmmsMeasurementConsumerId = MEASUREMENT_CONSUMERS.keys.first().measurementConsumerId externalReportingSetId = 220L this.primitive = - InternalReportingSetKt.primitive { eventGroupKeys += EVENT_GROUP_KEYS.map { it.toInternal() } } + InternalReportingSetKt.primitive { + eventGroupKeys += CMMS_EVENT_GROUP_KEYS.map { it.toInternal() } + } filter = PRIMITIVE_REPORTING_SET_FILTER displayName = "$cmmsMeasurementConsumerId-$externalReportingSetId-$filter" weightedSubsetUnions += weightedSubsetUnion { @@ -445,8 +442,8 @@ private val INTERNAL_UNION_ALL_BUT_LAST_PUBLISHER_REPORTING_SET = internalReport externalReportingSetId = INTERNAL_UNION_ALL_REPORTING_SET.externalReportingSetId + 1 this.primitive = InternalReportingSetKt.primitive { - (0 until EVENT_GROUP_KEYS.size - 1).map { i -> - eventGroupKeys += EVENT_GROUP_KEYS[i].toInternal() + (0 until CMMS_EVENT_GROUP_KEYS.size - 1).map { i -> + eventGroupKeys += CMMS_EVENT_GROUP_KEYS[i].toInternal() } } filter = PRIMITIVE_REPORTING_SET_FILTER @@ -468,9 +465,7 @@ private val INTERNAL_SINGLE_PUBLISHER_REPORTING_SET = internalReportingSet { eventGroupKeys += (0L until 3L) .map { index -> - val measurementConsumerKey = MEASUREMENT_CONSUMERS.keys.first() - EventGroupKey( - measurementConsumerKey.measurementConsumerId, + CmmsEventGroupKey( DATA_PROVIDERS.keys.first().dataProviderId, ExternalId(index + 670L).apiId.value ) @@ -547,11 +542,11 @@ private val TIME_INTERVAL = timeInterval { // Requisition specs private val REQUISITION_SPECS: Map = - EVENT_GROUP_KEYS.groupBy( - { DataProviderKey(it.cmmsDataProviderId) }, + CMMS_EVENT_GROUP_KEYS.groupBy( + { it.parentKey }, { RequisitionSpecKt.eventGroupEntry { - key = CmmsEventGroupKey(it.cmmsDataProviderId, it.cmmsEventGroupId).toName() + key = it.toName() value = RequisitionSpecKt.EventGroupEntryKt.value { collectionInterval = MEASUREMENT_TIME_INTERVAL @@ -4467,12 +4462,11 @@ private class RequestIdMatcher(private val expected: String) : } } -private fun EventGroupKey.toInternal(): InternalReportingSet.Primitive.EventGroupKey { +private fun CmmsEventGroupKey.toInternal(): InternalReportingSet.Primitive.EventGroupKey { val source = this return InternalReportingSetKt.PrimitiveKt.eventGroupKey { - cmmsMeasurementConsumerId = source.cmmsMeasurementConsumerId - cmmsDataProviderId = source.cmmsDataProviderId - cmmsEventGroupId = source.cmmsEventGroupId + cmmsDataProviderId = source.dataProviderId + cmmsEventGroupId = source.eventGroupId } } diff --git a/src/test/kotlin/org/wfanet/measurement/reporting/service/api/v2alpha/ReportingSetsServiceTest.kt b/src/test/kotlin/org/wfanet/measurement/reporting/service/api/v2alpha/ReportingSetsServiceTest.kt index 35e6aef50f3..ba2cbd6388e 100644 --- a/src/test/kotlin/org/wfanet/measurement/reporting/service/api/v2alpha/ReportingSetsServiceTest.kt +++ b/src/test/kotlin/org/wfanet/measurement/reporting/service/api/v2alpha/ReportingSetsServiceTest.kt @@ -30,6 +30,7 @@ import org.junit.runners.JUnit4 import org.mockito.kotlin.any import org.mockito.kotlin.whenever import org.wfanet.measurement.api.v2alpha.DataProviderKey +import org.wfanet.measurement.api.v2alpha.EventGroupKey as CmmsEventGroupKey import org.wfanet.measurement.api.v2alpha.MeasurementConsumerKey import org.wfanet.measurement.api.v2alpha.withDataProviderPrincipal import org.wfanet.measurement.common.base64UrlEncode @@ -76,14 +77,9 @@ private val DATA_PROVIDER_KEYS: List = (1L..3L).map { DataProviderKey(ExternalId(it + 220L).apiId.value) } // Event group IDs and names -private val EVENT_GROUP_KEYS = +private val CMMS_EVENT_GROUP_KEYS = DATA_PROVIDER_KEYS.mapIndexed { index, dataProviderKey -> - val measurementConsumerKey = MEASUREMENT_CONSUMER_KEYS.first() - EventGroupKey( - measurementConsumerKey.measurementConsumerId, - dataProviderKey.dataProviderId, - ExternalId(index + 330L).apiId.value - ) + CmmsEventGroupKey(dataProviderKey.dataProviderId, ExternalId(index + 330L).apiId.value) } // Internal reporting sets @@ -96,7 +92,7 @@ private val INTERNAL_PRIMITIVE_REPORTING_SETS: List = displayName = "primitive_reporting_set_display_name$it" primitive = InternalReportingSetKt.primitive { - eventGroupKeys += EVENT_GROUP_KEYS[it.toInt()].toInternal() + eventGroupKeys += CMMS_EVENT_GROUP_KEYS[it.toInt()].toInternal() } weightedSubsetUnions += InternalReportingSetKt.weightedSubsetUnion { @@ -225,9 +221,9 @@ private val PRIMITIVE_REPORTING_SETS: List = displayName = internalReportingSet.displayName primitive = ReportingSetKt.primitive { - eventGroups += - internalReportingSet.primitive.eventGroupKeysList.map { internalEventGroupKey -> - internalEventGroupKey.resourceName + cmmsEventGroups += + internalReportingSet.primitive.eventGroupKeysList.map { + CmmsEventGroupKey(it.cmmsDataProviderId, it.cmmsEventGroupId).toName() } } } @@ -749,7 +745,7 @@ class ReportingSetsServiceTest { reportingSet = PRIMITIVE_REPORTING_SETS.first().copy { clearName() - primitive = ReportingSetKt.primitive { eventGroups += invalidEventGroupName } + primitive = ReportingSetKt.primitive { cmmsEventGroups += invalidEventGroupName } } } val exception = @@ -762,33 +758,6 @@ class ReportingSetsServiceTest { assertThat(exception.status.description).contains(invalidEventGroupName) } - @Test - fun `createReportingSet throws PERMISSION_DENIED when EventGroup doesn't belong to the caller`() { - val notAccessibleEventGroupKey = - EventGroupKey( - MEASUREMENT_CONSUMER_KEYS.last().measurementConsumerId, - DATA_PROVIDER_KEYS.first().dataProviderId, - ExternalId(+300L).apiId.value - ) - val request = createReportingSetRequest { - parent = MEASUREMENT_CONSUMER_KEYS.first().toName() - reportingSet = - PRIMITIVE_REPORTING_SETS.first().copy { - clearName() - primitive = - ReportingSetKt.primitive { eventGroups += notAccessibleEventGroupKey.toName() } - } - } - val exception = - assertFailsWith { - withMeasurementConsumerPrincipal(MEASUREMENT_CONSUMER_KEYS.first().toName(), CONFIG) { - runBlocking { service.createReportingSet(request) } - } - } - assertThat(exception.status.code).isEqualTo(Status.Code.PERMISSION_DENIED) - assertThat(exception.status.description).contains(notAccessibleEventGroupKey.toName()) - } - @Test fun `listReportingSets returns without a next page token when there is no previous page token`() { val request = listReportingSetsRequest { parent = MEASUREMENT_CONSUMER_KEYS.first().toName() } @@ -1128,20 +1097,14 @@ class ReportingSetsServiceTest { } } -private fun EventGroupKey.toInternal(): InternalReportingSet.Primitive.EventGroupKey { +private fun CmmsEventGroupKey.toInternal(): InternalReportingSet.Primitive.EventGroupKey { val source = this return InternalReportingSetKt.PrimitiveKt.eventGroupKey { - cmmsMeasurementConsumerId = source.cmmsMeasurementConsumerId - cmmsDataProviderId = source.cmmsDataProviderId - cmmsEventGroupId = source.cmmsEventGroupId + cmmsDataProviderId = source.dataProviderId + cmmsEventGroupId = source.eventGroupId } } -private val InternalReportingSet.Primitive.EventGroupKey.resourceKey: EventGroupKey - get() = EventGroupKey(cmmsMeasurementConsumerId, cmmsDataProviderId, cmmsEventGroupId) -private val InternalReportingSet.Primitive.EventGroupKey.resourceName: String - get() = resourceKey.toName() - private val InternalReportingSet.resourceKey: ReportingSetKey get() = ReportingSetKey(cmmsMeasurementConsumerId, ExternalId(externalReportingSetId).apiId.value) private val InternalReportingSet.resourceName: String diff --git a/src/test/kotlin/org/wfanet/measurement/reporting/service/api/v2alpha/ReportsServiceTest.kt b/src/test/kotlin/org/wfanet/measurement/reporting/service/api/v2alpha/ReportsServiceTest.kt index 3d3d3ef5403..25984774066 100644 --- a/src/test/kotlin/org/wfanet/measurement/reporting/service/api/v2alpha/ReportsServiceTest.kt +++ b/src/test/kotlin/org/wfanet/measurement/reporting/service/api/v2alpha/ReportsServiceTest.kt @@ -2908,7 +2908,7 @@ class ReportsServiceTest { .toName() filter = "AGE>18" displayName = "reporting-set-$index-display-name" - primitive = ReportingSetKt.primitive { eventGroups += "event-group-$index" } + primitive = ReportingSetKt.primitive { cmmsEventGroups += "event-group-$index" } } } @@ -3279,8 +3279,6 @@ private val Metric.resourceKey: MetricKey get() = MetricKey.fromName(name)!! private val Metric.apiId: String get() = resourceKey.metricId -private val Metric.externalId: Long - get() = apiIdToExternalId(apiId) private val InternalReport.resourceKey: ReportKey get() = ReportKey(cmmsMeasurementConsumerId, ExternalId(externalReportId).apiId.value)