Skip to content
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

Add Support for different Privacy Params for Single and Multiple Data Providers #1610

Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
dddb20e
Add support for different privacy params for single and multiple data…
tristanvuong2021 May 8, 2024
0e62695
lint fix
tristanvuong2021 May 8, 2024
b2ddd2f
lint fix
tristanvuong2021 May 8, 2024
4305447
lint fix
tristanvuong2021 May 8, 2024
f217331
lint fix
tristanvuong2021 May 8, 2024
954897c
undo code move
tristanvuong2021 May 8, 2024
0b44825
lint fix
tristanvuong2021 May 8, 2024
3f6850a
fix merge
tristanvuong2021 May 8, 2024
a665cce
lint fix
tristanvuong2021 May 8, 2024
7825e5c
add new message for frequency
tristanvuong2021 May 8, 2024
89d03c0
lint fix
tristanvuong2021 May 8, 2024
d73bbf8
Rename field and messages
tristanvuong2021 May 10, 2024
61430e9
lint fix
tristanvuong2021 May 10, 2024
ee7355f
lint fix
tristanvuong2021 May 10, 2024
d5b5977
Merge branch 'main' into tristanvuong-add-reporting-v2-privacy-params…
tristanvuong2021 May 10, 2024
6a72c66
fixes
tristanvuong2021 May 10, 2024
cf4e600
lint fix
tristanvuong2021 May 10, 2024
9125a15
Merge branch 'main' into tristanvuong-add-reporting-v2-privacy-params…
tristanvuong2021 May 10, 2024
4ecaec5
Add metric spec config validation
tristanvuong2021 May 13, 2024
2b750a2
lint fix
tristanvuong2021 May 13, 2024
ca586fc
Merge branch 'main' into tristanvuong-add-reporting-v2-privacy-params…
tristanvuong2021 May 13, 2024
b5c6430
Move data provider count into details
tristanvuong2021 May 16, 2024
8e10fca
lint fix
tristanvuong2021 May 17, 2024
746cb19
Merge branch 'main' into tristanvuong-add-reporting-v2-privacy-params…
tristanvuong2021 May 17, 2024
9a33c02
Merge branch 'main' into tristanvuong-add-reporting-v2-privacy-params…
tristanvuong2021 May 17, 2024
202eee2
Minor refactoring
tristanvuong2021 May 20, 2024
4a96fbd
lint fix
tristanvuong2021 May 20, 2024
06607c4
minor refactor
tristanvuong2021 May 20, 2024
3da115c
change how vid sampling interval is handled
tristanvuong2021 May 21, 2024
284521f
Remove optional from config
tristanvuong2021 May 21, 2024
91d1dbb
lint fix
tristanvuong2021 May 21, 2024
f9982c1
make vid sampling interval not required
tristanvuong2021 May 21, 2024
60a8e70
lint fix
tristanvuong2021 May 21, 2024
a6d7dee
Some changes
tristanvuong2021 May 21, 2024
e103761
Update comments
tristanvuong2021 May 22, 2024
f0cdb59
fixes
tristanvuong2021 May 23, 2024
eb3c7cc
Merge branch 'main' into tristanvuong-add-reporting-v2-privacy-params…
tristanvuong2021 May 24, 2024
09f56be
reformat reserved fields
tristanvuong2021 May 24, 2024
b665888
Merge branch 'main' into tristanvuong-add-reporting-v2-privacy-params…
tristanvuong2021 May 28, 2024
7c82d51
Merge branch 'main' into tristanvuong-add-reporting-v2-privacy-params…
tristanvuong2021 May 31, 2024
679d0a7
wrap around random number instead of -1
tristanvuong2021 Jun 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
reach_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 {
reach_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 @@ -26,7 +26,9 @@ import com.google.type.interval
import com.google.type.timeZone
import java.io.File
import java.nio.file.Paths
import java.security.SecureRandom
import java.time.LocalDate
import kotlin.random.asKotlinRandom
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
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,70 @@ 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.samplingAndPrivacyParams {
privacyParams = DP_PARAMS
vidSamplingInterval = VID_SAMPLING_INTERVAL
}
singleDataProviderParams =
MetricSpecKt.samplingAndPrivacyParams {
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 +1210,7 @@ abstract class InProcessLifeOfAReportIntegrationTest(
}
vidSamplingInterval = VID_SAMPLING_INTERVAL
}
.withDefaults(reportingServer.metricSpecConfig)
.withDefaults(reportingServer.metricSpecConfig, secureRandom)
}

val createdMetric =
Expand Down Expand Up @@ -1215,7 +1283,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 +1342,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 +1380,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 +1435,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 +1804,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
Loading
Loading