Skip to content

Commit

Permalink
Add createReportingSet. (#985)
Browse files Browse the repository at this point in the history
Add createReportingSet for v2alpha reporting server.
  • Loading branch information
riemanli authored May 15, 2023
1 parent 3a078df commit 48e7363
Show file tree
Hide file tree
Showing 9 changed files with 1,427 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class ReportingSetReader(private val readContext: ReadContext) {
if (reportingSetInfo.displayName != null) {
displayName = reportingSetInfo.displayName
}
if (reportingSetInfo.filter != null) {
if (!reportingSetInfo.filter.isNullOrBlank()) {
filter = reportingSetInfo.filter
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ kt_jvm_library(
"//src/main/proto/wfa/measurement/internal/reporting/v2:reporting_sets_service_kt_jvm_grpc_proto",
"//src/main/proto/wfa/measurement/reporting/v2alpha:metrics_service_kt_jvm_grpc_proto",
"//src/main/proto/wfa/measurement/reporting/v2alpha:page_token_kt_jvm_proto",
"//src/main/proto/wfa/measurement/reporting/v2alpha:reporting_sets_service_kt_jvm_grpc_proto",
"@wfa_common_jvm//imports/java/com/google/protobuf/util",
"@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/common",
"@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/common/identity",
Expand Down Expand Up @@ -104,6 +105,7 @@ kt_jvm_library(
"//src/main/proto/wfa/measurement/internal/reporting/v2:reporting_sets_service_kt_jvm_grpc_proto",
"//src/main/proto/wfa/measurement/reporting/v2alpha:metrics_service_kt_jvm_grpc_proto",
"//src/main/proto/wfa/measurement/reporting/v2alpha:page_token_kt_jvm_proto",
"//src/main/proto/wfa/measurement/reporting/v2alpha:reporting_sets_service_kt_jvm_grpc_proto",
"@wfa_common_jvm//imports/java/com/google/protobuf/util",
"@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/common",
"@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/common/crypto:security_provider",
Expand All @@ -121,3 +123,22 @@ kt_jvm_library(
"@wfa_common_jvm//imports/kotlin/kotlinx/coroutines:core",
],
)

kt_jvm_library(
name = "reporting_sets_service",
srcs = ["ReportingSetsService.kt"],
deps = [
"//src/main/kotlin/org/wfanet/measurement/api:public_api_version",
"//src/main/kotlin/org/wfanet/measurement/reporting/service/api/v2alpha:principal_server_interceptor",
"//src/main/kotlin/org/wfanet/measurement/reporting/service/api/v2alpha:proto_conversions",
"//src/main/kotlin/org/wfanet/measurement/reporting/service/api/v2alpha:reporting_principal",
"//src/main/kotlin/org/wfanet/measurement/reporting/service/api/v2alpha:resource_key",
"//src/main/kotlin/org/wfanet/measurement/reporting/service/api/v2alpha:set_expression_compiler",
"//src/main/proto/wfa/measurement/internal/reporting/v2:reporting_sets_service_kt_jvm_grpc_proto",
"//src/main/proto/wfa/measurement/reporting/v2alpha:page_token_kt_jvm_proto",
"//src/main/proto/wfa/measurement/reporting/v2alpha:reporting_sets_service_kt_jvm_grpc_proto",
"@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/common",
"@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/common/grpc",
"@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/common/identity",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ import org.wfanet.measurement.api.v2alpha.MeasurementSpecKt
import org.wfanet.measurement.api.v2alpha.TimeInterval as CmmsTimeInterval
import org.wfanet.measurement.api.v2alpha.differentialPrivacyParams
import org.wfanet.measurement.api.v2alpha.timeInterval as cmmsTimeInterval
import org.wfanet.measurement.common.identity.externalIdToApiId
import org.wfanet.measurement.config.reporting.MetricSpecConfig
import org.wfanet.measurement.internal.reporting.v2.Measurement as InternalMeasurement
import org.wfanet.measurement.internal.reporting.v2.MeasurementKt as InternalMeasurementKt
import org.wfanet.measurement.internal.reporting.v2.MetricSpec as InternalMetricSpec
import org.wfanet.measurement.internal.reporting.v2.MetricSpecKt as InternalMetricSpecKt
import org.wfanet.measurement.internal.reporting.v2.ReportingSet as InternalReportingSet
import org.wfanet.measurement.internal.reporting.v2.StreamMetricsRequest
import org.wfanet.measurement.internal.reporting.v2.StreamMetricsRequestKt
import org.wfanet.measurement.internal.reporting.v2.TimeInterval as InternalTimeInterval
Expand All @@ -37,8 +39,11 @@ import org.wfanet.measurement.internal.reporting.v2.timeInterval as internalTime
import org.wfanet.measurement.reporting.v2alpha.ListMetricsPageToken
import org.wfanet.measurement.reporting.v2alpha.MetricSpec
import org.wfanet.measurement.reporting.v2alpha.MetricSpecKt
import org.wfanet.measurement.reporting.v2alpha.ReportingSet
import org.wfanet.measurement.reporting.v2alpha.ReportingSetKt
import org.wfanet.measurement.reporting.v2alpha.TimeInterval
import org.wfanet.measurement.reporting.v2alpha.metricSpec
import org.wfanet.measurement.reporting.v2alpha.reportingSet
import org.wfanet.measurement.reporting.v2alpha.timeInterval

/**
Expand Down Expand Up @@ -261,3 +266,126 @@ fun ListMetricsPageToken.toStreamMetricsRequest(): StreamMetricsRequest {
}
}
}

/** Converts an [InternalReportingSet] to a public [ReportingSet]. */
fun InternalReportingSet.toReportingSet(): ReportingSet {
val source = this
return reportingSet {
name =
ReportingSetKey(
cmmsMeasurementConsumerId = source.cmmsMeasurementConsumerId,
reportingSetId = externalIdToApiId(source.externalReportingSetId)
)
.toName()

displayName = source.displayName
filter = source.filter

@Suppress("WHEN_ENUM_CAN_BE_NULL_IN_JAVA")
when (source.valueCase) {
InternalReportingSet.ValueCase.PRIMITIVE -> {
primitive = source.primitive.toPrimitive()
}
InternalReportingSet.ValueCase.COMPOSITE -> {
composite =
ReportingSetKt.composite {
expression = source.composite.toExpression(source.cmmsMeasurementConsumerId)
}
}
InternalReportingSet.ValueCase.VALUE_NOT_SET -> {
error { "ReportingSet [$name] value should've been set." }
}
}
}
}

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

return ReportingSetKt.setExpression {
@Suppress("WHEN_ENUM_CAN_BE_NULL_IN_JAVA")
operation =
when (source.operation) {
InternalReportingSet.SetExpression.Operation.UNION -> {
ReportingSet.SetExpression.Operation.UNION
}
InternalReportingSet.SetExpression.Operation.DIFFERENCE -> {
ReportingSet.SetExpression.Operation.DIFFERENCE
}
InternalReportingSet.SetExpression.Operation.INTERSECTION -> {
ReportingSet.SetExpression.Operation.INTERSECTION
}
InternalReportingSet.SetExpression.Operation.OPERATION_UNSPECIFIED -> {
error { "Set expression operation type should've been set." }
}
InternalReportingSet.SetExpression.Operation.UNRECOGNIZED -> {
error { "Unrecognized set expression operation type." }
}
}

// Only set the operand when it has a type.
if (
source.lhs.operandCase !=
InternalReportingSet.SetExpression.Operand.OperandCase.OPERAND_NOT_SET
) {
lhs = source.lhs.toOperand(cmmsMeasurementConsumerId)
} else {
error("Operand type in lhs of set expression should've been set.")
}
if (
source.rhs.operandCase !=
InternalReportingSet.SetExpression.Operand.OperandCase.OPERAND_NOT_SET
) {
rhs = source.rhs.toOperand(cmmsMeasurementConsumerId)
}
}
}

/**
* Converts an [InternalReportingSet.SetExpression.Operand] to a
* [ReportingSet.SetExpression.Operand].
*/
fun InternalReportingSet.SetExpression.Operand.toOperand(
cmmsMeasurementConsumerId: String
): ReportingSet.SetExpression.Operand {
val source = this

return ReportingSetKt.SetExpressionKt.operand {
@Suppress("WHEN_ENUM_CAN_BE_NULL_IN_JAVA")
when (source.operandCase) {
InternalReportingSet.SetExpression.Operand.OperandCase.EXTERNAL_REPORTING_SET_ID -> {
val reportingSetKey =
ReportingSetKey(
cmmsMeasurementConsumerId,
externalIdToApiId(source.externalReportingSetId)
)
reportingSet = reportingSetKey.toName()
}
InternalReportingSet.SetExpression.Operand.OperandCase.EXPRESSION -> {
expression = source.expression.toExpression(cmmsMeasurementConsumerId)
}
InternalReportingSet.SetExpression.Operand.OperandCase.OPERAND_NOT_SET -> {
error("Unset operand type in set expression shouldn't reach this code.")
}
}
}
}

/** Converts an [InternalReportingSet.Primitive] to a [ReportingSet.Primitive]. */
fun InternalReportingSet.Primitive.toPrimitive(): ReportingSet.Primitive {
val source = this
return ReportingSetKt.primitive {
eventGroups +=
source.eventGroupKeysList.map { eventGroupKey ->
EventGroupKey(
eventGroupKey.cmmsMeasurementConsumerId,
eventGroupKey.cmmsDataProviderId,
eventGroupKey.cmmsEventGroupId
)
.toName()
}
}
}
Loading

0 comments on commit 48e7363

Please sign in to comment.