skypilot-nightly 1.0.0.dev20250831__py3-none-any.whl → 1.0.0.dev20250902__py3-none-any.whl

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.

Potentially problematic release.


This version of skypilot-nightly might be problematic. Click here for more details.

Files changed (45) hide show
  1. sky/__init__.py +2 -2
  2. sky/dashboard/out/404.html +1 -1
  3. sky/dashboard/out/_next/static/chunks/3015-8089ed1e0b7e37fd.js +1 -0
  4. sky/dashboard/out/_next/static/chunks/webpack-0eaa6f7e63f51311.js +1 -0
  5. sky/dashboard/out/_next/static/{FtHzmn6BMJ5PzqHhEY51g → tio0QibqY2C0F2-rPy00p}/_buildManifest.js +1 -1
  6. sky/dashboard/out/clusters/[cluster]/[job].html +1 -1
  7. sky/dashboard/out/clusters/[cluster].html +1 -1
  8. sky/dashboard/out/clusters.html +1 -1
  9. sky/dashboard/out/config.html +1 -1
  10. sky/dashboard/out/index.html +1 -1
  11. sky/dashboard/out/infra/[context].html +1 -1
  12. sky/dashboard/out/infra.html +1 -1
  13. sky/dashboard/out/jobs/[job].html +1 -1
  14. sky/dashboard/out/jobs/pools/[pool].html +1 -1
  15. sky/dashboard/out/jobs.html +1 -1
  16. sky/dashboard/out/users.html +1 -1
  17. sky/dashboard/out/volumes.html +1 -1
  18. sky/dashboard/out/workspace/new.html +1 -1
  19. sky/dashboard/out/workspaces/[name].html +1 -1
  20. sky/dashboard/out/workspaces.html +1 -1
  21. sky/global_user_state.py +67 -0
  22. sky/jobs/server/server.py +2 -1
  23. sky/serve/server/server.py +2 -1
  24. sky/server/auth/oauth2_proxy.py +6 -0
  25. sky/server/common.py +8 -6
  26. sky/server/metrics.py +82 -6
  27. sky/server/requests/executor.py +6 -2
  28. sky/server/requests/preconditions.py +3 -2
  29. sky/server/requests/requests.py +118 -29
  30. sky/server/server.py +50 -18
  31. sky/server/stream_utils.py +7 -5
  32. sky/server/uvicorn.py +7 -0
  33. sky/setup_files/dependencies.py +4 -1
  34. sky/skylet/constants.py +3 -0
  35. sky/utils/db/db_utils.py +64 -1
  36. sky/utils/perf_utils.py +22 -0
  37. {skypilot_nightly-1.0.0.dev20250831.dist-info → skypilot_nightly-1.0.0.dev20250902.dist-info}/METADATA +38 -35
  38. {skypilot_nightly-1.0.0.dev20250831.dist-info → skypilot_nightly-1.0.0.dev20250902.dist-info}/RECORD +43 -42
  39. sky/dashboard/out/_next/static/chunks/3015-6c9c09593b1e67b6.js +0 -1
  40. sky/dashboard/out/_next/static/chunks/webpack-6e76f636a048e145.js +0 -1
  41. /sky/dashboard/out/_next/static/{FtHzmn6BMJ5PzqHhEY51g → tio0QibqY2C0F2-rPy00p}/_ssgManifest.js +0 -0
  42. {skypilot_nightly-1.0.0.dev20250831.dist-info → skypilot_nightly-1.0.0.dev20250902.dist-info}/WHEEL +0 -0
  43. {skypilot_nightly-1.0.0.dev20250831.dist-info → skypilot_nightly-1.0.0.dev20250902.dist-info}/entry_points.txt +0 -0
  44. {skypilot_nightly-1.0.0.dev20250831.dist-info → skypilot_nightly-1.0.0.dev20250902.dist-info}/licenses/LICENSE +0 -0
  45. {skypilot_nightly-1.0.0.dev20250831.dist-info → skypilot_nightly-1.0.0.dev20250902.dist-info}/top_level.txt +0 -0
sky/global_user_state.py CHANGED
@@ -29,6 +29,7 @@ from sqlalchemy.ext import declarative
29
29
  from sky import models
30
30
  from sky import sky_logging
31
31
  from sky import skypilot_config
32
+ from sky.server import metrics as metrics_lib
32
33
  from sky.skylet import constants
33
34
  from sky.utils import common_utils
34
35
  from sky.utils import context_utils
@@ -329,6 +330,7 @@ def _init_db(func):
329
330
 
330
331
 
331
332
  @_init_db
