Skip to content

Add FXIOS-14919 [Nimbus] Submit nimbus-targeting-context ping#32150

Merged
Foxbolts merged 3 commits intomozilla-mobile:mainfrom
relud:relud-submit-targeting-context
Feb 23, 2026
Merged

Add FXIOS-14919 [Nimbus] Submit nimbus-targeting-context ping#32150
Foxbolts merged 3 commits intomozilla-mobile:mainfrom
relud:relud-submit-targeting-context

Conversation

@relud
Copy link
Copy Markdown
Contributor

@relud relud commented Feb 17, 2026

📜 Tickets

Jira ticket
Github issue

💡 Description

Application-services is adding a nimbus-targeting-context ping for nimbus_events.enrollment_status in mozilla/application-services#7225

In order to submit the new ping, MozillaRustComponents and FocusRustComponents must implement the new interface method MetricsHandler.submitTargetingContext to submit the new ping.

This is a breaking change, so it must be merged/tested in conjunction with updating application-services or an appropriate local build:

Test instructions for locally built application-services:
  • checkout application-services
    • commands below assume it's in the same parent directory as firefox-ios
  • build xcframework and generate swift files: taskcluster/scripts/build-and-test-swift.sh
  • copy generated swift files to firefox-ios: e.g.
    cp ./build/swift-components/all/Generated/*.swift ../firefox-ios/MozillaRustComponents/Sources/MozillaRustComponentsWrapper/Generated/.
    cp ./build/swift-components/all/Generated/Metrics/*.swift ../firefox-ios/MozillaRustComponents/Sources/MozillaRustComponentsWrapper/Generated/Metrics/.
    cp ./build/swift-components/focus/Generated/*.swift ../firefox-ios/MozillaRustComponents/Sources/FocusRustComponentsWrapper/Generated/.
    cp ./build/swift-components/focus/Generated/Metrics/*.swift ../firefox-ios/MozillaRustComponents/Sources/FocusRustComponentsWrapper/Generated/Metrics/.
    
  • Update MozillaRustComponents in MozillaRustComponents/Package.swift:
    • comment out url and checksum
    • set relative path to application-services artifacts, e.g.
      path: "../../application-services/megazords/ios-rust/MozillaRustComponents.xcframework"
      
  • Update FocusRustComponents in MozillaRustComponents/Package.swift:
    • comment out url and checksum
    • set relative path to application-services focus artifacts, e.g.
      path: "../../application-services/megazords/ios-rust/focus/FocusRustComponents.xcframework"
      
  • reset package caches and clean build folder:
    • File → Packages → Reset Package Caches
    • Product → Clean Build Folder
  • run tests

🎥 Demos

This change should only impact events being recorded by glean, as demonstrated in the new test case.

📝 Checklist

  • I filled in the ticket numbers and a description of my work
  • I updated the PR name to follow our PR naming guidelines
  • I ensured unit tests pass and wrote tests for new code
  • If working on UI, I checked and implemented accessibility (Dynamic Text and VoiceOver)
  • If adding telemetry, I read the data stewardship requirements and will request a data review
  • If adding or modifying strings, I read the guidelines and will request a string review from l10n
  • If needed, I updated documentation and added comments to complex code

XCTAssertEqual("US", calculatedAttributes.region)
}

func testRecordEnrollmentStatuses() throws {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't seem to figure out how to run any tests in this package 🙃

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I worked around this by applying the following patch to run an equivalent test in firefox-ios-tests:

test.patch
diff --git a/MozillaRustComponents/Sources/MozillaRustComponentsWrapper/Nimbus/NimbusCreate.swift b/MozillaRustComponents/Sources/MozillaRustComponentsWrapper/Nimbus/NimbusCreate.swift
index 3d36de1bd8..d610d3a344 100644
--- a/MozillaRustComponents/Sources/MozillaRustComponentsWrapper/Nimbus/NimbusCreate.swift
+++ b/MozillaRustComponents/Sources/MozillaRustComponentsWrapper/Nimbus/NimbusCreate.swift
@@ -166,4 +166,43 @@ public extension Nimbus {
             customTargetingAttributes: try? appSettings.customTargetingAttributes.stringify()
         )
     }
+
+    static func resetGlean() {
+        Glean.shared.resetGlean(clearStores: true)
+    }
+
+    static func serverKnobs() {
+        let metricConfig = """
+            {
+                "metrics_enabled": {
+                    "nimbus_events.enrollment_status": true
+                }
+            }
+        """
+        Glean.shared.applyServerKnobsConfig(metricConfig)
+    }
+
+    static func testBeforeNextSubmit(cb: @escaping (NoReasonCodes?) throws -> Void) {
+        GleanMetrics.Pings.shared.nimbusTargetingContext.testBeforeNextSubmit(cb: cb)
+    }
+
+    static func recordStatuses() {
+        let metricsHandler = GleanMetricsHandler()
+        metricsHandler.recordEnrollmentStatuses(enrollmentStatusExtras: [
+            EnrollmentStatusExtraDef(
+                branch: "branch",
+                conflictSlug: "conflictSlug",
+                errorString: "errorString",
+                reason: "reason",
+                slug: "slug",
+                status: "status",
+                prevGeckoPrefStates: nil
+            )
+        ])
+        metricsHandler.submitTargetingContext()
+    }
+
+    static func getEvents() -> [RecordedEvent]? {
+        return GleanMetrics.NimbusEvents.enrollmentStatus.testGetValue()
+    }
 }
diff --git a/firefox-ios/firefox-ios-tests/Tests/ClientTests/Nimbus/NimbusExposedTests.swift b/firefox-ios/firefox-ios-tests/Tests/ClientTests/Nimbus/NimbusExposedTests.swift
index e69de29bb2..3d97bd6c28 100644
--- a/firefox-ios/firefox-ios-tests/Tests/ClientTests/Nimbus/NimbusExposedTests.swift
+++ b/firefox-ios/firefox-ios-tests/Tests/ClientTests/Nimbus/NimbusExposedTests.swift
@@ -0,0 +1,41 @@
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/
+
+import Glean
+import MozillaAppServices
+import UIKit
+import XCTest
+
+class NimbusExposedTests: XCTestCase {
+    override func setUp() {
+        Nimbus.resetGlean()
+    }
+
+    func testRecordEnrollmentStatuses() throws {
+        Nimbus.serverKnobs()
+
+        var events: [RecordedEvent]?
+        let expectation = expectation(description: "The nimbus targeting context ping was sent")
+        Nimbus.testBeforeNextSubmit { e in
+            events = Nimbus.getEvents()
+            expectation.fulfill()
+        }
+
+        Nimbus.recordStatuses()
+
+        wait(for: [expectation], timeout: 5.0)
+
+        XCTAssertEqual(
+            events?.map { $0.extra },
+            [[
+                "branch": "branch",
+                "conflict_slug": "conflictSlug",
+                "error_string": "errorString",
+                "reason": "reason",
+                "slug": "slug",
+                "status": "status"
+            ]]
+        )
+    }
+}

@relud relud marked this pull request as ready for review February 17, 2026 23:54
@relud relud requested a review from a team as a code owner February 17, 2026 23:54
@relud relud requested a review from PARAIPAN9 February 17, 2026 23:54
@adudenamedruby
Copy link
Copy Markdown
Contributor

Bitrise failed with:

  /Users/[REDACTED]/git/MozillaRustComponents/Sources/MozillaRustComponentsWrapper/Nimbus/NimbusCreate.swift:66:35: value of type 'GleanMetrics.Pings' has no member 'nimbusTargetingContext'

        GleanMetrics.Pings.shared.nimbusTargetingContext.submit()
        ~~~~~~~~~~~~~~~~~~~~~~~~~ ^~~~~~~~~~~~~~~~~~~~~~

@mobiletest-ci-bot
Copy link
Copy Markdown

💪 Quality guardian

1 tests files modified. You're a champion of test coverage! 🚀

🧩 Neat Piece

This PR changes 410 lines. It's a substantial update,
but still review-friendly if there’s a clear description. Thanks for keeping things moving! 🚀

💬 Description craftsman

Great PR description! Reviewers salute you 🫡

✅ New file code coverage

No new file detected so code coverage gate wasn't ran.

Generated by 🚫 Danger Swift against f45c817

@Foxbolts Foxbolts merged commit d4d6c0a into mozilla-mobile:main Feb 23, 2026
10 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

🚀 PR merged to main, targeting version: 148.2

@relud relud deleted the relud-submit-targeting-context branch February 23, 2026 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants