swanmetrics 1.0.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,8 @@
1
+ [bumpversion]
2
+ current_version = 1.0.3
3
+ commit = True
4
+ tag = True
5
+ tag_name = SwanMetrics/v{new_version}
6
+ message = SwanMetrics v{new_version}
7
+
8
+ [bumpversion:file:swanmetrics/_version.py]
@@ -0,0 +1,267 @@
1
+ */*/js/
2
+ */*/nbextension/extension.js
3
+ !SwanContents/swancontents/js/
4
+ SparkMonitor/scalalistener/project/
5
+ SparkMonitor/scalalistener/target/
6
+ SparkMonitor/sparkmonitor/listener*.jar
7
+ SparkMonitor/sparkmonitor/nbextension/*
8
+ .idea/
9
+
10
+ # Byte-compiled / optimized / DLL files
11
+ __pycache__/
12
+ *.py[cod]
13
+ *$py.class
14
+
15
+ # C extensions
16
+ *.so
17
+
18
+ # Distribution / packaging
19
+ .Python
20
+ build/
21
+ develop-eggs/
22
+ dist/
23
+ downloads/
24
+ eggs/
25
+ .eggs/
26
+ lib/
27
+ lib64/
28
+ parts/
29
+ sdist/
30
+ var/
31
+ wheels/
32
+ share/python-wheels/
33
+ *.egg-info/
34
+ .installed.cfg
35
+ *.egg
36
+ MANIFEST
37
+
38
+ # PyInstaller
39
+ # Usually these files are written by a python script from a template
40
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
41
+ *.manifest
42
+ *.spec
43
+
44
+ # Installer logs
45
+ pip-log.txt
46
+ pip-delete-this-directory.txt
47
+
48
+ # Unit test / coverage reports
49
+ htmlcov/
50
+ .tox/
51
+ .nox/
52
+ .coverage
53
+ .coverage.*
54
+ .cache
55
+ nosetests.xml
56
+ coverage.xml
57
+ *.cover
58
+ *.py,cover
59
+ .hypothesis/
60
+ .pytest_cache/
61
+ cover/
62
+
63
+ # Translations
64
+ *.mo
65
+ *.pot
66
+
67
+ # Django stuff:
68
+ *.log
69
+ local_settings.py
70
+ db.sqlite3
71
+ db.sqlite3-journal
72
+
73
+ # Flask stuff:
74
+ instance/
75
+ .webassets-cache
76
+
77
+ # Scrapy stuff:
78
+ .scrapy
79
+
80
+ # Sphinx documentation
81
+ docs/_build/
82
+
83
+ # PyBuilder
84
+ .pybuilder/
85
+ target/
86
+
87
+ # Jupyter Notebook
88
+ .ipynb_checkpoints
89
+
90
+ # IPython
91
+ profile_default/
92
+ ipython_config.py
93
+
94
+ # pyenv
95
+ # For a library or package, you might want to ignore these files since the code is
96
+ # intended to run in multiple environments; otherwise, check them in:
97
+ # .python-version
98
+
99
+ # pipenv
100
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
101
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
102
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
103
+ # install all needed dependencies.
104
+ #Pipfile.lock
105
+
106
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow
107
+ __pypackages__/
108
+
109
+ # Celery stuff
110
+ celerybeat-schedule
111
+ celerybeat.pid
112
+
113
+ # SageMath parsed files
114
+ *.sage.py
115
+
116
+ # Environments
117
+ .env
118
+ .venv
119
+ env/
120
+ venv/
121
+ ENV/
122
+ env.bak/
123
+ venv.bak/
124
+
125
+ # Spyder project settings
126
+ .spyderproject
127
+ .spyproject
128
+
129
+ # Rope project settings
130
+ .ropeproject
131
+
132
+ # mkdocs documentation
133
+ /site
134
+
135
+ # mypy
136
+ .mypy_cache/
137
+ .dmypy.json
138
+ dmypy.json
139
+
140
+ # Pyre type checker
141
+ .pyre/
142
+
143
+ # pytype static type analyzer
144
+ .pytype/
145
+
146
+ # Cython debug symbols
147
+ cython_debug/
148
+
149
+ # Logs
150
+ logs
151
+ *.log
152
+ npm-debug.log*
153
+ yarn-debug.log*
154
+ yarn-error.log*
155
+ lerna-debug.log*
156
+
157
+ # Diagnostic reports (https://nodejs.org/api/report.html)
158
+ report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
159
+
160
+ # Runtime data
161
+ pids
162
+ *.pid
163
+ *.seed
164
+ *.pid.lock
165
+
166
+ # Directory for instrumented libs generated by jscoverage/JSCover
167
+ lib-cov
168
+
169
+ # Coverage directory used by tools like istanbul
170
+ coverage
171
+ *.lcov
172
+
173
+ # nyc test coverage
174
+ .nyc_output
175
+
176
+ # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
177
+ .grunt
178
+
179
+ # Bower dependency directory (https://bower.io/)
180
+ bower_components
181
+
182
+ # node-waf configuration
183
+ .lock-wscript
184
+
185
+ # Compiled binary addons (https://nodejs.org/api/addons.html)
186
+ build/Release
187
+
188
+ # Dependency directories
189
+ node_modules/
190
+ jspm_packages/
191
+
192
+ # Snowpack dependency directory (https://snowpack.dev/)
193
+ web_modules/
194
+
195
+ # TypeScript cache
196
+ *.tsbuildinfo
197
+
198
+ # Optional npm cache directory
199
+ .npm
200
+
201
+ # Optional eslint cache
202
+ .eslintcache
203
+
204
+ # Microbundle cache
205
+ .rpt2_cache/
206
+ .rts2_cache_cjs/
207
+ .rts2_cache_es/
208
+ .rts2_cache_umd/
209
+
210
+ # Optional REPL history
211
+ .node_repl_history
212
+
213
+ # Output of 'npm pack'
214
+ *.tgz
215
+
216
+ # Yarn Integrity file
217
+ .yarn-integrity
218
+
219
+ # dotenv environment variables file
220
+ .env
221
+ .env.test
222
+
223
+ # parcel-bundler cache (https://parceljs.org/)
224
+ .cache
225
+ .parcel-cache
226
+
227
+ # Next.js build output
228
+ .next
229
+ out
230
+
231
+ # Nuxt.js build / generate output
232
+ .nuxt
233
+ dist
234
+
235
+ # Gatsby files
236
+ .cache/
237
+ # Comment in the public line in if your project uses Gatsby and not Next.js
238
+ # https://nextjs.org/blog/next-9-1#public-directory-support
239
+ # public
240
+
241
+ # vuepress build output
242
+ .vuepress/dist
243
+
244
+ # Serverless directories
245
+ .serverless/
246
+
247
+ # FuseBox cache
248
+ .fusebox/
249
+
250
+ # DynamoDB Local files
251
+ .dynamodb/
252
+
253
+ # TernJS port file
254
+ .tern-port
255
+
256
+ # Stores VSCode versions used for testing VSCode extensions
257
+ .vscode-test
258
+
259
+ # yarn v2
260
+ .yarn/cache
261
+ .yarn/unplugged
262
+ .yarn/build-state.yml
263
+ .yarn/install-state.gz
264
+ .pnp.*
265
+
266
+ # Mac OS files
267
+ .DS_Store
@@ -0,0 +1,32 @@
1
+ Metadata-Version: 2.4
2
+ Name: swanmetrics
3
+ Version: 1.0.3
4
+ Summary: Jupyter Server extension for collecting metrics via jupyter_events
5
+ Author-email: SWAN Team <swan-admins@cern.ch>
6
+ License-Expression: MIT
7
+ Requires-Python: >=3.10
8
+ Requires-Dist: jupyter-events==0.12.0
9
+ Requires-Dist: jupyter-server==2.15.0
10
+ Description-Content-Type: text/markdown
11
+
12
+ # SwanMetrics
13
+
14
+ SWAN Metrics extension to add metrics for specific user actions, such as opening editors.
15
+
16
+
17
+ ## Requirements
18
+
19
+ * jupyter_server
20
+ * jupyter_events
21
+
22
+ ## Install
23
+
24
+ ```bash
25
+ pip install swanmetrics
26
+ ```
27
+
28
+ ## Observations
29
+
30
+ * The `/metrics` route was added to direct the `PrometheusMetricsHandler` to the root url, so that Prometheus always scrapes the same endpoint,
31
+ without having to access the `/user/<username>/metrics` endpoint every time. Otherwise, the username would have to be parsed each time Prometheus
32
+ would scrape the metrics from the user pod.
@@ -0,0 +1,21 @@
1
+ # SwanMetrics
2
+
3
+ SWAN Metrics extension to add metrics for specific user actions, such as opening editors.
4
+
5
+
6
+ ## Requirements
7
+
8
+ * jupyter_server
9
+ * jupyter_events
10
+
11
+ ## Install
12
+
13
+ ```bash
14
+ pip install swanmetrics
15
+ ```
16
+
17
+ ## Observations
18
+
19
+ * The `/metrics` route was added to direct the `PrometheusMetricsHandler` to the root url, so that Prometheus always scrapes the same endpoint,
20
+ without having to access the `/user/<username>/metrics` endpoint every time. Otherwise, the username would have to be parsed each time Prometheus
21
+ would scrape the metrics from the user pod.
@@ -0,0 +1,7 @@
1
+ {
2
+ "ServerApp": {
3
+ "jpserver_extensions": {
4
+ "swanmetrics": true
5
+ }
6
+ }
7
+ }
@@ -0,0 +1,25 @@
1
+ [build-system]
2
+ requires = ["hatchling==1.28.0"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "swanmetrics"
7
+ dynamic = ["version"]
8
+ description = "Jupyter Server extension for collecting metrics via jupyter_events"
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ requires-python = ">=3.10"
12
+ authors = [{ name = "SWAN Team", email = "swan-admins@cern.ch" }]
13
+ dependencies = ["jupyter_server==2.15.0", "jupyter_events==0.12.0"]
14
+
15
+ [project.entry-points."jupyter_server.extensions"]
16
+ swanmetrics = "swanmetrics:_load_jupyter_server_extension"
17
+
18
+ [tool.hatch]
19
+ version = { path = "swanmetrics/_version.py" }
20
+
21
+ [tool.hatch.build.targets.wheel]
22
+ packages = ["swanmetrics"]
23
+
24
+ [tool.hatch.build.targets.wheel.shared-data]
25
+ "jupyter_server_config.d/swanmetrics.json" = "etc/jupyter/jupyter_server_config.d/swanmetrics.json"
@@ -0,0 +1,55 @@
1
+ from __future__ import annotations
2
+ from jupyter_server_proxy.handlers import ProxyHandler
3
+
4
+ from prometheus_client import Counter
5
+ from ._version import __version__
6
+
7
+ from jupyter_server.base.handlers import PrometheusMetricsHandler
8
+
9
+ editors_opened = {
10
+ "vscode": False
11
+ }
12
+
13
+ # Prometheus metrics
14
+ EDITORS_OPEN = Counter(
15
+ "swan_editor_open",
16
+ "Code editor usage in SWAN",
17
+ ["editor"]
18
+ )
19
+
20
+ _original_prepare = ProxyHandler.prepare
21
+ def _wrapped_prepare(self, *args, **kwargs):
22
+ path = self.request.path
23
+ for editor, visited in editors_opened.items():
24
+ if editor in path and not visited:
25
+ EDITORS_OPEN.labels(editor=editor).inc()
26
+ editors_opened[editor] = True
27
+ return _original_prepare(self)
28
+ ProxyHandler.prepare = _wrapped_prepare
29
+
30
+ def _load_jupyter_server_extension(server_app) -> None:
31
+ """
32
+ Extension entry point. Called by Jupyter Server on startup.
33
+ """
34
+ log = server_app.log
35
+ log.info(f"SwanMetrics: Loading version v{__version__}")
36
+
37
+ web_app = server_app.web_app
38
+
39
+ # Add route for Prometheus handler at the root level
40
+ # so that Prometheus always scrapes the same endpoint,
41
+ # without having to access /user/<username>/metrics every time.
42
+
43
+ web_app.add_handlers(
44
+ r".*$",
45
+ [(r"/metrics", PrometheusMetricsHandler)]
46
+ )
47
+
48
+
49
+ def _jupyter_server_extension_points():
50
+ """
51
+ Returns the extension metadata for jupyter_server.
52
+
53
+ This is required for `jupyter server extension enable` to work.
54
+ """
55
+ return [{"module": "swanmetrics"}]
@@ -0,0 +1,3 @@
1
+ # please don't modify this file,
2
+ # this is automatically updated by bump2version
3
+ __version__ = '1.0.3'