proto: Problem differentiating not-set value from default value

Abierto
#183 3 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
25/100
Tipo de issue
Nueva funcionalidad
Claridad
Necesita aclaración
Estado de actividad
Estancado

Línea de trabajo

Comienza con proto/openmetrics_data_model.proto alrededor de las líneas 109-123 y revisa la especificación de OpenMetrics Protobuf enlazada. Compara la definición referenciada de Prometheus metrics.proto y los tres enfoques propuestos; después, establece qué comportamiento de presencia de campos debería admitir el esquema y cómo se verificaría la finalización.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Problem

The OpenMetrics Protobuf specification is using the proto3 syntax.

With the proto3 syntax all fields are optional by default. This is not to be confused with null-able. While one can choose not to specify a field it is then represented by its default value. Someone receiving a proto3 encoded payload has no way to tell the difference between a field explicitly set to its default value or not set at all.

The most prominent case where this can be problematic is for boolean fields where both the default value and the not-set value is false. In the context of OpenMetrics, as far as I can tell, one problematic example would be the examplar field in the CounterValue message. A use can not tell the difference between a not-set examplar and an examplar set to 0.

https://github.com/OpenObservability/OpenMetrics/blob/1ff04f252cec929acd9a569fce87b8ec4f72b086/proto/openmetrics_data_model.proto#L109-L123

Solution

To solve the above I see 3 solutions:

  1. The optional keyword, which would allow differentiating between a default value and a not-set value, was initially removed with the proto3 syntax, but has been revived with v3.12.0. In case requiring protoc v3.12.0 is fine, one could just make use of the revived optional keyword.
  2. The optional keyword is just syntactic sugar for oneof. Thus, in case requiring protoc v3.12.0 is not an option, one can use oneof directly. See this stackoverflow answer.
  3. Use proto2 instead of proto3 (see original Prometheus proto definition).
Further reading

What do people think? Do you see alternative approaches?

Given that I don't have much expertise with Protobuf I might be missing something. If so, I would appreciate an answer pointing out my mistake.

Lenguaje dominante
Go
Estrellas
2.5k
Forks
175
Merge medio
1 d 22 h
PR fusionados (30 d)
1

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de prometheus/OpenMetrics

Todos los issues de prometheus/OpenMetrics

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.