{"action":"created","comment":{"url":"https://api.github.com/repos/mozilla-mobile/android-components/pulls/comments/239531196","pull_request_review_id":182342457,"id":239531196,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIzOTUzMTE5Ng==","diff_hunk":"@@ -0,0 +1,105 @@\n+/* This Source Code Form is subject to the terms of the Mozilla Public\n+ * License, v. 2.0. If a copy of the MPL was not distributed with this\n+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */\n+\n+package mozilla.components.service.glean\n+\n+import kotlinx.coroutines.launch\n+import mozilla.components.service.glean.storages.StringListsStorageEngine\n+import mozilla.components.support.base.log.logger.Logger\n+\n+/**\n+ * This implements the developer facing API for recording string list metrics.\n+ *\n+ * Instances of this class type are automatically generated by the parsers at build time,\n+ * allowing developers to record values that were previously registered in the metrics.yaml file.\n+ *\n+ * The string list API exposes the [add] and [set] methods, which take care of validating the input\n+ * data and making sure that limits are enforced.\n+ */\n+data class StringListMetricType(\n+    override val disabled: Boolean,\n+    override val category: String,\n+    override val lifetime: Lifetime,\n+    override val name: String,\n+    override val sendInPings: List<String>\n+) : CommonMetricData {\n+\n+    override val defaultStorageDestinations: List<String> = listOf(\"metrics\")\n+\n+    private val logger = Logger(\"glean/StringListMetricType\")\n+\n+    companion object {\n+        // Maximum length of any passed value string, in UTF8 byte sequence length.\n+        const val MAX_STRING_LENGTH = 50\n+    }\n+\n+    /**\n+     * Appends a string value to one or more string list metric stores.  If the string exceeds the\n+     * maximum string length, defined as [MAX_STRING_LENGTH], it will be truncated.\n+     *\n+     * If adding the string to the lists would exceed the maximum value defined as\n+     * [StringListsStorageEngine.MAX_LIST_LENGTH_VALUE], then the storage engine will drop the new\n+     * value and it will not be added to the list.\n+     *\n+     * @param value This is a user defined string value. The maximum length of\n+     * this string is [MAX_STRING_LENGTH].\n+     */\n+    fun add(value: String) {\n+        // TODO report errors through other special metrics handled by the SDK. See bug 1499761.\n+\n+        if (!shouldRecord(logger)) {\n+            return\n+        }\n+\n+        val truncatedValue = value.let {\n+            if (it.length > MAX_STRING_LENGTH) {\n+                logger.warn(\"$category.$name - string too \" +\n+                        \"long ${it.length} > $MAX_STRING_LENGTH\")\n+                return@let it.substring(0, MAX_STRING_LENGTH)\n+            }\n+            it\n+        }\n+\n+        Dispatchers.API.launch {\n+            // Delegate storing the string to the storage engine.\n+            StringListsStorageEngine.add(\n+                    this@StringListMetricType,\n+                    value = listOf(truncatedValue)\n+            )\n+        }\n+    }\n+\n+    /**\n+     * Sets a List<String> to one or more metric stores.\n+     *\n+     * @param value This is a user defined string list. The maximum length of each string in the\n+     * list is defined by [MAX_STRING_LENGTH], while the maximum length of the list itself is\n+     * defined by [StringListsStorageEngine.MAX_LIST_LENGTH_VALUE].  If a longer list is passed\n+     * into this function, then the additional values will be dropped from the list and the list,\n+     * up to the [StringListsStorageEngine.MAX_LIST_LENGTH_VALUE], will still be recorded.\n+     */\n+    fun set(value: List<String>) {\n+        // TODO report errors through other special metrics handled by the SDK. See bug 1499761.\n+\n+        if (!shouldRecord(logger)) {\n+            return\n+        }\n+\n+        val stringList = value.map let@{","path":"components/service/glean/src/main/java/mozilla/components/service/glean/StringListMetricType.kt","position":89,"original_position":89,"commit_id":"a3382588a76ae63e7748fc71e71dee608a34ccce","original_commit_id":"a3382588a76ae63e7748fc71e71dee608a34ccce","user":{"login":"Dexterp37","id":883721,"node_id":"MDQ6VXNlcjg4MzcyMQ==","avatar_url":"https://avatars1.githubusercontent.com/u/883721?v=4","gravatar_id":"","url":"https://api.github.com/users/Dexterp37","html_url":"https://github.com/Dexterp37","followers_url":"https://api.github.com/users/Dexterp37/followers","following_url":"https://api.github.com/users/Dexterp37/following{/other_user}","gists_url":"https://api.github.com/users/Dexterp37/gists{/gist_id}","starred_url":"https://api.github.com/users/Dexterp37/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Dexterp37/subscriptions","organizations_url":"https://api.github.com/users/Dexterp37/orgs","repos_url":"https://api.github.com/users/Dexterp37/repos","events_url":"https://api.github.com/users/Dexterp37/events{/privacy}","received_events_url":"https://api.github.com/users/Dexterp37/received_events","type":"User","site_admin":false},"body":"I have the feeling this should work. I can't try that though, as I don't have the environment here on my laptop :(\r\n\r\n```\r\nval stringList = value.map {  \r\n  if (it.length > MAX_STRING_LENGTH) {\r\n    logger.warn(\"$category.$name - string too long ${stringValue.length} > $MAX_STRING_LENGTH\")\r\n  }\r\n  it.substring(0, MAX_STRING_LENGTH)\r\n}\r\n```","created_at":"2018-12-06T16:55:39Z","updated_at":"2018-12-06T16:55:39Z","html_url":"https://github.com/mozilla-mobile/android-components/pull/1537#discussion_r239531196","pull_request_url":"https://api.github.com/repos/mozilla-mobile/android-components/pulls/1537","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/mozilla-mobile/android-components/pulls/comments/239531196"},"html":{"href":"https://github.com/mozilla-mobile/android-components/pull/1537#discussion_r239531196"},"pull_request":{"href":"https://api.github.com/repos/mozilla-mobile/android-components/pulls/1537"}},"in_reply_to_id":239461529},"pull_request":{"url":"https://api.github.com/repos/mozilla-mobile/android-components/pulls/1537","id":235925222,"node_id":"MDExOlB1bGxSZXF1ZXN0MjM1OTI1MjIy","html_url":"https://github.com/mozilla-mobile/android-components/pull/1537","diff_url":"https://github.com/mozilla-mobile/android-components/pull/1537.diff","patch_url":"https://github.com/mozilla-mobile/android-components/pull/1537.patch","issue_url":"https://api.github.com/repos/mozilla-mobile/android-components/issues/1537","number":1537,"state":"open","locked":false,"title":"[glean] [WIP] Bug 1508952 - Add StringList metric type","user":{"login":"travis79","id":7341315,"node_id":"MDQ6VXNlcjczNDEzMTU=","avatar_url":"https://avatars1.githubusercontent.com/u/7341315?v=4","gravatar_id":"","url":"https://api.github.com/users/travis79","html_url":"https://github.com/travis79","followers_url":"https://api.github.com/users/travis79/followers","following_url":"https://api.github.com/users/travis79/following{/other_user}","gists_url":"https://api.github.com/users/travis79/gists{/gist_id}","starred_url":"https://api.github.com/users/travis79/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/travis79/subscriptions","organizations_url":"https://api.github.com/users/travis79/orgs","repos_url":"https://api.github.com/users/travis79/repos","events_url":"https://api.github.com/users/travis79/events{/privacy}","received_events_url":"https://api.github.com/users/travis79/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-12-04T19:07:56Z","updated_at":"2018-12-06T16:55:39Z","closed_at":null,"merged_at":null,"merge_commit_sha":"34c90d96ecddb6c43fb4b93019f0a80dcf841b1b","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/mozilla-mobile/android-components/pulls/1537/commits","review_comments_url":"https://api.github.com/repos/mozilla-mobile/android-components/pulls/1537/comments","review_comment_url":"https://api.github.com/repos/mozilla-mobile/android-components/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mozilla-mobile/android-components/issues/1537/comments","statuses_url":"https://api.github.com/repos/mozilla-mobile/android-components/statuses/a3382588a76ae63e7748fc71e71dee608a34ccce","head":{"label":"travis79:Bug-1508952","ref":"Bug-1508952","sha":"a3382588a76ae63e7748fc71e71dee608a34ccce","user":{"login":"travis79","id":7341315,"node_id":"MDQ6VXNlcjczNDEzMTU=","avatar_url":"https://avatars1.githubusercontent.com/u/7341315?v=4","gravatar_id":"","url":"https://api.github.com/users/travis79","html_url":"https://github.com/travis79","followers_url":"https://api.github.com/users/travis79/followers","following_url":"https://api.github.com/users/travis79/following{/other_user}","gists_url":"https://api.github.com/users/travis79/gists{/gist_id}","starred_url":"https://api.github.com/users/travis79/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/travis79/subscriptions","organizations_url":"https://api.github.com/users/travis79/orgs","repos_url":"https://api.github.com/users/travis79/repos","events_url":"https://api.github.com/users/travis79/events{/privacy}","received_events_url":"https://api.github.com/users/travis79/received_events","type":"User","site_admin":false},"repo":{"id":151725575,"node_id":"MDEwOlJlcG9zaXRvcnkxNTE3MjU1NzU=","name":"android-components","full_name":"travis79/android-components","private":false,"owner":{"login":"travis79","id":7341315,"node_id":"MDQ6VXNlcjczNDEzMTU=","avatar_url":"https://avatars1.githubusercontent.com/u/7341315?v=4","gravatar_id":"","url":"https://api.github.com/users/travis79","html_url":"https://github.com/travis79","followers_url":"https://api.github.com/users/travis79/followers","following_url":"https://api.github.com/users/travis79/following{/other_user}","gists_url":"https://api.github.com/users/travis79/gists{/gist_id}","starred_url":"https://api.github.com/users/travis79/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/travis79/subscriptions","organizations_url":"https://api.github.com/users/travis79/orgs","repos_url":"https://api.github.com/users/travis79/repos","events_url":"https://api.github.com/users/travis79/events{/privacy}","received_events_url":"https://api.github.com/users/travis79/received_events","type":"User","site_admin":false},"html_url":"https://github.com/travis79/android-components","description":"A collection of Android libraries to build browsers or browser-like applications.","fork":true,"url":"https://api.github.com/repos/travis79/android-components","forks_url":"https://api.github.com/repos/travis79/android-components/forks","keys_url":"https://api.github.com/repos/travis79/android-components/keys{/key_id}","collaborators_url":"https://api.github.com/repos/travis79/android-components/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/travis79/android-components/teams","hooks_url":"https://api.github.com/repos/travis79/android-components/hooks","issue_events_url":"https://api.github.com/repos/travis79/android-components/issues/events{/number}","events_url":"https://api.github.com/repos/travis79/android-components/events","assignees_url":"https://api.github.com/repos/travis79/android-components/assignees{/user}","branches_url":"https://api.github.com/repos/travis79/android-components/branches{/branch}","tags_url":"https://api.github.com/repos/travis79/android-components/tags","blobs_url":"https://api.github.com/repos/travis79/android-components/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/travis79/android-components/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/travis79/android-components/git/refs{/sha}","trees_url":"https://api.github.com/repos/travis79/android-components/git/trees{/sha}","statuses_url":"https://api.github.com/repos/travis79/android-components/statuses/{sha}","languages_url":"https://api.github.com/repos/travis79/android-components/languages","stargazers_url":"https://api.github.com/repos/travis79/android-components/stargazers","contributors_url":"https://api.github.com/repos/travis79/android-components/contributors","subscribers_url":"https://api.github.com/repos/travis79/android-components/subscribers","subscription_url":"https://api.github.com/repos/travis79/android-components/subscription","commits_url":"https://api.github.com/repos/travis79/android-components/commits{/sha}","git_commits_url":"https://api.github.com/repos/travis79/android-components/git/commits{/sha}","comments_url":"https://api.github.com/repos/travis79/android-components/comments{/number}","issue_comment_url":"https://api.github.com/repos/travis79/android-components/issues/comments{/number}","contents_url":"https://api.github.com/repos/travis79/android-components/contents/{+path}","compare_url":"https://api.github.com/repos/travis79/android-components/compare/{base}...{head}","merges_url":"https://api.github.com/repos/travis79/android-components/merges","archive_url":"https://api.github.com/repos/travis79/android-components/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/travis79/android-components/downloads","issues_url":"https://api.github.com/repos/travis79/android-components/issues{/number}","pulls_url":"https://api.github.com/repos/travis79/android-components/pulls{/number}","milestones_url":"https://api.github.com/repos/travis79/android-components/milestones{/number}","notifications_url":"https://api.github.com/repos/travis79/android-components/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/travis79/android-components/labels{/name}","releases_url":"https://api.github.com/repos/travis79/android-components/releases{/id}","deployments_url":"https://api.github.com/repos/travis79/android-components/deployments","created_at":"2018-10-05T13:34:17Z","updated_at":"2018-11-30T17:35:38Z","pushed_at":"2018-12-06T13:45:57Z","git_url":"git://github.com/travis79/android-components.git","ssh_url":"git@github.com:travis79/android-components.git","clone_url":"https://github.com/travis79/android-components.git","svn_url":"https://github.com/travis79/android-components","homepage":"https://mozilla-mobile.github.io/android-components/","size":39911,"stargazers_count":0,"watchers_count":0,"language":"Kotlin","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"mpl-2.0","name":"Mozilla Public License 2.0","spdx_id":"MPL-2.0","url":"https://api.github.com/licenses/mpl-2.0","node_id":"MDc6TGljZW5zZTE0"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"mozilla-mobile:master","ref":"master","sha":"2373be02626fd8f3f7d80f2988063ddec3b083cd","user":{"login":"mozilla-mobile","id":22351667,"node_id":"MDEyOk9yZ2FuaXphdGlvbjIyMzUxNjY3","avatar_url":"https://avatars3.githubusercontent.com/u/22351667?v=4","gravatar_id":"","url":"https://api.github.com/users/mozilla-mobile","html_url":"https://github.com/mozilla-mobile","followers_url":"https://api.github.com/users/mozilla-mobile/followers","following_url":"https://api.github.com/users/mozilla-mobile/following{/other_user}","gists_url":"https://api.github.com/users/mozilla-mobile/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla-mobile/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla-mobile/subscriptions","organizations_url":"https://api.github.com/users/mozilla-mobile/orgs","repos_url":"https://api.github.com/users/mozilla-mobile/repos","events_url":"https://api.github.com/users/mozilla-mobile/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla-mobile/received_events","type":"Organization","site_admin":false},"repo":{"id":126199585,"node_id":"MDEwOlJlcG9zaXRvcnkxMjYxOTk1ODU=","name":"android-components","full_name":"mozilla-mobile/android-components","private":false,"owner":{"login":"mozilla-mobile","id":22351667,"node_id":"MDEyOk9yZ2FuaXphdGlvbjIyMzUxNjY3","avatar_url":"https://avatars3.githubusercontent.com/u/22351667?v=4","gravatar_id":"","url":"https://api.github.com/users/mozilla-mobile","html_url":"https://github.com/mozilla-mobile","followers_url":"https://api.github.com/users/mozilla-mobile/followers","following_url":"https://api.github.com/users/mozilla-mobile/following{/other_user}","gists_url":"https://api.github.com/users/mozilla-mobile/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla-mobile/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla-mobile/subscriptions","organizations_url":"https://api.github.com/users/mozilla-mobile/orgs","repos_url":"https://api.github.com/users/mozilla-mobile/repos","events_url":"https://api.github.com/users/mozilla-mobile/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla-mobile/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/mozilla-mobile/android-components","description":"A collection of Android libraries to build browsers or browser-like applications.","fork":false,"url":"https://api.github.com/repos/mozilla-mobile/android-components","forks_url":"https://api.github.com/repos/mozilla-mobile/android-components/forks","keys_url":"https://api.github.com/repos/mozilla-mobile/android-components/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mozilla-mobile/android-components/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mozilla-mobile/android-components/teams","hooks_url":"https://api.github.com/repos/mozilla-mobile/android-components/hooks","issue_events_url":"https://api.github.com/repos/mozilla-mobile/android-components/issues/events{/number}","events_url":"https://api.github.com/repos/mozilla-mobile/android-components/events","assignees_url":"https://api.github.com/repos/mozilla-mobile/android-components/assignees{/user}","branches_url":"https://api.github.com/repos/mozilla-mobile/android-components/branches{/branch}","tags_url":"https://api.github.com/repos/mozilla-mobile/android-components/tags","blobs_url":"https://api.github.com/repos/mozilla-mobile/android-components/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mozilla-mobile/android-components/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mozilla-mobile/android-components/git/refs{/sha}","trees_url":"https://api.github.com/repos/mozilla-mobile/android-components/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mozilla-mobile/android-components/statuses/{sha}","languages_url":"https://api.github.com/repos/mozilla-mobile/android-components/languages","stargazers_url":"https://api.github.com/repos/mozilla-mobile/android-components/stargazers","contributors_url":"https://api.github.com/repos/mozilla-mobile/android-components/contributors","subscribers_url":"https://api.github.com/repos/mozilla-mobile/android-components/subscribers","subscription_url":"https://api.github.com/repos/mozilla-mobile/android-components/subscription","commits_url":"https://api.github.com/repos/mozilla-mobile/android-components/commits{/sha}","git_commits_url":"https://api.github.com/repos/mozilla-mobile/android-components/git/commits{/sha}","comments_url":"https://api.github.com/repos/mozilla-mobile/android-components/comments{/number}","issue_comment_url":"https://api.github.com/repos/mozilla-mobile/android-components/issues/comments{/number}","contents_url":"https://api.github.com/repos/mozilla-mobile/android-components/contents/{+path}","compare_url":"https://api.github.com/repos/mozilla-mobile/android-components/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mozilla-mobile/android-components/merges","archive_url":"https://api.github.com/repos/mozilla-mobile/android-components/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mozilla-mobile/android-components/downloads","issues_url":"https://api.github.com/repos/mozilla-mobile/android-components/issues{/number}","pulls_url":"https://api.github.com/repos/mozilla-mobile/android-components/pulls{/number}","milestones_url":"https://api.github.com/repos/mozilla-mobile/android-components/milestones{/number}","notifications_url":"https://api.github.com/repos/mozilla-mobile/android-components/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mozilla-mobile/android-components/labels{/name}","releases_url":"https://api.github.com/repos/mozilla-mobile/android-components/releases{/id}","deployments_url":"https://api.github.com/repos/mozilla-mobile/android-components/deployments","created_at":"2018-03-21T15:24:03Z","updated_at":"2018-12-06T13:12:00Z","pushed_at":"2018-12-06T15:53:38Z","git_url":"git://github.com/mozilla-mobile/android-components.git","ssh_url":"git@github.com:mozilla-mobile/android-components.git","clone_url":"https://github.com/mozilla-mobile/android-components.git","svn_url":"https://github.com/mozilla-mobile/android-components","homepage":"https://mozilla-mobile.github.io/android-components/","size":39900,"stargazers_count":512,"watchers_count":512,"language":"Kotlin","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":104,"mirror_url":null,"archived":false,"open_issues_count":281,"license":{"key":"mpl-2.0","name":"Mozilla Public License 2.0","spdx_id":"MPL-2.0","url":"https://api.github.com/licenses/mpl-2.0","node_id":"MDc6TGljZW5zZTE0"},"forks":104,"open_issues":281,"watchers":512,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mozilla-mobile/android-components/pulls/1537"},"html":{"href":"https://github.com/mozilla-mobile/android-components/pull/1537"},"issue":{"href":"https://api.github.com/repos/mozilla-mobile/android-components/issues/1537"},"comments":{"href":"https://api.github.com/repos/mozilla-mobile/android-components/issues/1537/comments"},"review_comments":{"href":"https://api.github.com/repos/mozilla-mobile/android-components/pulls/1537/comments"},"review_comment":{"href":"https://api.github.com/repos/mozilla-mobile/android-components/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mozilla-mobile/android-components/pulls/1537/commits"},"statuses":{"href":"https://api.github.com/repos/mozilla-mobile/android-components/statuses/a3382588a76ae63e7748fc71e71dee608a34ccce"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"Dexterp37"}}