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

enhancement(http source): unifying http query parameters #22242

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

sainad2222
Copy link
Contributor

@sainad2222 sainad2222 commented Jan 18, 2025

Summary

Unifying http query parameters while maintaining backward compatibility. Refer to this for approach

Change Type

  • Bug fix
  • New feature
  • Non-functional (chore, refactoring, docs)
  • Performance

Is this a breaking change?

  • Yes
  • No

How did you test this PR?

sources:
  prom_source:
    endpoints:
      - "http://localhost:9090/federate"
    honor_labels: true
    scrape_interval_secs: 60
    scrape_timeout_secs: 45
    query:
      match[]:
        - '{job="node1"}'
    tls:
      verify_certificate: false
      verify_hostname: false
    type: prometheus_scrape

sinks:
  output:
    type: "console"
    inputs: ["prom_source"]
    target: "stdout"
    encoding:
      codec: "json"

Does this PR include user facing changes?

  • Yes. Please add a changelog fragment based on our guidelines.
  • No. A maintainer will apply the "no-changelog" label to this PR.

Checklist

  • Please read our Vector contributor resources.
    • make check-all is a good command to run locally. This check is
      defined here. Some of these
      checks might not be relevant to your PR. For Rust changes, at the very least you should run:
      • cargo fmt --all
      • cargo clippy --workspace --all-targets -- -D warnings
      • cargo nextest run --workspace (alternatively, you can run cargo test --all)
  • If this PR introduces changes Vector dependencies (modifies Cargo.lock), please
    run dd-rust-license-tool write to regenerate the license inventory and commit the changes (if any). More details here.

References

@sainad2222 sainad2222 requested review from a team as code owners January 18, 2025 19:43
@github-actions github-actions bot added domain: sources Anything related to the Vector's sources domain: sinks Anything related to the Vector's sinks domain: external docs Anything related to Vector's external, public documentation labels Jan 18, 2025
Copy link

@kayayarai kayayarai left a comment

Choose a reason for hiding this comment

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

No docs review required

@sainad2222
Copy link
Contributor Author

@jszwedko Gentle ping :)

Copy link
Member

@jszwedko jszwedko left a comment

Choose a reason for hiding this comment

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

Nice! Thanks for this improvement @sainad2222 ! I think the code looks good. It is a bit unfortunate that the docs don't clearly show that query can be a key/value or key/values. I expect users may end up confused. If you feel up to it, you could try to dig into the docs generation to see if you can adjust it, but I don't think that needs to block this since the current docs also don't really clearly show how the query option is used.

I left a couple of other minor comments below.

@@ -175,7 +175,7 @@ pub struct ElasticsearchConfig {
#[configurable(metadata(docs::advanced))]
#[configurable(metadata(docs::additional_props_description = "A query string parameter."))]
#[configurable(metadata(docs::examples = "query_examples()"))]
Copy link
Member

Choose a reason for hiding this comment

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

It seems like these examples aren't rendering properly on the docs, but that seems to be an existing issue so we don't need to block this.

However, could we add to the examples an example of specifying a single value? I think all existing examples in query_examples() for all of the sources only show specifying an array of values.

Copy link
Member

Choose a reason for hiding this comment

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

As an alternative, you can hand write a small "how it works" section on query params

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi,
@jszwedko This particular example has single value(for elasticsearch sink) only. Did you mean for http_client source? If Yes, I made changes for that now
@pront Where can I write this "how it works" for query params. Any existing reference I can follow? Will it go in .rs files or .cue files?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks this helps. Just to clarify, right now changes are in 3 places

  1. elasticsearch(single params only)
  2. prometheus_scrape(multiple params or single param but query key name should include [])
  3. http_client(generic, so either single param or multiple params)

So Do I need to create how_it_works section individually for each of their cue files with these details along with examples?

Copy link
Member

Choose a reason for hiding this comment

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

Ah good point. It seems we are hitting a lot of doc generation limitations here. I think we should copy paste it in all affected components in this case.

@@ -515,7 +515,7 @@ base: components: sources: http_client: configuration: {
options: "*": {
description: "A query string parameter and it's value(s)."
required: true
type: array: items: type: string: {}
Copy link
Member

Choose a reason for hiding this comment

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

Technically this should indicate that either a string or [string] can be used, but I'm not sure the current cue schema supports this (or if the code that generates the cue from the struct definitions does) 🤔

@sainad2222 sainad2222 requested review from pront and jszwedko January 27, 2025 18:25
@sainad2222 sainad2222 changed the title enhancement(http): unifying http query parameters enhancement(http_client): unifying http query parameters Jan 28, 2025
@sainad2222 sainad2222 changed the title enhancement(http_client): unifying http query parameters enhancement(http source): unifying http query parameters Jan 30, 2025
Copy link
Member

@pront pront left a comment

Choose a reason for hiding this comment

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

👍 from me, would be great to get another review from @jszwedko for UX

Copy link
Member

@jszwedko jszwedko left a comment

Choose a reason for hiding this comment

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

Thanks for adding the examples!

@pront pront enabled auto-merge February 1, 2025 20:31
@sainad2222
Copy link
Contributor Author

@pront Need some help in debugging nats integration test failure. I see two types of errors

publish_and_check failed, expected BuildError::Connect, got: Err(Config { source: CredentialsFileError { source: Custom { kind: InvalidData, error: Error { kind: ChecksumFailure, description: Some("Checksum mismatch") } } } })

and

+ datadog-ci junit upload --service vector target/nextest/default/junit.xml
./scripts/upload-test-results.sh: line 22: datadog-ci: command not found
+ echo 'Failed to upload results'

Second one might be a side effect of first. But I am not sure why integration test may panic because of my changes

@pront
Copy link
Member

pront commented Feb 3, 2025

@pront Need some help in debugging nats integration test failure. I see two types of errors

publish_and_check failed, expected BuildError::Connect, got: Err(Config { source: CredentialsFileError { source: Custom { kind: InvalidData, error: Error { kind: ChecksumFailure, description: Some("Checksum mismatch") } } } })

and

+ datadog-ci junit upload --service vector target/nextest/default/junit.xml
./scripts/upload-test-results.sh: line 22: datadog-ci: command not found
+ echo 'Failed to upload results'

Second one might be a side effect of first. But I am not sure why integration test may panic because of my changes

Hmm, not sure. I rebased on origin/master, if it happens again I will take a closer look.

@sainad2222
Copy link
Contributor Author

@pront Can you trigger workflows too?

@sainad2222
Copy link
Contributor Author

Still failing 🤔 . Can't find any recent PRs that has integration tests run for nats too

@pront
Copy link
Member

pront commented Feb 3, 2025

Still failing 🤔 . Can't find any recent PRs that has integration tests run for nats too

This is probably an unrelated failure. I don't have time right now but I plan to take a look soon. Unless you beat me to it ;)

@pront
Copy link
Member

pront commented Feb 3, 2025

Still failing 🤔 . Can't find any recent PRs that has integration tests run for nats too

This is probably an unrelated failure. I don't have time right now but I plan to take a look soon. Unless you beat me to it ;)

Made a test PR: #22359 (review)

Kicked off a run: https://github.com/vectordotdev/vector/actions/runs/13124105116/job/36616694045?pr=22359

@sainad2222
Copy link
Contributor Author

What's the correct way to run integration tests locally? I tried doing docker-compose -f nats/compose.yaml up and then cargo test --features "nats-integration-tests" sinks::nats::integration_tests::nats_tls_valid but it seems to have tls error this way. Github actions looks to be using vector test runner so couldn't figure out the steps from the logs

Exact error logs

tests logs
thread 'sinks::nats::integration_tests::nats_tls_valid' panicked at src/sinks/nats/integration_tests.rs:313:5:
publish_and_check failed, expected Ok(()), got: Err(Connect { source: Error { kind: Io, source: Some(Custom { kind: InvalidData, error: InvalidMessage(InvalidContentType) }) } })
nats server logs
[nats]                 | [1] 2025/02/04 07:55:48.757058 [DBG] 10.89.3.52:55782 - cid:9 - Client connection created
[nats]                 | [1] 2025/02/04 07:55:48.764665 [TRC] 10.89.3.52:55782 - cid:9 - ->> [-ERR Unknown Protocol Operation]
[nats]                 | [1] 2025/02/04 07:55:48.765445 [ERR] 10.89.3.52:55782 - cid:9 - Client parser ERROR, state=0, i=0: proto='"\x16\x03\x01\x00\xd5\x01\x00\x00\xd1\x03\x03\x11Ҏ\x80<\n\xbe\x81\x9c\x1387C\xe1\x9b1\xeaC\x98\xb3\xf3"...'
[nats]                 | [1] 2025/02/04 07:55:48.765492 [DBG] 10.89.3.52:55782 - cid:9 - Client connection closed: Protocol Violation
[nats]                 | [1] 2025/02/04 07:55:48.767593 [DBG] 10.89.3.52:55784 - cid:10 - Client connection created
[nats]                 | [1] 2025/02/04 07:55:48.769498 [TRC] 10.89.3.52:55784 - cid:10 - ->> [-ERR Unknown Protocol Operation]
[nats]                 | [1] 2025/02/04 07:55:48.769557 [ERR] 10.89.3.52:55784 - cid:10 - Client parser ERROR, state=0, i=0: proto='"\x16\x03\x01\x00\xd5\x01\x00\x00\xd1\x03\x03\x82\xa4rݿ\x9b*\xcdE\x98\x8fo\xc7ր3\x1e\t*\xfa\v"...'
[nats]                 | [1] 2025/02/04 07:55:48.769561 [DBG] 10.89.3.52:55784 - cid:10 - Client connection closed: Protocol Violation

Also might not be related but there is a recent upgrade of async-nats library and integration tests didn't run for that PR too. They got skipped

@pront
Copy link
Member

pront commented Feb 4, 2025

#22359 (review)

You should be able to run with:

scripts/ci-int-e2e-test.sh int nats

I noticed some weirdness, on my run as well. The datadog-e2e-metrics test failed and the nats integration tests did not run (I suppose stopped early because of the first failure).

Running it here:
https://github.com/vectordotdev/vector/actions/runs/13138215406/job/36658665492?pr=22359

@pront
Copy link
Member

pront commented Feb 5, 2025

You can do a git merge origin master and push to pick up the fix. Apologies for the friction here but it exposed an interesting bug.

@sainad2222
Copy link
Contributor Author

splunk tests are taking ~1h. Is it expected to take this time?

@pront
Copy link
Member

pront commented Feb 5, 2025

splunk tests are taking ~1h. Is it expected to take this time?

No, this looks like a regression. The test filter decided to run splunk tests because src/sources/util/http_client.rs was modified and it matches src/sources/util/**

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain: external docs Anything related to Vector's external, public documentation domain: sinks Anything related to the Vector's sinks domain: sources Anything related to the Vector's sources
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unify handling of query for HTTP-based components that support it
4 participants