Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib/protoparser: adds opentelemetry parser #2570

Merged
merged 7 commits into from Jul 27, 2023
Merged

Conversation

f41gh7
Copy link
Contributor

@f41gh7 f41gh7 commented May 11, 2022

app/{vmagent,vminsert}: adds opentelemetry ingestion path

Adds ability to ingest data with opentelemetry protocol
protobuf and json encoding is supported
data converted into prometheus protobuf timeseries
each data type has own converter and it may produce multiple timeseries
from single datapoint (for summary and histogram).
only cumulative aggregationFamily is supported for sum(prometheus
counter) and histogram.

For #2424

@f41gh7 f41gh7 marked this pull request as ready for review May 11, 2022 19:23
@f41gh7 f41gh7 requested review from valyala and hagen1778 May 11, 2022 19:23
Copy link
Collaborator

@hagen1778 hagen1778 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
app/vminsert/opentelemetryhttp/request_handler.go Outdated Show resolved Hide resolved
@f41gh7 f41gh7 force-pushed the adds-opentelemetry branch 2 times, most recently from 0439bdf to 88c4b16 Compare June 2, 2022 16:30
@codecov
Copy link

codecov bot commented Jun 2, 2022

Codecov Report

Patch coverage: 76.09% and project coverage change: -3.48% ⚠️

Comparison is base (7e5555f) 61.06% compared to head (532ec90) 57.58%.
Report is 1 commits behind head on master.

❗ Current head 532ec90 differs from pull request most recent head 4ae796f. Consider uploading reports for the commit 4ae796f to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2570      +/-   ##
==========================================
- Coverage   61.06%   57.58%   -3.48%     
==========================================
  Files         385      310      -75     
  Lines       71951    52184   -19767     
==========================================
- Hits        43939    30052   -13887     
+ Misses      25605    20237    -5368     
+ Partials     2407     1895     -512     
Files Changed Coverage Δ
lib/protoparser/opentelemetry/streamparser.go 76.09% <76.09%> (ø)

... and 280 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@hagen1778 hagen1778 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@valyala
Copy link
Collaborator

valyala commented Aug 22, 2022

