You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "eschutho (via GitHub)" <gi...@apache.org> on 2023/02/09 00:43:57 UTC

[GitHub] [superset] eschutho opened a new pull request, #23041: increment statsd as warn

eschutho opened a new pull request, #23041:
URL: https://github.com/apache/superset/pull/23041

   <!---
   Please write the PR title following the conventions at https://www.conventionalcommits.org/en/v1.0.0/
   Example:
   fix(dashboard): load charts correctly
   -->
   
   ### SUMMARY
   This PR allows us to track 4xx errors separately from 5xx in statsd for api responses. For monitoring overall health of the app, we can use statsd metrics to only look at application errors as opposed to client errors. 
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   <!--- Skip this if not applicable -->
   
   ### TESTING INSTRUCTIONS
   <!--- Required! What steps can be taken to manually verify the changes? -->
   
   ### ADDITIONAL INFORMATION
   <!--- Check any relevant boxes with "x" -->
   <!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue -->
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] Migration is atomic, supports rollback & is backwards-compatible
     - [ ] Confirm DB migration upgrade and downgrade tested
     - [ ] Runtime estimates and downtime expectations provided
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] eschutho commented on a diff in pull request #23041: chore: increment statsd as warn

Posted by "eschutho (via GitHub)" <gi...@apache.org>.
eschutho commented on code in PR #23041:
URL: https://github.com/apache/superset/pull/23041#discussion_r1107512018


##########
tests/unit_tests/utils/test_decorators.py:
##########
@@ -0,0 +1,76 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+
+from enum import Enum
+from typing import Any
+from unittest.mock import call, Mock, patch
+
+import pytest
+
+from superset import app
+from superset.utils import decorators
+
+
+class ResponseValues(str, Enum):
+    FAIL = "fail"
+    WARN = "warn"
+    OK = "ok"
+
+
+def test_debounce() -> None:
+    mock = Mock()
+
+    @decorators.debounce()
+    def myfunc(arg1: int, arg2: int, kwarg1: str = "abc", kwarg2: int = 2) -> int:
+        mock(arg1, kwarg1)
+        return arg1 + arg2 + kwarg2
+
+    # should be called only once when arguments don't change
+    myfunc(1, 1)
+    myfunc(1, 1)
+    result = myfunc(1, 1)
+    mock.assert_called_once_with(1, "abc")
+    assert result == 4
+
+    # kwarg order shouldn't matter
+    myfunc(1, 0, kwarg2=2, kwarg1="haha")
+    result = myfunc(1, 0, kwarg1="haha", kwarg2=2)
+    mock.assert_has_calls([call(1, "abc"), call(1, "haha")])
+    assert result == 3
+
+
+def test_statsd_gauge() -> None:
+    @decorators.statsd_gauge("custom.prefix")
+    def my_func(response: ResponseValues, *args: Any, **kwargs: Any) -> str:
+        if response == ResponseValues.FAIL:
+            raise ValueError("Error")
+        if response == ResponseValues.WARN:
+            raise FileNotFoundError("Not found")
+        return "OK"
+
+    with patch.object(app.config["STATS_LOGGER"], "gauge") as mock:
+        my_func(ResponseValues.OK, 1, 2)
+        mock.assert_called_once_with("custom.prefix.ok", 1)
+
+        with pytest.raises(ValueError):
+            my_func(ResponseValues.FAIL, 1, 2)
+            mock.assert_called_once_with("custom.prefix.error", 1)
+
+        with pytest.raises(FileNotFoundError):
+            my_func(ResponseValues.WARN, 1, 2)
+            mock.assert_called_once_with("custom.prefix.warn", 1)

Review Comment:
   Thanks, this is a great suggestion!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] eschutho merged pull request #23041: chore: increment statsd as warn

Posted by "eschutho (via GitHub)" <gi...@apache.org>.
eschutho merged PR #23041:
URL: https://github.com/apache/superset/pull/23041


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] villebro commented on a diff in pull request #23041: chore: increment statsd as warn

Posted by "villebro (via GitHub)" <gi...@apache.org>.
villebro commented on code in PR #23041:
URL: https://github.com/apache/superset/pull/23041#discussion_r1101102671


##########
tests/unit_tests/utils/test_decorators.py:
##########
@@ -0,0 +1,76 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+
+from enum import Enum
+from typing import Any
+from unittest.mock import call, Mock, patch
+
+import pytest
+
+from superset import app
+from superset.utils import decorators
+
+
+class ResponseValues(str, Enum):
+    FAIL = "fail"
+    WARN = "warn"
+    OK = "ok"
+
+
+def test_debounce() -> None:
+    mock = Mock()
+
+    @decorators.debounce()
+    def myfunc(arg1: int, arg2: int, kwarg1: str = "abc", kwarg2: int = 2) -> int:
+        mock(arg1, kwarg1)
+        return arg1 + arg2 + kwarg2
+
+    # should be called only once when arguments don't change
+    myfunc(1, 1)
+    myfunc(1, 1)
+    result = myfunc(1, 1)
+    mock.assert_called_once_with(1, "abc")
+    assert result == 4
+
+    # kwarg order shouldn't matter
+    myfunc(1, 0, kwarg2=2, kwarg1="haha")
+    result = myfunc(1, 0, kwarg1="haha", kwarg2=2)
+    mock.assert_has_calls([call(1, "abc"), call(1, "haha")])
+    assert result == 3
+
+
+def test_statsd_gauge() -> None:
+    @decorators.statsd_gauge("custom.prefix")
+    def my_func(response: ResponseValues, *args: Any, **kwargs: Any) -> str:
+        if response == ResponseValues.FAIL:
+            raise ValueError("Error")
+        if response == ResponseValues.WARN:
+            raise FileNotFoundError("Not found")
+        return "OK"
+
+    with patch.object(app.config["STATS_LOGGER"], "gauge") as mock:
+        my_func(ResponseValues.OK, 1, 2)
+        mock.assert_called_once_with("custom.prefix.ok", 1)
+
+        with pytest.raises(ValueError):
+            my_func(ResponseValues.FAIL, 1, 2)
+            mock.assert_called_once_with("custom.prefix.error", 1)
+
+        with pytest.raises(FileNotFoundError):
+            my_func(ResponseValues.WARN, 1, 2)
+            mock.assert_called_once_with("custom.prefix.warn", 1)

