Upgrade the Python version used by the Service and Context components

Upgrade Python version of the Service and Context components from 3.9 to 3.13, with relevant upgrades in the version of dependencies. This MR also provides infrastructure for the migration of other components.

Closes #307

Edited by Lluis Gifre Renom

Merge request reports

Loading
+9 −4
Changes for manifests/contextservice.yaml: 9 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -52,12 +52,17 @@ spec:
                name: crdb-data
            - secretRef:
                name: nats-data
          startupProbe:
            grpc:
              port: 1010
            failureThreshold: 30
            periodSeconds: 1
          readinessProbe:
            exec:
              command: ["/bin/grpc_health_probe", "-addr=:1010"]
            grpc:
              port: 1010
          livenessProbe:
            exec:
              command: ["/bin/grpc_health_probe", "-addr=:1010"]
            grpc:
              port: 1010
          resources:
            requests:
              cpu: 250m
+9 −4
Changes for manifests/serviceservice.yaml: 9 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -37,12 +37,17 @@ spec:
          env:
            - name: LOG_LEVEL
              value: "INFO"
          startupProbe:
            grpc:
              port: 3030
            failureThreshold: 30
            periodSeconds: 1
          readinessProbe:
            exec:
              command: ["/bin/grpc_health_probe", "-addr=:3030"]
            grpc:
              port: 3030
          livenessProbe:
            exec:
              command: ["/bin/grpc_health_probe", "-addr=:3030"]
            grpc:
              port: 3030
          resources:
            requests:
              cpu: 250m
+4 −1
Changes for src/common/method_wrappers/Decorator.py: 4 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -128,7 +128,10 @@ class MetricsPool:
                else:
                    raise Exception('Unsupported metric: {:s}'.format(raw_metric_name)) # pragma: no cover
                metric_data = method_to_metric_fields.setdefault(method_name, dict()).setdefault(metric_name, dict())
                for field_name,labels,value,_,_ in raw_metric_data._child_samples():
                for values in raw_metric_data._child_samples():
                    field_name = values[0]
                    labels = values[1]
                    value = values[2]
                    if field_name == '_bucket': bucket_bounds.add(labels['le'])
                    if len(labels) > 0: field_name = '{:s}:{:s}'.format(field_name, json.dumps(labels, sort_keys=True))
                    metric_data[field_name] = value
+13 −0
Changes for src/common/tools/grpc/Tools.py: 13 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -13,15 +13,28 @@
# limitations under the License.

import json
import warnings
from google import protobuf
from google.protobuf.json_format import MessageToDict

def grpc_message_to_json(
        message, including_default_value_fields=True, preserving_proto_field_name=True, use_integers_for_enums=False
    ):
    if not hasattr(message, 'DESCRIPTOR'): return json.dumps(str(message), sort_keys=True) # not a gRPC message
    if including_default_value_fields is not True:
        warnings.warn(
            "The 'including_default_value_fields' argument is deprecated and will have no effect in future versions.",
            DeprecationWarning,
            stacklevel=2
        )
    if protobuf.__version__ < '4.0.0':
        return MessageToDict(
                message, including_default_value_fields=including_default_value_fields,
                preserving_proto_field_name=preserving_proto_field_name, use_integers_for_enums=use_integers_for_enums)
    else:
        return MessageToDict(
            message,
            preserving_proto_field_name=preserving_proto_field_name, use_integers_for_enums=use_integers_for_enums)

def grpc_message_list_to_json(message_list):
    if message_list is None: return None
+6 −6
Changes for src/context/Dockerfile: 6 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM python:3.9-slim
FROM python:3.13-slim

# Install dependencies
RUN apt-get --yes --quiet --quiet update && \
@@ -23,9 +23,9 @@ RUN apt-get --yes --quiet --quiet update && \
ENV PYTHONUNBUFFERED=0

# Download the gRPC health probe
RUN GRPC_HEALTH_PROBE_VERSION=v0.2.0 && \
    wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 && \
    chmod +x /bin/grpc_health_probe
# RUN GRPC_HEALTH_PROBE_VERSION=v0.4.40 && \
#     wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 && \
#     chmod +x /bin/grpc_health_probe

# Get generic Python packages
RUN python3 -m pip install --upgrade pip
@@ -35,7 +35,7 @@ RUN python3 -m pip install --upgrade pip-tools
# Get common Python packages
# Note: this step enables sharing the previous Docker build steps among all the Python components
WORKDIR /var/teraflow
COPY common_requirements.in common_requirements.in
COPY common_requirements_py313.in common_requirements.in
RUN pip-compile --quiet --output-file=common_requirements.txt common_requirements.in
RUN python3 -m pip install -r common_requirements.txt

@@ -57,7 +57,7 @@ RUN find . -type f -exec sed -i -E 's/^(import\ .*)_pb2/from . \1_pb2/g' {} \;
RUN mkdir -p /var/teraflow/context
WORKDIR /var/teraflow/context
COPY src/context/requirements.in requirements.in
RUN pip-compile --quiet --output-file=requirements.txt requirements.in
RUN pip-compile --quiet --output-file=requirements.txt requirements.in /var/teraflow/common_requirements.in
RUN python3 -m pip install -r requirements.txt

# Add component files into working directory
Loading
Loading