1+ import logging
2+ import os
13from dataclasses import dataclass , field
24from enum import Enum
5+ from importlib .metadata import version
6+ from typing import TypeVar
7+
8+ from pynumaflow import setup_logging
9+
10+ _LOGGER = setup_logging (__name__ )
11+ if os .getenv ("PYTHONDEBUG" ):
12+ _LOGGER .setLevel (logging .DEBUG )
313
414# Constants for using in the info-server
515# Specify the minimum Numaflow version required by the current SDK version
1222# Format - (key, env_var)
1323METADATA_ENVS = [("CPU_LIMIT" , "NUMAFLOW_CPU_LIMIT" )]
1424
25+ # Metadata keys
26+
27+ # MAP_MODE_KEY is used in the server info object's metadata to indicate which map mode is enabled
28+ MAP_MODE_KEY = "MAP_MODE"
29+ # MULTIPROC_KEY is the field used to indicate that Multiproc map mode is enabled
30+ # The value contains the number of servers spawned.
31+ MULTIPROC_KEY = "MULTIPROC"
32+
33+ SI = TypeVar ("SI" , bound = "ServerInfo" )
34+
1535
1636class Protocol (str , Enum ):
1737 """
@@ -32,6 +52,16 @@ class Language(str, Enum):
3252 JAVA = "java"
3353
3454
55+ class MapMode (str , Enum ):
56+ """
57+ Enumerate Map Mode to be enabled
58+ """
59+
60+ UnaryMap = "unary-map"
61+ StreamMap = "stream-map"
62+ BatchMap = "batch-map"
63+
64+
3565@dataclass
3666class ServerInfo :
3767 """
@@ -50,3 +80,27 @@ class ServerInfo:
5080 minimum_numaflow_version : str
5181 version : str
5282 metadata : dict = field (default_factory = dict )
83+
84+ @classmethod
85+ def get_default_server_info (cls ) -> SI :
86+ serv_info = ServerInfo (
87+ protocol = Protocol .UDS ,
88+ language = Language .PYTHON ,
89+ minimum_numaflow_version = MINIMUM_NUMAFLOW_VERSION ,
90+ version = get_sdk_version (),
91+ metadata = dict (),
92+ )
93+ return serv_info
94+
95+
96+ def get_sdk_version () -> str :
97+ """
98+ Return the pynumaflow SDK version
99+ """
100+ try :
101+ return version ("pynumaflow" )
102+ except Exception as e :
103+ # Adding this to handle the case for local test/CI where pynumaflow
104+ # will not be installed as a package
105+ _LOGGER .error ("Could not read SDK version %r" , e , exc_info = True )
106+ return ""
0 commit comments