Review Comment:
   I think we could use `pytest.mark.parametrize` break out the actual test cases (`ResponseValues.OK`, `ResponseValues.FAIL` and `ResponseValues.WARN` and their respective assertions) into test function parameters. You can check a test cases that I did for the thumbnail digest functions where I'm defining cases that both execute with error vs without error (`nullcontext` is handy for being able to use `with` even when you don't have a real context manager like `pytest.raises`): https://github.com/apache/superset/blob/ddd8d17aa4785918afc5395312678d206a2f100a/tests/unit_tests/thumbnails/test_digest.py



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] codecov[bot] commented on pull request #23041: chore: increment statsd as warn

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #23041:
URL: https://github.com/apache/superset/pull/23041#issuecomment-1433641009

   # [Codecov](https://codecov.io/gh/apache/superset/pull/23041?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#23041](https://codecov.io/gh/apache/superset/pull/23041?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (bebf3af) into [master](https://codecov.io/gh/apache/superset/commit/50f1e2ee29d69c8aa44e5f610f3b7b385dc81af9?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (50f1e2e) will **increase** coverage by `1.02%`.
   > The diff coverage is `72.79%`.
   
   > :exclamation: Current head bebf3af differs from pull request most recent head 334a5da. Consider uploading reports for the commit 334a5da to get more accurate results
   
   ```diff
   @@            Coverage Diff             @@
   ##           master   #23041      +/-   ##
   ==========================================
   + Coverage   65.65%   66.67%   +1.02%     
   ==========================================
     Files        1878     1881       +3     
     Lines       72152    72398     +246     
     Branches     7868     7882      +14     
   ==========================================
   + Hits        47370    48274     +904     
   + Misses      22763    22102     -661     
   - Partials     2019     2022       +3     
   ```
   
   | Flag | Coverage Δ | |
   |---|---|---|
   | mysql | `?` | |
   | postgres | `?` | |
   | python | `80.46% <71.87%> (+2.04%)` | :arrow_up: |
   | sqlite | `76.90% <71.87%> (+0.27%)` | :arrow_up: |
   | unit | `52.52% <31.25%> (?)` | |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#carryforward-flags-in-the-pull-request-comment) to find out more.
   
   | [Impacted Files](https://codecov.io/gh/apache/superset/pull/23041?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [...es/superset-ui-core/src/query/buildQueryContext.ts](https://codecov.io/gh/apache/superset/pull/23041?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3VwZXJzZXQtZnJvbnRlbmQvcGFja2FnZXMvc3VwZXJzZXQtdWktY29yZS9zcmMvcXVlcnkvYnVpbGRRdWVyeUNvbnRleHQudHM=) | `100.00% <ø> (ø)` | |
   | [...tend/packages/superset-ui-core/src/style/index.tsx](https://codecov.io/gh/apache/superset/pull/23041?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3VwZXJzZXQtZnJvbnRlbmQvcGFja2FnZXMvc3VwZXJzZXQtdWktY29yZS9zcmMvc3R5bGUvaW5kZXgudHN4) | `100.00% <ø> (ø)` | |
   | [superset-frontend/src/SqlLab/App.jsx](https://codecov.io/gh/apache/superset/pull/23041?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3VwZXJzZXQtZnJvbnRlbmQvc3JjL1NxbExhYi9BcHAuanN4) | `0.00% <ø> (ø)` | |
   | [superset-frontend/src/SqlLab/actions/sqlLab.js](https://codecov.io/gh/apache/superset/pull/23041?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3VwZXJzZXQtZnJvbnRlbmQvc3JjL1NxbExhYi9hY3Rpb25zL3NxbExhYi5qcw==) | `64.05% <0.00%> (ø)` | |
   | [...lLab/components/ExploreCtasResultsButton/index.tsx](https://codecov.io/gh/apache/superset/pull/23041?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3VwZXJzZXQtZnJvbnRlbmQvc3JjL1NxbExhYi9jb21wb25lbnRzL0V4cGxvcmVDdGFzUmVzdWx0c0J1dHRvbi9pbmRleC50c3g=) | `8.33% <ø> (ø)` | |
   | [...set-frontend/src/components/Select/AsyncSelect.tsx](https://codecov.io/gh/apache/superset/pull/23041?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3VwZXJzZXQtZnJvbnRlbmQvc3JjL2NvbXBvbmVudHMvU2VsZWN0L0FzeW5jU2VsZWN0LnRzeA==) | `88.46% <ø> (ø)` | |
   | [...t-frontend/src/dashboard/components/SliceAdder.jsx](https://codecov.io/gh/apache/superset/pull/23041?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3VwZXJzZXQtZnJvbnRlbmQvc3JjL2Rhc2hib2FyZC9jb21wb25lbnRzL1NsaWNlQWRkZXIuanN4) | `60.27% <ø> (ø)` | |
   | [...rset-frontend/src/explore/components/SaveModal.tsx](https://codecov.io/gh/apache/superset/pull/23041?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3VwZXJzZXQtZnJvbnRlbmQvc3JjL2V4cGxvcmUvY29tcG9uZW50cy9TYXZlTW9kYWwudHN4) | `38.67% <0.00%> (-0.37%)` | :arrow_down: |
   | [...onents/controls/VizTypeControl/FastVizSwitcher.tsx](https://codecov.io/gh/apache/superset/pull/23041?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3VwZXJzZXQtZnJvbnRlbmQvc3JjL2V4cGxvcmUvY29tcG9uZW50cy9jb250cm9scy9WaXpUeXBlQ29udHJvbC9GYXN0Vml6U3dpdGNoZXIudHN4) | `89.79% <ø> (ø)` | |
   | [...perset-frontend/src/middleware/loggerMiddleware.js](https://codecov.io/gh/apache/superset/pull/23041?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c3VwZXJzZXQtZnJvbnRlbmQvc3JjL21pZGRsZXdhcmUvbG9nZ2VyTWlkZGxld2FyZS5qcw==) | `71.11% <0.00%> (-6.94%)` | :arrow_down: |
   | ... and [178 more](https://codecov.io/gh/apache/superset/pull/23041?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
   
   :mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org