mozilla-mobile / telemetry-ios

A generic library for sending telemetry pings from iOS applications to Mozilla's telemetry service.
Mozilla Public License 2.0
28 stars 23 forks source link

dailyUploadCount is not reset? #94

Closed st3fan closed 6 years ago

st3fan commented 6 years ago

I may be missing something here that is not obvious from the code, but I only see two functions that deal with the $PINGTYPE-dailyUploadCount value in Storage:

The first retrieves the value:

    private func dailyUploadCountForPingType(_ pingType: String) -> Int {
        return storage.get(valueFor: "\(pingType)-dailyUploadCount") as? Int ?? 0
    }

The second increments the value:

    private func incrementDailyUploadCountForPingType(_ pingType: String) {
        let dailyUploadCount = dailyUploadCountForPingType(pingType) + 1
        storage.set(key: "\(pingType)-dailyUploadCount", value: dailyUploadCount)

        let lastUploadTimestamp = Date().timeIntervalSince1970
        storage.set(key: "\(pingType)-lastUploadTimestamp", value: lastUploadTimestamp)
    }

Where is the code that resets or decrements this counter?

What happens when this counter reaches MaxNumberOfPingUploadsPerDay (100)?

st3fan commented 6 years ago

When this counter reaches MaxNumberOfPingUploadsPerDay, all pings are queued to disk.

justindarc commented 6 years ago

Oh man... good catch. I actually think this is the same issue as #95 because we check hasReachedDailyUploadLimit() which short-circuits when we've crossed over into the next day (which would result in ONE ping getting uploaded then stopping). So, that's actually the exact place where we should be resetting the counter.