Skip to content

Commit

Permalink
Add support for different privacy params for single and multiple data…
Browse files Browse the repository at this point in the history
… providers
  • Loading branch information
tristanvuong2021 committed May 8, 2024
1 parent 652228f commit d08978a
Show file tree
Hide file tree
Showing 31 changed files with 8,053 additions and 5,078 deletions.
105 changes: 75 additions & 30 deletions src/main/k8s/testing/secretfiles/metric_spec_config.textproto
Original file line number Diff line number Diff line change
@@ -1,50 +1,95 @@
# proto-file: wfa/measurement/config/reporting/metric_spec_config.proto
# proto-message: MetricSpecConfig
reach_params {
privacy_params {
epsilon: 0.0041
delta: 1.0E-12
multiple_data_provider_params {
privacy_params {
epsilon: 0.0041
delta: 1.0E-12
}
vid_sampling_interval {
fixed_start {
start: 0.00
width: 0.01
}
}
}
single_data_provider_params {
privacy_params {
epsilon: 0.0041
delta: 1.0E-12
}
vid_sampling_interval {
fixed_start {
start: 0.00
width: 0.01
}
}
}
}
reach_and_frequency_params {
reach_privacy_params {
epsilon: 0.0033
delta: 1.0E-12
multiple_data_provider_params {
privacy_params {
epsilon: 0.0033
delta: 1.0E-12
}
frequency_privacy_params {
epsilon: 0.115
delta: 1.0E-12
}
vid_sampling_interval {
fixed_start {
start: 0.16
width: 0.016666668
}
}
}
frequency_privacy_params {
epsilon: 0.115
delta: 1.0E-12
single_data_provider_params {
privacy_params {
epsilon: 0.0033
delta: 1.0E-12
}
frequency_privacy_params {
epsilon: 0.115
delta: 1.0E-12
}
vid_sampling_interval {
fixed_start {
start: 0.16
width: 0.016666668
}
}
}
maximum_frequency: 10
}
impression_count_params {
privacy_params {
epsilon: 0.0011
delta: 1.0E-12
params {
privacy_params {
epsilon: 0.0011
delta: 1.0E-12
}
vid_sampling_interval {
fixed_start {
start: 0.47666666
width: 0.20666666
}
}
}
maximum_frequency_per_user: 60
}
watch_duration_params {
privacy_params {
epsilon: 0.001
delta: 1.0E-12
params {
privacy_params {
epsilon: 0.001
delta: 1.0E-12
}
vid_sampling_interval {
fixed_start {
start: 0.68333334
width: 0.31666666
}
}
}
maximum_watch_duration_per_user {
seconds: 4000
}
}
reach_vid_sampling_interval {
width: 0.01
}
reach_and_frequency_vid_sampling_interval {
start: 0.16
width: 0.016666668
}
impression_count_vid_sampling_interval {
start: 0.47666666
width: 0.20666666
}
watch_duration_vid_sampling_interval {
start: 0.68333334
width: 0.31666666
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ import org.wfanet.measurement.api.v2alpha.MeasurementKt
import org.wfanet.measurement.api.v2alpha.RequisitionSpecKt
import org.wfanet.measurement.api.v2alpha.batchGetEventGroupMetadataDescriptorsRequest
import org.wfanet.measurement.api.v2alpha.eventGroup as cmmsEventGroup
import java.security.SecureRandom
import kotlin.random.asKotlinRandom
import org.wfanet.measurement.api.v2alpha.event_templates.testing.Person
import org.wfanet.measurement.api.v2alpha.getDataProviderRequest
import org.wfanet.measurement.api.v2alpha.getMeasurementConsumerRequest
Expand Down Expand Up @@ -142,6 +144,8 @@ abstract class InProcessLifeOfAReportIntegrationTest(

abstract val internalReportingServerServices: InternalReportingServer.Services

private val secureRandom = SecureRandom().asKotlinRandom()

private val reportingServerRule =
object : TestRule {
lateinit var reportingServer: InProcessReportingServer
Expand Down Expand Up @@ -329,7 +333,7 @@ abstract class InProcessLifeOfAReportIntegrationTest(
reach = MetricSpecKt.reachParams { privacyParams = DP_PARAMS }
vidSamplingInterval = VID_SAMPLING_INTERVAL
}
.withDefaults(reportingServer.metricSpecConfig)
.withDefaults(reportingServer.metricSpecConfig, secureRandom)
}
metricCalculationSpecId = "fed"
}
Expand Down Expand Up @@ -453,7 +457,7 @@ abstract class InProcessLifeOfAReportIntegrationTest(
reach = MetricSpecKt.reachParams { privacyParams = DP_PARAMS }
vidSamplingInterval = VID_SAMPLING_INTERVAL
}
.withDefaults(reportingServer.metricSpecConfig)
.withDefaults(reportingServer.metricSpecConfig, secureRandom)
}
metricCalculationSpecId = "fed"
}
Expand Down Expand Up @@ -566,7 +570,7 @@ abstract class InProcessLifeOfAReportIntegrationTest(
reach = MetricSpecKt.reachParams { privacyParams = DP_PARAMS }
vidSamplingInterval = VID_SAMPLING_INTERVAL
}
.withDefaults(reportingServer.metricSpecConfig)
.withDefaults(reportingServer.metricSpecConfig, secureRandom)
}
metricCalculationSpecId = "fed"
}
Expand Down Expand Up @@ -645,7 +649,7 @@ abstract class InProcessLifeOfAReportIntegrationTest(
reach = MetricSpecKt.reachParams { privacyParams = DP_PARAMS }
vidSamplingInterval = VID_SAMPLING_INTERVAL
}
.withDefaults(reportingServer.metricSpecConfig)
.withDefaults(reportingServer.metricSpecConfig, secureRandom)
}
metricCalculationSpecId = "fed"
}
Expand Down Expand Up @@ -732,7 +736,7 @@ abstract class InProcessLifeOfAReportIntegrationTest(
reach = MetricSpecKt.reachParams { privacyParams = DP_PARAMS }
vidSamplingInterval = VID_SAMPLING_INTERVAL
}
.withDefaults(reportingServer.metricSpecConfig)
.withDefaults(reportingServer.metricSpecConfig, secureRandom)
}
metricCalculationSpecId = "fed"
}
Expand Down Expand Up @@ -811,7 +815,7 @@ abstract class InProcessLifeOfAReportIntegrationTest(
reach = MetricSpecKt.reachParams { privacyParams = DP_PARAMS }
vidSamplingInterval = VID_SAMPLING_INTERVAL
}
.withDefaults(reportingServer.metricSpecConfig)
.withDefaults(reportingServer.metricSpecConfig, secureRandom)
metricFrequencySpec =
MetricCalculationSpecKt.metricFrequencySpec {
daily = MetricCalculationSpec.MetricFrequencySpec.Daily.getDefaultInstance()
Expand Down Expand Up @@ -913,7 +917,7 @@ abstract class InProcessLifeOfAReportIntegrationTest(
reach = MetricSpecKt.reachParams { privacyParams = DP_PARAMS }
vidSamplingInterval = VID_SAMPLING_INTERVAL
}
.withDefaults(reportingServer.metricSpecConfig)
.withDefaults(reportingServer.metricSpecConfig, secureRandom)
groupings +=
MetricCalculationSpecKt.grouping {
predicates += grouping1Predicate1
Expand Down Expand Up @@ -1005,7 +1009,7 @@ abstract class InProcessLifeOfAReportIntegrationTest(
privacyParams = MetricSpecKt.differentialPrivacyParams {}
}
}
.withDefaults(reportingServer.metricSpecConfig)
.withDefaults(reportingServer.metricSpecConfig, secureRandom)
}
metricCalculationSpecId = "fed"
}
Expand Down Expand Up @@ -1088,7 +1092,7 @@ abstract class InProcessLifeOfAReportIntegrationTest(
reach = MetricSpecKt.reachParams { privacyParams = DP_PARAMS }
vidSamplingInterval = VID_SAMPLING_INTERVAL
}
.withDefaults(reportingServer.metricSpecConfig)
.withDefaults(reportingServer.metricSpecConfig, secureRandom)
}

