Re-export internal enums and classes for use in the public API

These will only start making sense when they are actually added in the
UDL file, which will come along in later commits.
This commit is contained in:
Jan-Erik Rediger 2021-12-08 14:38:39 +01:00 коммит произвёл Jan-Erik Rediger
Родитель e3914280e8
Коммит c5f9686bab
12 изменённых файлов: 57 добавлений и 124 удалений

Просмотреть файл

@ -0,0 +1,37 @@
/* 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/. */
/**
* Reexport of internal enums and classes for use in the public API.
*/
package mozilla.telemetry.glean.private
/**
* The common set of data shared across all different metric types.
*/
typealias CommonMetricData = mozilla.telemetry.glean.internal.CommonMetricData
/**
* Enumeration of the different kinds of histograms supported by metrics based on histograms.
*/
typealias HistogramType = mozilla.telemetry.glean.internal.HistogramType
/**
* Enumeration of different metric lifetimes.
*/
typealias Lifetime = mozilla.telemetry.glean.internal.Lifetime
/**
* Enumeration of different resolutions supported by the MemoryDistribution metric type.
*
* These use the power-of-2 values of these units, that is, Kilobyte is pedantically a Kibibyte.
*/
typealias MemoryUnit = mozilla.telemetry.glean.internal.MemoryUnit
/**
* Enumeration of different resolutions supported by
* the Timespan and DateTime metric types.
*/
typealias TimeUnit = mozilla.telemetry.glean.internal.TimeUnit

Просмотреть файл

@ -15,7 +15,7 @@ interface HistogramBase {
* Please note that this assumes that the provided samples are already in the
* "unit" declared by the instance of the implementing metric type (e.g. if the
* implementing class is a [TimingDistributionMetricType] and the instance this
* method was called on is using [TimeUnit.Second], then `samples` are assumed
* method was called on is using [TimeUnit.SECOND], then `samples` are assumed
* to be in that unit).
*
* @param samples the [LongArray] holding the samples to be recorded by the metric.

Просмотреть файл

@ -1,19 +0,0 @@
/* 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/. */
package mozilla.telemetry.glean.private
/**
* Enumeration of the different kinds of histograms supported by metrics based on histograms.
*/
enum class HistogramType {
/**
* A histogram with linear spaced buckets.
*/
Linear,
/**
* A histogram with exponentially spaced buckets.
*/
Exponential
}

Просмотреть файл

@ -1,10 +0,0 @@
/* 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/. */
package mozilla.telemetry.glean.private
/**
* Enumeration of different metric lifetimes.
*/
typealias Lifetime = mozilla.telemetry.glean.internal.Lifetime

Просмотреть файл

@ -1,32 +0,0 @@
/* 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/. */
package mozilla.telemetry.glean.private
/**
* Enumeration of different resolutions supported by the MemoryDistribution metric type.
*
* These use the power-of-2 values of these units, that is, Kilobyte is pedantically a Kibibyte.
*/
enum class MemoryUnit {
/**
* Byte: 1 byte
*/
Byte,
/**
* Kilobyte: 2^10 bytes
*/
Kilobyte,
/**
* Megabyte: 2^20 bytes
*/
Megabyte,
/**
* Gigabyte: 2^30 bytes
*/
Gigabyte
}

Просмотреть файл

@ -1,40 +0,0 @@
/* 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/. */
package mozilla.telemetry.glean.private
/**
* Enumeration of different resolutions supported by
* the Timespan and DateTime metric types.
*/
enum class TimeUnit {
/**
* Represents nanosecond precision.
*/
Nanosecond,
/**
* Represents microsecond precision.
*/
Microsecond,
/**
* Represents millisecond precision.
*/
Millisecond,
/**
* Represents second precision.
*/
Second,
/**
* Represents minute precision.
*/
Minute,
/**
* Represents hour precision.
*/
Hour,
/**
* Represents day precision.
*/
Day,
}

Просмотреть файл

@ -315,7 +315,7 @@ internal class MetricsPingScheduler(
}
// Update the collection date: we don't really care if we have data or not, let's
// always update the sent date.
updateSentDate(getISOTimeString(now, truncateTo = TimeUnit.Day))
updateSentDate(getISOTimeString(now, truncateTo = TimeUnit.DAY))
// Reschedule the collection.
schedulePingCollection(now, sendTheNextCalendarDay = true, reason = Pings.metricsReasonCodes.reschedule)
}

Просмотреть файл

@ -65,7 +65,7 @@ class GleanTestRule(
val buildInfo = BuildInfo(versionCode = "0.0.1", versionName = "0.0.1")
val mps = MetricsPingScheduler(context, buildInfo)
mps.updateSentDate(getISOTimeString(fakeNow, truncateTo = TimeUnit.Day))
mps.updateSentDate(getISOTimeString(fakeNow, truncateTo = TimeUnit.DAY))
Glean.resetGlean(
context = context,

Просмотреть файл

@ -13,13 +13,13 @@ import java.util.Locale
@Suppress("TopLevelPropertyNaming")
internal val DATE_FORMAT_PATTERNS = mapOf(
TimeUnit.Nanosecond to "yyyy-MM-dd'T'HH:mm:ss.SSSZ",
TimeUnit.Microsecond to "yyyy-MM-dd'T'HH:mm:ss.SSSZ",
TimeUnit.Millisecond to "yyyy-MM-dd'T'HH:mm:ss.SSSZ",
TimeUnit.Second to "yyyy-MM-dd'T'HH:mm:ssZ",
TimeUnit.Minute to "yyyy-MM-dd'T'HH:mmZ",
TimeUnit.Hour to "yyyy-MM-dd'T'HHZ",
TimeUnit.Day to "yyyy-MM-ddZ"
TimeUnit.NANOSECOND to "yyyy-MM-dd'T'HH:mm:ss.SSSZ",
TimeUnit.MICROSECOND to "yyyy-MM-dd'T'HH:mm:ss.SSSZ",
TimeUnit.MILLISECOND to "yyyy-MM-dd'T'HH:mm:ss.SSSZ",
TimeUnit.SECOND to "yyyy-MM-dd'T'HH:mm:ssZ",
TimeUnit.MINUTE to "yyyy-MM-dd'T'HH:mmZ",
TimeUnit.HOUR to "yyyy-MM-dd'T'HHZ",
TimeUnit.DAY to "yyyy-MM-ddZ"
)
// A mapping from the length of the date string to the format that would parse
@ -46,7 +46,7 @@ internal val DATE_FORMAT_PATTERN_VALUES = DATE_FORMAT_PATTERNS.values.toSet()
*/
internal fun getISOTimeString(
date: Date = Date(),
truncateTo: TimeUnit = TimeUnit.Minute
truncateTo: TimeUnit = TimeUnit.MINUTE
): String {
val cal = Calendar.getInstance()
cal.setTime(date)
@ -62,7 +62,7 @@ internal fun getISOTimeString(
*/
internal fun getISOTimeString(
calendar: Calendar,
truncateTo: TimeUnit = TimeUnit.Minute
truncateTo: TimeUnit = TimeUnit.MINUTE
): String {
val dateFormat = SimpleDateFormat(DATE_FORMAT_PATTERNS[truncateTo], Locale.US)
dateFormat.setTimeZone(calendar.getTimeZone())

Просмотреть файл

@ -265,7 +265,7 @@ internal fun delayMetricsPing(
// Set the last sent date to yesterday.
val mps = MetricsPingScheduler(context, buildInfo)
mps.updateSentDate(getISOTimeString(fakeNow, truncateTo = TimeUnit.Day))
mps.updateSentDate(getISOTimeString(fakeNow, truncateTo = TimeUnit.DAY))
}
// The following Mockito fixups are copied over from support-test (Matchers.kt) from

Просмотреть файл

@ -27,9 +27,6 @@ import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import java.util.concurrent.TimeUnit
import mozilla.telemetry.glean.internal.CounterMetric as CounterMetricType
import mozilla.telemetry.glean.internal.CommonMetricData
import mozilla.telemetry.glean.internal.Lifetime
@RunWith(AndroidJUnit4::class)
class PingTypeTest {

Просмотреть файл

@ -16,13 +16,13 @@ class DateUtilsTest {
@Test
fun `test roundtripping ISO date formats`() {
for (timeUnit in listOf(
TimeUnit.Nanosecond,
TimeUnit.Microsecond,
TimeUnit.Millisecond,
TimeUnit.Second,
TimeUnit.Minute,
TimeUnit.Hour,
TimeUnit.Day
TimeUnit.NANOSECOND,
TimeUnit.MICROSECOND,
TimeUnit.MILLISECOND,
TimeUnit.SECOND,
TimeUnit.MINUTE,
TimeUnit.HOUR,
TimeUnit.DAY
)) {
val dateString = getISOTimeString(truncateTo = timeUnit)
val parsedDate = parseISOTimeString(dateString)!!