333
+ @metrics_lib.time_me
332
334
  def add_or_update_user(user: models.User,
333
335
  allow_duplicate_name: bool = True) -> bool:
334
336
  """Store the mapping from user hash to user name for display purposes.
@@ -423,6 +425,7 @@ def add_or_update_user(user: models.User,
423
425
 
424
426
 
425
427
  @_init_db
428
+ @metrics_lib.time_me
426
429
  def get_user(user_id: str) -> Optional[models.User]:
427
430
  assert _SQLALCHEMY_ENGINE is not None
428
431
  with orm.Session(_SQLALCHEMY_ENGINE) as session:
@@ -436,6 +439,7 @@ def get_user(user_id: str) -> Optional[models.User]:
436
439
 
437
440
 
438
441
  @_init_db
442
+ @metrics_lib.time_me
439
443
  def _get_users(user_ids: Set[str]) -> Dict[str, models.User]:
440
444
  assert _SQLALCHEMY_ENGINE is not None
441
445
  with orm.Session(_SQLALCHEMY_ENGINE) as session:
@@ -450,6 +454,7 @@ def _get_users(user_ids: Set[str]) -> Dict[str, models.User]:
450
454
 
451
455
 
452
456
  @_init_db
457
+ @metrics_lib.time_me
453
458
  def get_user_by_name(username: str) -> List[models.User]:
454
459
  with orm.Session(_SQLALCHEMY_ENGINE) as session:
455
460
  rows = session.query(user_table).filter_by(name=username).all()
@@ -464,6 +469,7 @@ def get_user_by_name(username: str) -> List[models.User]:
464
469
 
465
470
 
466
471
  @_init_db
472
+ @metrics_lib.time_me
467
473
  def get_user_by_name_match(username_match: str) -> List[models.User]:
468
474
  with orm.Session(_SQLALCHEMY_ENGINE) as session:
469
475
  rows = session.query(user_table).filter(
@@ -475,6 +481,7 @@ def get_user_by_name_match(username_match: str) -> List[models.User]:
475
481
 
476
482
 
477
483
  @_init_db
484
+ @metrics_lib.time_me
478
485
  def delete_user(user_id: str) -> None:
479
486
  with orm.Session(_SQLALCHEMY_ENGINE) as session:
480
487
  session.query(user_table).filter_by(id=user_id).delete()
@@ -482,6 +489,7 @@ def delete_user(user_id: str) -> None:
482
489
 
483
490
 
484
491
  @_init_db
492
+ @metrics_lib.time_me
485
493
  def get_all_users() -> List[models.User]:
486
494
  assert _SQLALCHEMY_ENGINE is not None
487
495
  with orm.Session(_SQLALCHEMY_ENGINE) as session:
@@ -495,6 +503,7 @@ def get_all_users() -> List[models.User]:
495
503
 
496
504
 
497
505
  @_init_db
506
+ @metrics_lib.time_me
498
507
  def add_or_update_cluster(cluster_name: str,
499
508
  cluster_handle: 'backends.ResourceHandle',
500
509
  requested_resources: Optional[Set[Any]],
@@ -693,6 +702,7 @@ def add_or_update_cluster(cluster_name: str,
693
702
 
694
703
 
695
704
  @_init_db
705
+ @metrics_lib.time_me
696
706
  def add_cluster_event(cluster_name: str,
697
707
  new_status: Optional[status_lib.ClusterStatus],
698
708
  reason: str,
@@ -903,6 +913,7 @@ def _get_user_hash_or_current_user(user_hash: Optional[str]) -> str:
903
913
 
904
914
 
905
915
  @_init_db
916
+ @metrics_lib.time_me
906
917
  def update_cluster_handle(cluster_name: str,
907
918
  cluster_handle: 'backends.ResourceHandle'):
908
919
  assert _SQLALCHEMY_ENGINE is not None
@@ -914,6 +925,7 @@ def update_cluster_handle(cluster_name: str,
914
925
 
915
926
 
916
927
  @_init_db
928
+ @metrics_lib.time_me
917
929
  def update_last_use(cluster_name: str):
918
930
  """Updates the last used command for the cluster."""
919
931
  with orm.Session(_SQLALCHEMY_ENGINE) as session:
@@ -923,6 +935,7 @@ def update_last_use(cluster_name: str):
923
935
 
924
936
 
925
937
  @_init_db
938
+ @metrics_lib.time_me
926
939
  def remove_cluster(cluster_name: str, terminate: bool) -> None:
927
940
  """Removes cluster_name mapping."""
928
941
  assert _SQLALCHEMY_ENGINE is not None
@@ -971,6 +984,7 @@ def remove_cluster(cluster_name: str, terminate: bool) -> None:
971
984
 
972
985
 
973
986
  @_init_db
987
+ @metrics_lib.time_me
974
988
  def get_handle_from_cluster_name(
975
989
  cluster_name: str) -> Optional['backends.ResourceHandle']:
976
990
  assert _SQLALCHEMY_ENGINE is not None
@@ -983,6 +997,7 @@ def get_handle_from_cluster_name(
983
997
 
984
998
 
985
999
  @_init_db
1000
+ @metrics_lib.time_me
986
1001
  def get_glob_cluster_names(cluster_name: str) -> List[str]:
987
1002
  assert _SQLALCHEMY_ENGINE is not None
988
1003
  assert cluster_name is not None, 'cluster_name cannot be None'
@@ -1002,6 +1017,7 @@ def get_glob_cluster_names(cluster_name: str) -> List[str]:
1002
1017
 
1003
1018
 
1004
1019
  @_init_db
1020
+ @metrics_lib.time_me
1005
1021
  def set_cluster_status(cluster_name: str,
1006
1022
  status: status_lib.ClusterStatus) -> None:
1007
1023
  assert _SQLALCHEMY_ENGINE is not None
@@ -1019,6 +1035,7 @@ def set_cluster_status(cluster_name: str,
1019
1035
 
1020
1036
 
1021
1037
  @_init_db
1038
+ @metrics_lib.time_me
1022
1039
  def set_cluster_autostop_value(cluster_name: str, idle_minutes: int,
1023
1040
  to_down: bool) -> None:
1024
1041
  assert _SQLALCHEMY_ENGINE is not None
@@ -1035,6 +1052,7 @@ def set_cluster_autostop_value(cluster_name: str, idle_minutes: int,
1035
1052
 
1036
1053
 
1037
1054
  @_init_db
1055
+ @metrics_lib.time_me
1038
1056
  def get_cluster_launch_time(cluster_name: str) -> Optional[int]:
1039
1057
  assert _SQLALCHEMY_ENGINE is not None
1040
1058
  with orm.Session(_SQLALCHEMY_ENGINE) as session:
@@ -1045,6 +1063,7 @@ def get_cluster_launch_time(cluster_name: str) -> Optional[int]:
1045
1063
 
1046
1064
 
1047
1065
  @_init_db
1066
+ @metrics_lib.time_me
1048
1067
  def get_cluster_info(cluster_name: str) -> Optional[Dict[str, Any]]:
1049
1068
  assert _SQLALCHEMY_ENGINE is not None
1050
1069
  with orm.Session(_SQLALCHEMY_ENGINE) as session:
@@ -1055,6 +1074,7 @@ def get_cluster_info(cluster_name: str) -> Optional[Dict[str, Any]]:
1055
1074
 
1056
1075
 
1057
1076
  @_init_db
1077
+ @metrics_lib.time_me
1058
1078
  def get_cluster_provision_log_path(cluster_name: str) -> Optional[str]:
1059
1079
  """Returns provision_log_path from clusters table, if recorded."""
1060
1080
  assert _SQLALCHEMY_ENGINE is not None
@@ -1066,6 +1086,7 @@ def get_cluster_provision_log_path(cluster_name: str) -> Optional[str]:
1066
1086
 
1067
1087
 
1068
1088
  @_init_db
1089
+ @metrics_lib.time_me
1069
1090
  def get_cluster_history_provision_log_path(cluster_name: str) -> Optional[str]:
1070
1091
  """Returns provision_log_path from cluster_history for this name.