This pull request increases VictoriaMetrics binary size from 19MB to 29MB, e.g. by around 50%. This is too big price to pay for the inclusion of OpenTelemetry-compatible JSON and protobuf data ingestion protocols :( All the existing data ingestion protocols supported by VictoriaMetrics increase binary size by a few tens of kilobytes in worst case. It would be great trying to decrease the binary size overhead for this change before merging it into VictoriaMetrics.

In the mean time it is possible to export data from OpenTelemetry collector client to VictoriaMetrics via one of the supported data ingestion protocols:

Copy link
Collaborator

@valyala valyala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rodrigc
Copy link
Contributor

rodrigc commented Sep 15, 2022

@valyala might be nice to add to the VictoriaMetrics docs, some
example configs (or pointers to configs in OpenTelemetry docs) for configuring an OpenTelemetry client to push to VictoriaMetrics via the various protocols you mentioned. That way end-users would have a better idea how to configure OpenTelemetry to push to VictoriaMetrics. If the existing protocols work well enough, then a native OLTP ingest path may not be necessary.

If native OLTP could be implemented without increasing the footprint requirements for VictoriaMetrics, that would be nice too, but is a longer discussion/implementation.

@syepes
Copy link
Contributor

syepes commented Sep 16, 2022

+1 Hope you can find a solution to this one, this would be a great addition.

@syepes
Copy link
Contributor

syepes commented Nov 8, 2022

@f41gh7 Is there any news on the merger of this feature? it would be great to have native support for this new protocol

@PatMis16
Copy link

Hi VictoriaMetrics Developers!
How about this feture with the OpenTelemetry protocol? Is there a planned release date for this?

@f41gh7
Copy link
Contributor Author

f41gh7 commented Nov 22, 2022

Will take a look and update dependency soon.

@f41gh7
Copy link
Contributor Author

f41gh7 commented Nov 29, 2022

@valyala PR was updated, but any way it increases result binary size by 5MB because of protobuf json parser dependencies. It's possible to optimize it further, but I'm not sure, that it worth it.

@f41gh7 f41gh7 requested a review from valyala November 29, 2022 18:31
@valyala
Copy link
Collaborator

valyala commented Dec 14, 2022

PR was updated, but any way it increases result binary size by 5MB because of protobuf json parser dependencies. It's possible to optimize it further, but I'm not sure, that it worth it.

+5MB is better than +10MB from the previous attempt, but is is still too much for a simple parser for metrics in OpenTelemetry protocol when comparing to binary footprints for other data ingestion protocols supported by VictoriaMetrics :(

I believe we can write our own implementation for the OpenTelemetry metrics parser, which will increase the resulting binary size by no more than 100Kb in the worst case.

@f41gh7
Copy link
Contributor Author

f41gh7 commented Dec 28, 2022

@valyala changed implementation - rewritten parser from scratch with default protobuf generator. Produced binary size almost the same as it was before adding this feature.

@syepes
Copy link
Contributor

syepes commented Jan 6, 2023

@f41gh7 Do you guys have an rough idea when you will be releasing a version with this?

@valyala
Copy link
Collaborator

valyala commented Jan 10, 2023

Do you guys have an rough idea when you will be releasing a version with this?

We had plans to merge this pull request in the upcoming v1.86.0 release, but it won't be included there because of issues with the increased binary size :( The latest version of the pull request still increases VictoriaMetrics binary size by 4MiB from 19MiB to 23MiB. I hope these issues will be resolved until the next release, so the support for OpenTelemetry protocol will be added into the next release after v1.86.0.

Side note: the OpenTelemetry metrics protocol specification is an over-engineered nightmare comparing to other popular data ingestion formats such as Influx line protocol, Graphite plaintext protocol and Prometheus text exposition format. This introduces non-trivial overhead to users, clients and server, which have to deal with it. For example, a simple temperature{job="vm",label1="value1"} 15 metric transforms into the following monster when being transferred with OpenTelemetry metrics JSON format:

{
  "resourceMetrics": [
    {
      "resource": {
        "attributes": [
          {
            "key": "job",
            "value": {
              "stringValue": "vm"
            }
          }
        ]
      },
      "scopeMetrics": [
        {
          "metrics": [
            {
              "name": "temperature",
              "gauge": {
                "dataPoints": [
                  {
                    "attributes": [
                      {
                        "key": "label1",
                        "value": {
                          "stringValue": "value1"
                        }
                      }
                    ],
                    "asInt": "15"
                  }
                ]
              }
            }
          ]
        }
      ]
    }
  ]
}

@f41gh7
Copy link
Contributor Author

f41gh7 commented Feb 27, 2023

@valyala changed proto compiler. Without any external dependency it increases binary size for 1MB approx.

@hagen1778
Copy link
Collaborator

Without any external dependency it increases binary size for 1MB approx.

not all heroes wear capes)

@rodrigc
Copy link
Contributor

rodrigc commented Mar 11, 2023

@hagen1778 @f41gh7 Small PR to fix the lint issues in this branch: #3943

@PatMis16
Copy link

Great work guys! Hope this is comming soon.

@syepes
Copy link
Contributor

syepes commented Apr 14, 2023

Any good news on this merger?

@zahdab
Copy link

zahdab commented May 16, 2023

Any update on this by any chance?

@f41gh7 f41gh7 force-pushed the adds-opentelemetry branch 2 times, most recently from 85a3381 to 8d10087 Compare June 26, 2023 08:24
app/{vmagent,vminsert}: adds opentelemetry ingestion path

Adds ability to ingest data with opentelemetry protocol
protobuf and json encoding is supported
data converted into prometheus protobuf timeseries
each data type has own converter and it may produce multiple timeseries
from single datapoint (for summary and histogram).
only cumulative aggregationFamily is supported for sum(prometheus
counter) and histogram.

Apply suggestions from code review

Co-authored-by: Roman Khavronenko <roman@victoriametrics.com>

updates deps

fixes tests

wip

wip

wip

wip

lib/protoparser/opentelemetry: moves to vtprotobuf generator

go mod vendor

lib/protoparse/opentelemetry: reduce memory allocations
@syepes
Copy link
Contributor

syepes commented Jun 26, 2023

Closer and closer to have this merged, there will be a big party for this one 🥳

@Cho1409
Copy link

Cho1409 commented Jul 17, 2023

I hope to see some updates soon.

- Remove support for JSON parsing, since it is too fragile and is rarely used in practice.
  The most clients send OpenTelemetry metrics in protobuf.
  The JSON parser can be added in the future if needed.
- Remove unused code from lib/protoparser/opentelemetry/pb and lib/protoparser/opentelemetry/proto
- Do not re-use protobuf message between ParseStream() calls, since there is high chance
  of high fragmentation of the re-used message because of too complex nested structure of the message.
@valyala valyala merged commit 46ecbbe into master Jul 27, 2023
6 checks passed
@valyala valyala deleted the adds-opentelemetry branch July 27, 2023 20:26
@valyala
Copy link
Collaborator

valyala commented Jul 27, 2023

@f41gh7 , thanks for the pull request!

valyala added a commit that referenced this pull request Jul 27, 2023
* lib/protoparser: adds opentelemetry parser
app/{vmagent,vminsert}: adds opentelemetry ingestion path

Adds ability to ingest data with opentelemetry protocol
protobuf and json encoding is supported
data converted into prometheus protobuf timeseries
each data type has own converter and it may produce multiple timeseries
from single datapoint (for summary and histogram).
only cumulative aggregationFamily is supported for sum(prometheus
counter) and histogram.

Apply suggestions from code review

Co-authored-by: Roman Khavronenko <roman@victoriametrics.com>

updates deps

fixes tests

wip

wip

wip

wip

lib/protoparser/opentelemetry: moves to vtprotobuf generator

go mod vendor

lib/protoparse/opentelemetry: reduce memory allocations

* wip

- Remove support for JSON parsing, since it is too fragile and is rarely used in practice.
  The most clients send OpenTelemetry metrics in protobuf.
  The JSON parser can be added in the future if needed.
- Remove unused code from lib/protoparser/opentelemetry/pb and lib/protoparser/opentelemetry/proto
- Do not re-use protobuf message between ParseStream() calls, since there is high chance
  of high fragmentation of the re-used message because of too complex nested structure of the message.

* wip

* wip

* wip

---------

Co-authored-by: Aliaksandr Valialkin <valyala@victoriametrics.com>
@hagen1778
Copy link
Collaborator

No way!

@valyala
Copy link
Collaborator

valyala commented Jul 28, 2023

FYI, this pull request has been included in VictoriaMetrics v1.92.0.

@sumukhs
Copy link

sumukhs commented Aug 1, 2023

Hi @valyala ,

When I use opentelemetry-sdk python version 1.19.0 and generate a few metrics in json and try to push this to Victoria Metrics instance version v1.92.0 I see an error like this:

2023-08-01T22:43:01.654Z        warn    VictoriaMetrics/app/vminsert/main.go:218        remoteAddr: "172.17.0.1:45372"; requestURI: /opentelemetry/api/v1/push; cannot unpack OpenTelemetry metrics: cannot unmarshal request from 4738 bytes: proto: illegal wireType 6

The way I get the json data for the metrics is by dumping the state in a file like this:

    reader = InMemoryMetricReader()
    provider = MeterProvider(metric_readers=[reader])
    set_meter_provider(provider)

    meter = get_meter_provider().get_meter("MIT-Metrics", "0.1.2")
    state = reader.get_metrics_data().to_json()
    logging.info(f"State:\n {state}")
    with open(output_file, "w") as f:
        json.dump(state, f)

Is this a supported way of reporting metrics into Victoria metrics?

@f41gh7
Copy link
Contributor Author

f41gh7 commented Aug 3, 2023

@sumukhs VictoriaMetrics supports opentelemetry only with protobuf encoding. json isn't supported atm.

@valyala
Copy link
Collaborator

valyala commented Aug 12, 2023

FYI, VictoriaMetrics v1.93.0 has the following enhancements for Opentelemetry:

  1. It returns user-readable error on an attempt to push OTEL metrics with unsupported encoding. See this pull request.
  2. It prevents from panic when pushing histograms with non-counter buckets. See this issue for details.

valyala added a commit that referenced this pull request Jan 14, 2024
…to for protobuf message unmarshaling and marshaling

This reduces VictoriaMetrics binary size by 100KB.

Updates #2570
Updates #2424
@valyala
Copy link
Collaborator

valyala commented Jan 14, 2024

FYI, the commit dd25049 switches parsing of OTEL protobuf messages from protoc-generated code to github.com/VictoriaMetrics/easyproto. This reduces code bloat and binary bloat (VictoriaMetrics binary size has been reduced by 100KB on top of this change), and improves maintainability of the resulting code. This commit will be included in the next release of VictoriaMetrics.

valyala added a commit that referenced this pull request Jan 16, 2024
…to for protobuf message unmarshaling and marshaling

This reduces VictoriaMetrics binary size by 100KB.

Updates #2570
Updates #2424
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants