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 option to defer ping lifetime metric persistence #530

Merged
merged 1 commit into from
Dec 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ open class GleanInternalAPI internal constructor () {
dataDir = this.gleanDataDir.path,
packageName = applicationContext.packageName,
uploadEnabled = uploadEnabled,
maxEvents = this.configuration.maxEvents
maxEvents = this.configuration.maxEvents,
delayPingLifetimeIO = false
)

// Start the migration from glean-ac, if needed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ import mozilla.telemetry.glean.net.PingUploader
* **CAUTION**: This must match _exactly_ the definition on the Rust side.
* If this side is changed, the Rust side need to be changed, too.
*/
@Structure.FieldOrder("dataDir", "packageName", "uploadEnabled", "maxEvents")
@Structure.FieldOrder("dataDir", "packageName", "uploadEnabled", "maxEvents", "delayPingLifetimeIO")
internal class FfiConfiguration(
dataDir: String,
packageName: String,
uploadEnabled: Boolean,
maxEvents: Int? = null
maxEvents: Int? = null,
delayPingLifetimeIO: Boolean
) : Structure() {
/**
* Expose all structure fields as actual fields,
Expand All @@ -37,6 +38,8 @@ internal class FfiConfiguration(
public var uploadEnabled: Byte = uploadEnabled.toByte()
@JvmField
public var maxEvents: IntByReference = if (maxEvents == null) IntByReference() else IntByReference(maxEvents)
@JvmField
public var delayPingLifetimeIO: Byte = delayPingLifetimeIO.toByte()

init {
// Force UTF-8 string encoding when passing strings over the FFI
Expand Down Expand Up @@ -64,6 +67,7 @@ data class Configuration internal constructor(
val channel: String? = null,
val userAgent: String = DEFAULT_USER_AGENT,
val maxEvents: Int? = null,
val delayPingLifetimeIO: Boolean = false,
val logPings: Boolean = DEFAULT_LOG_PINGS,
// NOTE: since only simple object or strings can be made `const val`s, if the
// default values for the lines below are ever changed, they are required
Expand Down Expand Up @@ -96,6 +100,7 @@ data class Configuration internal constructor(
serverEndpoint = serverEndpoint,
userAgent = DEFAULT_USER_AGENT,
maxEvents = maxEvents,
delayPingLifetimeIO = false,
logPings = DEFAULT_LOG_PINGS,
httpClient = httpClient,
pingTag = null,
Expand Down
1 change: 1 addition & 0 deletions glean-core/examples/sample.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ fn main() {
application_id: "org.mozilla.glean_core.example".into(),
upload_enabled: true,
max_events: None,
delay_ping_lifetime_io: false,
};
let mut glean = Glean::new(cfg).unwrap();
glean.register_ping_type(&PingType::new("baseline", true, false));
Expand Down
1 change: 1 addition & 0 deletions glean-core/ffi/glean.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ typedef struct {
FfiStr package_name;
uint8_t upload_enabled;
const int32_t *max_events;
uint8_t delay_ping_lifetime_io;
} FfiConfiguration;

/**
Expand Down
3 changes: 3 additions & 0 deletions glean-core/ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ pub struct FfiConfiguration<'a> {
package_name: FfiStr<'a>,
upload_enabled: u8,
max_events: Option<&'a i32>,
delay_ping_lifetime_io: u8,
badboy marked this conversation as resolved.
Show resolved Hide resolved
}

/// Convert the FFI-compatible configuration object into the proper Rust configuration object.
Expand All @@ -112,12 +113,14 @@ impl TryFrom<&FfiConfiguration<'_>> for glean_core::Configuration {
let application_id = cfg.package_name.to_string_fallible()?;
let upload_enabled = cfg.upload_enabled != 0;
let max_events = cfg.max_events.filter(|&&i| i >= 0).map(|m| *m as usize);
let delay_ping_lifetime_io = cfg.delay_ping_lifetime_io != 0;

Ok(Self {
upload_enabled,
data_path,
application_id,
max_events,
delay_ping_lifetime_io,
})
}
}
Expand Down
1 change: 1 addition & 0 deletions glean-core/ios/Glean/GleanFfi.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ typedef struct {
FfiStr package_name;
uint8_t upload_enabled;
const int32_t *max_events;
uint8_t delay_ping_lifetime_io;
} FfiConfiguration;

/**
Expand Down
3 changes: 2 additions & 1 deletion glean-core/ios/Glean/Utils/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ func withFfiConfiguration<R>(
data_dir: dataDir,
package_name: packageName,
upload_enabled: uploadEnabled.toByte(),
max_events: maxEventsPtr
max_events: maxEventsPtr,
delay_ping_lifetime_io: false.toByte()
)
return body(cfg)
}
Expand Down
7 changes: 6 additions & 1 deletion glean-core/python/glean/_ffi.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ def _load_header(path: str) -> str:


def make_config(
data_dir: Path, package_name: str, upload_enabled: bool, max_events: int
data_dir: Path,
package_name: str,
upload_enabled: bool,
max_events: int,
delay_ping_lifetime_io: bool = False,
) -> Any:
"""
Make an `FfiConfiguration` object.
Expand All @@ -65,6 +69,7 @@ def make_config(
cfg.package_name = package_name
cfg.upload_enabled = upload_enabled
cfg.max_events = max_events
cfg.delay_ping_lifetime_io = delay_ping_lifetime_io

_global_weakkeydict[cfg] = (data_dir, package_name, max_events)

Expand Down
Loading