Understanding the Limitations of 64-Bit integers in Prom-client, Prometheus, Grafana

As WinCC OA natively uses 64-bit long integers in the context of integration with new Node.js manager that leverage JavaScript engine, it is crucial to understand the limitations. This chapter delves into the specific challenges encountered when integrating this values with Prometheus and Grafana.

The Distinction Between `number` and `BigInt` in JavaScript

JavaScript traditionally employs the `number` data type for numeric values, which is based on the IEEE 754 standard for double-precision floating-point numbers. This format allows for the representation of numbers with fractional parts but has limitations when it comes to very large integers:- The `number` data type can accurately represent integers up to 2^53 - 1 (9,007,199,254,740,991). Beyond this threshold, the precision of integer values can no longer be guaranteed. To address the need for handling integers larger than what the `number` type can accommodate, the `BigInt` data type was introduced with the ECMAScript 2020 (ES11) update:- `BigInt` is a newer addition to JavaScript, specifically designed to represent whole numbers larger than 2^53 - 1, without any upper limit. This capability is essential for applications that require high-precision arithmetic on very large integers. Despite its powerful capabilities, the integration of BigInt into the JavaScript ecosystem has encountered challenges. Key tools and libraries, notably Prometheus and Grafana, have yet to fully support BigInt.

Lack of Support in Prometheus, Grafana

Prometheus explicitly does not support BigInt. This decision is outlined in their FAQ, citing the choice to use 64-bit floats to simplify design. Prometheus argues that the IEEE 754 double-precision binary floating-point format, which supports integer precision for values up to 2^53, is sufficient for most use cases. They acknowledge the theoretical possibility of supporting native 64-bit integers and even larger values but do not prioritize it.- Grafana struggles to support BigInt values independently of its integration with Prometheus. This limitation persists even when Grafana connects directly to databases such as InfluxDB® or SQLite®, capable of storing BigInt values.

Implications for WinCC OA Users

The WinCC OA Node.js manager's ability to generate `BigInt` numbers presents challenges. Users expecting precise monitoring and visualization of large integers may encounter inaccuracies for values exceeding 2^53. This can lead to data misinterpretation, with the Prometheus library failing to report any errors. Such limitations necessitate awareness and adaptation strategies for WinCC OA users to mitigate potential impacts on data integrity and analysis.

Strategy for Ensuring Precision

Represent as Strings and Store as Labels: If maintaining full precision is critical e.g. storing a bit field, the simplest workaround is to convert the integer to strings and store them as labels associated with relevant metrics. This method prevents any loss of data accuracy. However, it's important to note that direct visualization of these values will not be feasible.