val createdMetric =
Expand Down Expand Up @@ -1119,6 +1123,63 @@ abstract class InProcessLifeOfAReportIntegrationTest(
assertThat(actualResult).reachValue().isWithin(tolerance).of(expectedResult.reach.value)
}

@Test
fun `reach metric with single edp params result has the expected result`() = runBlocking {
val measurementConsumerData = inProcessCmmsComponents.getMeasurementConsumerData()
val eventGroups = listEventGroups()
val eventGroup = eventGroups.first()
val eventGroupEntries: List<Pair<EventGroup, String>> =
listOf(eventGroup to "person.age_group == ${Person.AgeGroup.YEARS_18_TO_34_VALUE}")
val createdPrimitiveReportingSet: ReportingSet =
createPrimitiveReportingSets(eventGroupEntries, measurementConsumerData.name).single()

val metric = metric {
reportingSet = createdPrimitiveReportingSet.name
timeInterval = EVENT_RANGE.toInterval()
metricSpec =
metricSpec {
reach = MetricSpecKt.reachParams {
multipleDataProviderParams = MetricSpecKt.params {
privacyParams = DP_PARAMS
vidSamplingInterval = VID_SAMPLING_INTERVAL
}
singleDataProviderParams = MetricSpecKt.params {
privacyParams = SINGLE_DATA_PROVIDER_DP_PARAMS
vidSamplingInterval = SINGLE_DATA_PROVIDER_VID_SAMPLING_INTERVAL
}
}
}
.withDefaults(reportingServer.metricSpecConfig, secureRandom)
}

val createdMetric =
publicMetricsClient
.withPrincipalName(measurementConsumerData.name)
.createMetric(
createMetricRequest {
parent = measurementConsumerData.name
this.metric = metric
metricId = "abc"
}
)

val retrievedMetric = pollForCompletedMetric(measurementConsumerData.name, createdMetric.name)
assertThat(retrievedMetric.state).isEqualTo(Metric.State.SUCCEEDED)

val eventGroupSpecs: Iterable<EventQuery.EventGroupSpec> =
eventGroupEntries.map { (eventGroup, filter) ->
buildEventGroupSpec(eventGroup, filter, EVENT_RANGE.toInterval())
}
val sampledVids = sampleVids(eventGroupSpecs, metric.metricSpec.reach.singleDataProviderParams.vidSamplingInterval)
val expectedResult = calculateExpectedReachMeasurementResult(sampledVids)

val reachResult = retrievedMetric.result.reach
val actualResult =
MeasurementKt.result { reach = MeasurementKt.ResultKt.reach { value = reachResult.value } }
val tolerance = computeErrorMargin(reachResult.univariateStatistics.standardDeviation)
assertThat(actualResult).reachValue().isWithin(tolerance).of(expectedResult.reach.value)
}

@Test
fun `reach-and-frequency metric has the expected result`() = runBlocking {
val measurementConsumerData = inProcessCmmsComponents.getMeasurementConsumerData()
Expand All @@ -1142,7 +1203,7 @@ abstract class InProcessLifeOfAReportIntegrationTest(
}
vidSamplingInterval = VID_SAMPLING_INTERVAL
}
.withDefaults(reportingServer.metricSpecConfig)
.withDefaults(reportingServer.metricSpecConfig, secureRandom)
}

val createdMetric =
Expand Down Expand Up @@ -1215,7 +1276,7 @@ abstract class InProcessLifeOfAReportIntegrationTest(
impressionCount = MetricSpecKt.impressionCountParams { privacyParams = DP_PARAMS }
vidSamplingInterval = VID_SAMPLING_INTERVAL
}
.withDefaults(reportingServer.metricSpecConfig)
.withDefaults(reportingServer.metricSpecConfig, secureRandom)
}

val createdMetric =
Expand Down Expand Up @@ -1274,7 +1335,7 @@ abstract class InProcessLifeOfAReportIntegrationTest(
watchDuration = MetricSpecKt.watchDurationParams { privacyParams = DP_PARAMS }
vidSamplingInterval = VID_SAMPLING_INTERVAL
}
.withDefaults(reportingServer.metricSpecConfig)
.withDefaults(reportingServer.metricSpecConfig, secureRandom)
}

val createdMetric =
Expand Down Expand Up @@ -1312,7 +1373,7 @@ abstract class InProcessLifeOfAReportIntegrationTest(
reach = MetricSpecKt.reachParams { privacyParams = DP_PARAMS }
vidSamplingInterval = VID_SAMPLING_INTERVAL
}
.withDefaults(reportingServer.metricSpecConfig)
.withDefaults(reportingServer.metricSpecConfig, secureRandom)
filters += "person.gender == ${Person.Gender.MALE_VALUE}"
}

Expand Down Expand Up @@ -1367,7 +1428,7 @@ abstract class InProcessLifeOfAReportIntegrationTest(
reach =
MetricSpecKt.reachParams { privacyParams = MetricSpecKt.differentialPrivacyParams {} }
}
.withDefaults(reportingServer.metricSpecConfig)
.withDefaults(reportingServer.metricSpecConfig, secureRandom)
}

val deferred: MutableList<Deferred<Metric>> = mutableListOf()
Expand Down Expand Up @@ -1736,12 +1797,24 @@ abstract class InProcessLifeOfAReportIntegrationTest(
delta = 1e-15
}

private val SINGLE_DATA_PROVIDER_DP_PARAMS =
MetricSpecKt.differentialPrivacyParams {
epsilon = 1.0
delta = 1.01e-15
}

private val VID_SAMPLING_INTERVAL =
MetricSpecKt.vidSamplingInterval {
start = 0.0f
width = 1.0f
}

private val SINGLE_DATA_PROVIDER_VID_SAMPLING_INTERVAL =
MetricSpecKt.vidSamplingInterval {
start = 0.0f
width = 0.9f
}

// For a 99.9% Confidence Interval.
private const val CONFIDENCE_INTERVAL_MULTIPLIER = 3.291

Expand Down

0 comments on commit d08978a

Please sign in to comment.