1071
1092
 
@@ -1107,6 +1128,7 @@ def get_cluster_history_provision_log_path(cluster_name: str) -> Optional[str]:
1107
1128
 
1108
1129
 
1109
1130
  @_init_db
1131
+ @metrics_lib.time_me
1110
1132
  def set_cluster_info(cluster_name: str, metadata: Dict[str, Any]) -> None:
1111
1133
  assert _SQLALCHEMY_ENGINE is not None
1112
1134
  with orm.Session(_SQLALCHEMY_ENGINE) as session:
@@ -1120,6 +1142,7 @@ def set_cluster_info(cluster_name: str, metadata: Dict[str, Any]) -> None:
1120
1142
 
1121
1143
 
1122
1144
  @_init_db
1145
+ @metrics_lib.time_me
1123
1146
  def get_cluster_storage_mounts_metadata(
1124
1147
  cluster_name: str) -> Optional[Dict[str, Any]]:
1125
1148
  assert _SQLALCHEMY_ENGINE is not None
@@ -1131,6 +1154,7 @@ def get_cluster_storage_mounts_metadata(
1131
1154
 
1132
1155
 
1133
1156
  @_init_db
1157
+ @metrics_lib.time_me
1134
1158
  def set_cluster_storage_mounts_metadata(
1135
1159
  cluster_name: str, storage_mounts_metadata: Dict[str, Any]) -> None:
1136
1160
  assert _SQLALCHEMY_ENGINE is not None
@@ -1147,6 +1171,7 @@ def set_cluster_storage_mounts_metadata(
1147
1171
 
1148
1172
 
1149
1173
  @_init_db
1174
+ @metrics_lib.time_me
1150
1175
  def _get_cluster_usage_intervals(
1151
1176
  cluster_hash: Optional[str]
1152
1177
  ) -> Optional[List[Tuple[int, Optional[int]]]]:
@@ -1188,6 +1213,7 @@ def _get_cluster_duration(cluster_hash: str) -> int:
1188
1213
 
1189
1214
 
1190
1215
  @_init_db
1216
+ @metrics_lib.time_me
1191
1217
  def _set_cluster_usage_intervals(
1192
1218
  cluster_hash: str, usage_intervals: List[Tuple[int,
1193
1219
  Optional[int]]]) -> None:
@@ -1205,6 +1231,7 @@ def _set_cluster_usage_intervals(
1205
1231
 
1206
1232
 
1207
1233
  @_init_db
1234
+ @metrics_lib.time_me
1208
1235
  def set_owner_identity_for_cluster(cluster_name: str,
1209
1236
  owner_identity: Optional[List[str]]) -> None:
1210
1237
  assert _SQLALCHEMY_ENGINE is not None
@@ -1222,6 +1249,7 @@ def set_owner_identity_for_cluster(cluster_name: str,
1222
1249
 
1223
1250
 
1224
1251
  @_init_db
1252
+ @metrics_lib.time_me
1225
1253
  def _get_hash_for_existing_cluster(cluster_name: str) -> Optional[str]:
1226
1254
  assert _SQLALCHEMY_ENGINE is not None
1227
1255
  with orm.Session(_SQLALCHEMY_ENGINE) as session:
@@ -1232,6 +1260,7 @@ def _get_hash_for_existing_cluster(cluster_name: str) -> Optional[str]:
1232
1260
 
1233
1261
 
1234
1262
  @_init_db
1263
+ @metrics_lib.time_me
1235
1264
  def get_launched_resources_from_cluster_hash(
1236
1265
  cluster_hash: str) -> Optional[Tuple[int, Any]]:
1237
1266
  assert _SQLALCHEMY_ENGINE is not None
@@ -1278,6 +1307,7 @@ def _load_storage_mounts_metadata(
1278
1307
 
1279
1308
 
1280
1309
  @_init_db
1310
+ @metrics_lib.time_me
1281
1311
  @context_utils.cancellation_guard
1282
1312
  def get_cluster_from_name(
1283
1313
  cluster_name: Optional[str]) -> Optional[Dict[str, Any]]:
@@ -1321,6 +1351,7 @@ def get_cluster_from_name(
1321
1351
 
1322
1352
 
1323
1353
  @_init_db
1354
+ @metrics_lib.time_me
1324
1355
  def get_clusters(
1325
1356
  *, # keyword only separator
1326
1357
  exclude_managed_clusters: bool = False,
@@ -1416,6 +1447,7 @@ def get_clusters(
1416
1447
 
1417
1448
 
1418
1449
  @_init_db
1450
+ @metrics_lib.time_me
1419
1451
  def get_clusters_from_history(
1420
1452
  days: Optional[int] = None) -> List[Dict[str, Any]]:
1421
1453
  """Get cluster reports from history.
@@ -1541,6 +1573,7 @@ def get_clusters_from_history(
1541
1573
 
1542
1574
 
1543
1575
  @_init_db
1576
+ @metrics_lib.time_me
1544
1577
  def get_cluster_names_start_with(starts_with: str) -> List[str]:
1545
1578
  assert _SQLALCHEMY_ENGINE is not None
1546
1579
  with orm.Session(_SQLALCHEMY_ENGINE) as session:
@@ -1550,6 +1583,7 @@ def get_cluster_names_start_with(starts_with: str) -> List[str]:
1550
1583
 
1551
1584
 
1552
1585
  @_init_db
1586
+ @metrics_lib.time_me
1553
1587
  def get_cached_enabled_clouds(cloud_capability: 'cloud.CloudCapability',
1554
1588
  workspace: str) -> List['clouds.Cloud']:
1555
1589
  assert _SQLALCHEMY_ENGINE is not None
@@ -1575,6 +1609,7 @@ def get_cached_enabled_clouds(cloud_capability: 'cloud.CloudCapability',
1575
1609
 
1576
1610
 
1577
1611
  @_init_db
1612
+ @metrics_lib.time_me
1578
1613
  def set_enabled_clouds(enabled_clouds: List[str],
1579
1614
  cloud_capability: 'cloud.CloudCapability',
1580
1615
  workspace: str) -> None:
@@ -1604,6 +1639,7 @@ def _get_enabled_clouds_key(cloud_capability: 'cloud.CloudCapability',
1604
1639
 
1605
1640
 
1606
1641
  @_init_db
1642
+ @metrics_lib.time_me
1607
1643
  def get_allowed_clouds(workspace: str) -> List[str]:
1608
1644
  assert _SQLALCHEMY_ENGINE is not None
1609
1645
  with orm.Session(_SQLALCHEMY_ENGINE) as session:
@@ -1615,6 +1651,7 @@ def get_allowed_clouds(workspace: str) -> List[str]:
1615
1651
 
1616
1652
 
1617
1653
  @_init_db
1654
+ @metrics_lib.time_me
1618
1655
  def set_allowed_clouds(allowed_clouds: List[str], workspace: str) -> None:
1619
1656
  assert _SQLALCHEMY_ENGINE is not None
1620
1657
  with orm.Session(_SQLALCHEMY_ENGINE) as session:
@@ -1641,6 +1678,7 @@ def _get_allowed_clouds_key(workspace: str) -> str:
1641
1678
 
1642
1679
 
1643
1680
  @_init_db
1681
+ @metrics_lib.time_me
1644
1682
  def add_or_update_storage(storage_name: str,
1645
1683
  storage_handle: 'Storage.StorageMetadata',
1646
1684
  storage_status: status_lib.StorageStatus):
@@ -1683,6 +1721,7 @@ def add_or_update_storage(storage_name: str,
1683
1721
 
1684
1722
 
1685
1723
  @_init_db
1724
+ @metrics_lib.time_me
1686
1725
  def remove_storage(storage_name: str):
1687
1726
  """Removes Storage from Database"""
1688
1727
  assert _SQLALCHEMY_ENGINE is not None
@@ -1692,6 +1731,7 @@ def remove_storage(storage_name: str):
1692
1731
 
1693
1732
 
1694
1733
  @_init_db
1734
+ @metrics_lib.time_me
1695
1735
  def set_storage_status(storage_name: str,
1696
1736
  status: status_lib.StorageStatus) -> None:
1697
1737
  assert _SQLALCHEMY_ENGINE is not None
@@ -1705,6 +1745,7 @@ def set_storage_status(storage_name: str,
1705
1745
 
1706
1746
 
1707
1747
  @_init_db
1748
+ @metrics_lib.time_me
1708
1749
  def get_storage_status(storage_name: str) -> Optional[status_lib.StorageStatus]:
1709
1750
  assert _SQLALCHEMY_ENGINE is not None
1710
1751
  assert storage_name is not None, 'storage_name cannot be None'
@@ -1716,6 +1757,7 @@ def get_storage_status(storage_name: str) -> Optional[status_lib.StorageStatus]:
1716
1757
 
1717
1758
 
1718
1759
  @_init_db
1760
+ @metrics_lib.time_me
1719
1761
  def set_storage_handle(storage_name: str,
1720
1762
  handle: 'Storage.StorageMetadata') -> None:
1721
1763
  assert _SQLALCHEMY_ENGINE is not None
@@ -1730,6 +1772,7 @@ def set_storage_handle(storage_name: str,
1730
1772
 
1731
1773
 
1732
1774
  @_init_db
1775
+ @metrics_lib.time_me
1733
1776
  def get_handle_from_storage_name(
1734
1777
  storage_name: Optional[str]) -> Optional['Storage.StorageMetadata']:
1735
1778
  assert _SQLALCHEMY_ENGINE is not None
@@ -1743,6 +1786,7 @@ def get_handle_from_storage_name(
1743
1786
 
1744
1787
 
1745
1788
  @_init_db
1789
+ @metrics_lib.time_me
1746
1790
  def get_glob_storage_name(storage_name: str) -> List[str]:
1747
1791
  assert _SQLALCHEMY_ENGINE is not None
1748
1792
  assert storage_name is not None, 'storage_name cannot be None'
@@ -1762,6 +1806,7 @@ def get_glob_storage_name(storage_name: str) -> List[str]:
1762
1806
 
1763
1807
 
1764
1808
  @_init_db
1809
+ @metrics_lib.time_me
1765
1810
  def get_storage_names_start_with(starts_with: str) -> List[str]:
1766
1811
  assert _SQLALCHEMY_ENGINE is not None
1767
1812
  with orm.Session(_SQLALCHEMY_ENGINE) as session:
@@ -1771,6 +1816,7 @@ def get_storage_names_start_with(starts_with: str) -> List[str]:
1771
1816
 
1772
1817
 
1773
1818
  @_init_db
1819
+ @metrics_lib.time_me
1774
1820
  def get_storage() -> List[Dict[str, Any]]:
1775
1821
  assert _SQLALCHEMY_ENGINE is not None
1776
1822
  with orm.Session(_SQLALCHEMY_ENGINE) as session:
@@ -1789,6 +1835,7 @@ def get_storage() -> List[Dict[str, Any]]:
1789
1835
 
1790
1836
 
1791
1837
  @_init_db
1838
+ @metrics_lib.time_me
1792
1839
  def get_volume_names_start_with(starts_with: str) -> List[str]:
1793
1840
  assert _SQLALCHEMY_ENGINE is not None
1794
1841
  with orm.Session(_SQLALCHEMY_ENGINE) as session:
@@ -1798,6 +1845,7 @@ def get_volume_names_start_with(starts_with: str) -> List[str]:
1798
1845
 
1799
1846
 
1800
1847
  @_init_db
1848
+ @metrics_lib.time_me
1801
1849
  def get_volumes() -> List[Dict[str, Any]]:
1802
1850
  assert _SQLALCHEMY_ENGINE is not None
1803
1851
  with orm.Session(_SQLALCHEMY_ENGINE) as session:
@@ -1818,6 +1866,7 @@ def get_volumes() -> List[Dict[str, Any]]:
1818
1866
 
1819
1867
 
1820
1868
  @_init_db
1869
+ @metrics_lib.time_me
1821
1870
  def get_volume_by_name(name: str) -> Optional[Dict[str, Any]]:
1822
1871
  assert _SQLALCHEMY_ENGINE is not None
1823
1872
  with orm.Session(_SQLALCHEMY_ENGINE) as session:
@@ -1837,6 +1886,7 @@ def get_volume_by_name(name: str) -> Optional[Dict[str, Any]]:
1837
1886
 
1838
1887
 
1839
1888
  @_init_db
1889
+ @metrics_lib.time_me
1840
1890
  def add_volume(name: str, config: models.VolumeConfig,
1841
1891
  status: status_lib.VolumeStatus) -> None:
1842
1892
  assert _SQLALCHEMY_ENGINE is not None
@@ -1871,6 +1921,7 @@ def add_volume(name: str, config: models.VolumeConfig,
1871
1921
 
1872
1922
 
1873
1923
  @_init_db
1924
+ @metrics_lib.time_me
1874
1925
  def update_volume(name: str, last_attached_at: int,
1875
1926
  status: status_lib.VolumeStatus) -> None:
1876
1927
  assert _SQLALCHEMY_ENGINE is not None
@@ -1883,6 +1934,7 @@ def update_volume(name: str, last_attached_at: int,
1883
1934
 
1884
1935
 
1885
1936
  @_init_db
1937
+ @metrics_lib.time_me
1886
1938
  def update_volume_status(name: str, status: status_lib.VolumeStatus) -> None:
1887
1939
  assert _SQLALCHEMY_ENGINE is not None
1888
1940
  with orm.Session(_SQLALCHEMY_ENGINE) as session:
@@ -1893,6 +1945,7 @@ def update_volume_status(name: str, status: status_lib.VolumeStatus) -> None:
1893
1945
 
1894
1946
 
1895
1947
  @_init_db
1948
+ @metrics_lib.time_me
1896
1949
  def delete_volume(name: str) -> None:
1897
1950
  assert _SQLALCHEMY_ENGINE is not None
1898
1951
  with orm.Session(_SQLALCHEMY_ENGINE) as session:
@@ -1901,6 +1954,7 @@ def delete_volume(name: str) -> None:
1901
1954
 
1902
1955
 
1903
1956
  @_init_db
1957
+ @metrics_lib.time_me
1904
1958
  def get_ssh_keys(user_hash: str) -> Tuple[str, str, bool]:
1905
1959
  assert _SQLALCHEMY_ENGINE is not None
1906
1960
  with orm.Session(_SQLALCHEMY_ENGINE) as session:
@@ -1912,6 +1966,7 @@ def get_ssh_keys(user_hash: str) -> Tuple[str, str, bool]:
1912
1966
 
1913
1967
 
1914
1968
  @_init_db
1969
+ @metrics_lib.time_me
1915
1970
  def set_ssh_keys(user_hash: str, ssh_public_key: str, ssh_private_key: str):
1916
1971
  assert _SQLALCHEMY_ENGINE is not None
1917
1972
  with orm.Session(_SQLALCHEMY_ENGINE) as session:
@@ -1938,6 +1993,7 @@ def set_ssh_keys(user_hash: str, ssh_public_key: str, ssh_private_key: str):
1938
1993
 
1939
1994
 
1940
1995
  @_init_db
1996
+ @metrics_lib.time_me
1941
1997
  def add_service_account_token(token_id: str,
1942
1998
  token_name: str,
1943
1999
  token_hash: str,
@@ -1971,6 +2027,7 @@ def add_service_account_token(token_id: str,
1971
2027
 
1972
2028
 
1973
2029
  @_init_db
2030
+ @metrics_lib.time_me
1974
2031
  def get_service_account_token(token_id: str) -> Optional[Dict[str, Any]]:
1975
2032
  """Get a service account token by token_id."""
1976
2033
  assert _SQLALCHEMY_ENGINE is not None
@@ -1992,6 +2049,7 @@ def get_service_account_token(token_id: str) -> Optional[Dict[str, Any]]:
1992
2049
 
1993
2050
 
1994
2051
  @_init_db
2052
+ @metrics_lib.time_me
1995
2053
  def get_user_service_account_tokens(user_hash: str) -> List[Dict[str, Any]]:
1996
2054
  """Get all service account tokens for a user (as creator)."""
1997
2055
  assert _SQLALCHEMY_ENGINE is not None
@@ -2011,6 +2069,7 @@ def get_user_service_account_tokens(user_hash: str) -> List[Dict[str, Any]]:
2011
2069
 
2012
2070
 
2013
2071
  @_init_db
2072
+ @metrics_lib.time_me
2014
2073
  def update_service_account_token_last_used(token_id: str) -> None:
2015
2074
  """Update the last_used_at timestamp for a service account token."""
2016
2075
  assert _SQLALCHEMY_ENGINE is not None
@@ -2024,6 +2083,7 @@ def update_service_account_token_last_used(token_id: str) -> None:
2024
2083
 
2025
2084
 
2026
2085
  @_init_db
2086
+ @metrics_lib.time_me
2027
2087
  def delete_service_account_token(token_id: str) -> bool:
2028
2088
  """Delete a service account token.
2029
2089
 
@@ -2039,6 +2099,7 @@ def delete_service_account_token(token_id: str) -> bool:
2039
2099
 
2040
2100
 
2041
2101
  @_init_db
2102
+ @metrics_lib.time_me
2042
2103
  def rotate_service_account_token(token_id: str,
2043
2104
  new_token_hash: str,
2044
2105
  new_expires_at: Optional[int] = None) -> None:
@@ -2069,6 +2130,7 @@ def rotate_service_account_token(token_id: str,
2069
2130
 
2070
2131
 
2071
2132
  @_init_db
2133
+ @metrics_lib.time_me
2072
2134
  def get_cluster_yaml_str(cluster_yaml_path: Optional[str]) -> Optional[str]:
2073
2135
  """Get the cluster yaml from the database or the local file system.
2074
2136
  If the cluster yaml is not in the database, check if it exists on the
@@ -2155,6 +2217,7 @@ def get_cluster_yaml_dict_multiple(
2155
2217
 
2156
2218
 
2157
2219
  @_init_db
2220
+ @metrics_lib.time_me
2158
2221
  def set_cluster_yaml(cluster_name: str, yaml_str: str) -> None:
2159
2222
  """Set the cluster yaml in the database."""
2160
2223
  assert _SQLALCHEMY_ENGINE is not None
@@ -2177,6 +2240,7 @@ def set_cluster_yaml(cluster_name: str, yaml_str: str) -> None:
2177
2240
 
2178
2241
 
2179
2242
  @_init_db
2243
+ @metrics_lib.time_me
2180
2244
  def remove_cluster_yaml(cluster_name: str):
2181
2245
  assert _SQLALCHEMY_ENGINE is not None
2182
2246
  with orm.Session(_SQLALCHEMY_ENGINE) as session:
@@ -2186,6 +2250,7 @@ def remove_cluster_yaml(cluster_name: str):
2186
2250
 
2187
2251
 
2188
2252
  @_init_db
2253
+ @metrics_lib.time_me
2189
2254
  def get_all_service_account_tokens() -> List[Dict[str, Any]]:
2190
2255
  """Get all service account tokens across all users (for admin access)."""
2191
2256
  assert _SQLALCHEMY_ENGINE is not None
@@ -2204,6 +2269,7 @@ def get_all_service_account_tokens() -> List[Dict[str, Any]]:
2204
2269
 
2205
2270
 
2206
2271
  @_init_db
2272
+ @metrics_lib.time_me
2207
2273
  def get_system_config(config_key: str) -> Optional[str]:
2208
2274
  """Get a system configuration value by key."""
2209
2275
  assert _SQLALCHEMY_ENGINE is not None
@@ -2216,6 +2282,7 @@ def get_system_config(config_key: str) -> Optional[str]:
2216
2282
 
2217
2283
 
2218
2284
  @_init_db
2285
+ @metrics_lib.time_me
2219
2286
  def set_system_config(config_key: str, config_value: str) -> None:
2220
2287
  """Set a system configuration value."""
2221
2288
  assert _SQLALCHEMY_ENGINE is not None
sky/jobs/server/server.py CHANGED
@@ -79,7 +79,8 @@ async def logs(
79
79
  if jobs_logs_body.refresh else api_requests.ScheduleType.SHORT,
80
80
  request_cluster_name=common.JOB_CONTROLLER_NAME,
81
81
  )
82
- request_task = api_requests.get_request(request.state.request_id)
82
+ request_task = await api_requests.get_request_async(request.state.request_id
83
+ )
83
84
 
84
85
  return stream_utils.stream_response(
85
86
  request_id=request_task.request_id,
@@ -107,7 +107,8 @@ async def tail_logs(
107
107
  request_cluster_name=common.SKY_SERVE_CONTROLLER_NAME,
108
108
  )
109
109
 
110
- request_task = api_requests.get_request(request.state.request_id)
110
+ request_task = await api_requests.get_request_async(request.state.request_id
111
+ )
111
112
 
112
113
  return stream_utils.stream_response(
113
114
  request_id=request_task.request_id,
@@ -12,9 +12,11 @@ import aiohttp
12
12
  import fastapi
13
13
  import starlette.middleware.base
14
14
 
15
+ from sky import global_user_state
15
16
  from sky import models
16
17
  from sky import sky_logging
17
18
  from sky.server.auth import authn
19
+ from sky.users import permission
18
20
  from sky.utils import common_utils
19
21
 
20
22
  logger = sky_logging.init_logger(__name__)
@@ -149,6 +151,10 @@ class OAuth2ProxyMiddleware(starlette.middleware.base.BaseHTTPMiddleware):
149
151
  'return user info, check your oauth2-proxy'
150
152
  'setup.'
151
153
  })
154
+ newly_added = global_user_state.add_or_update_user(auth_user)
155
+ if newly_added:
156
+ permission.permission_service.add_user_if_not_exists(
157
+ auth_user.id)
152
158
  request.state.auth_user = auth_user
153
159
  await authn.override_user_info_in_request_body(
154
160
  request, auth_user)
sky/server/common.py CHANGED
@@ -648,14 +648,16 @@ def _set_metrics_env_var(env: Union[Dict[str, str], os._Environ], metrics: bool,
648
648
  deploy: Whether the server is running in deploy mode, which means
649
649
  multiple processes might be running.
650
650
  """
651
+ del deploy
651
652
  if metrics or os.getenv(constants.ENV_VAR_SERVER_METRICS_ENABLED) == 'true':
652
653
  env[constants.ENV_VAR_SERVER_METRICS_ENABLED] = 'true'
653
- if deploy:
654
- metrics_dir = os.path.join(tempfile.gettempdir(), 'metrics')
655
- shutil.rmtree(metrics_dir, ignore_errors=True)
656
- os.makedirs(metrics_dir, exist_ok=True)
657
- # Refer to https://prometheus.github.io/client_python/multiprocess/
658
- env['PROMETHEUS_MULTIPROC_DIR'] = metrics_dir
654
+ # Always set the metrics dir since we need to collect metrics from
655
+ # subprocesses like the executor.
656
+ metrics_dir = os.path.join(tempfile.gettempdir(), 'metrics')
657
+ shutil.rmtree(metrics_dir, ignore_errors=True)
658
+ os.makedirs(metrics_dir, exist_ok=True)
659
+ # Refer to https://prometheus.github.io/client_python/multiprocess/
660
+ env['PROMETHEUS_MULTIPROC_DIR'] = metrics_dir
659
661
 
660
662
 
661
663
  def check_server_healthy(