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

Add "components" Command #6322

Merged
merged 25 commits into from
Nov 28, 2022
Merged

Conversation

Chinwendu20
Copy link
Contributor

@Chinwendu20 Chinwendu20 commented Oct 15, 2022

Signed-off-by: Maureen amaka013@gmail.com

Description:
Enhancement: Added build command to output components in collector distribution in YAML format

Link to tracking Issue: Closes #4671

Documentation: I would open an issue on opentelemetry.io for the documentation, however, I updated the readme of the service package.

@jpkrohling please check this out

@Chinwendu20
Copy link
Contributor Author

Missed adding the distribution version, adding it now

@Chinwendu20
Copy link
Contributor Author

Chinwendu20 commented Oct 15, 2022

Hi, please I noticed something about the flag, it is always, true. I am fixing that now

Update: Fixed it

Signed-off-by: Maureen <amaka013@gmail.com>
Copy link
Contributor

@codeboten codeboten 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 the contribution @Chinwendu20! Please add a unit test for the new functionality.

Adding entries to the changelog is done via yaml files in the .chloggen directory. Please take a look at https://github.com/open-telemetry/opentelemetry-collector/blob/main/CONTRIBUTING.md#adding-a-changelog-entry for all the details!

service/flags.go Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Oct 17, 2022

Codecov Report

Base: 91.66% // Head: 91.13% // Decreases project coverage by -0.52% ⚠️

Coverage data is based on head (b2bba0b) compared to base (f411094).
Patch coverage: 89.65% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6322      +/-   ##
==========================================
- Coverage   91.66%   91.13%   -0.53%     
==========================================
  Files         240      245       +5     
  Lines       13815    14143     +328     
==========================================
+ Hits        12663    12889     +226     
- Misses        921     1002      +81     
- Partials      231      252      +21     
Impacted Files Coverage Δ
service/command_build_info.go 89.28% <89.28%> (ø)
service/command.go 65.51% <100.00%> (+1.23%) ⬆️
consumer/consumertest/base_consumer.go 0.00% <0.00%> (-100.00%) ⬇️
component/component.go 63.82% <0.00%> (-36.18%) ⬇️
component/componenttest/nop_factories.go 0.00% <0.00%> (-29.42%) ⬇️
processor/batchprocessor/metrics.go 84.71% <0.00%> (-15.29%) ⬇️
receiver/otlpreceiver/internal/logs/otlp.go 87.50% <0.00%> (-12.50%) ⬇️
receiver/otlpreceiver/internal/metrics/otlp.go 87.50% <0.00%> (-12.50%) ⬇️
receiver/otlpreceiver/internal/trace/otlp.go 88.00% <0.00%> (-12.00%) ⬇️
exporter/exporterhelper/obsreport.go 94.91% <0.00%> (-5.09%) ⬇️
... and 45 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@Chinwendu20
Copy link
Contributor Author

I have pushed the new change for the changelog and unit test. I am still waiting for your response to the "logger.info" recommendation, thank you.

@jpkrohling jpkrohling self-requested a review October 18, 2022 20:11
Copy link
Member

@jpkrohling jpkrohling left a comment

Choose a reason for hiding this comment

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

I tried it locally and this is what I got:

$ ./bin/otelcorecol_linux_amd64 --build-info
version: 0.62.1-dev
receivers:
    - otlp
processors:
    - batch
    - memory_limiter
exporters:
    - otlphttp
    - logging
    - otlp
extensions:
    - memory_ballast
    - zpages

This looks nice!

service/flags.go Outdated
)

var (
// Command-line flag that control the configuration file.
gatesList = featuregate.FlagValue{}
BuildFlag bool
Copy link
Member

Choose a reason for hiding this comment

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

This should not be public

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, thanks. I would be changing that.

service/flags.go Outdated
"strings"

"fmt"
"go.opentelemetry.io/collector/config"
Copy link
Member

Choose a reason for hiding this comment

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

I wonder why the linter didn't catch this. The import order seems odd.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I ran gofmt -w . on the project. This is how it looks:
image
Should I look up correct import order and implement changes manually if this is not in line?

Copy link
Member

Choose a reason for hiding this comment

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

Run make lint and see if it complains. I expect it to complain with something like this:

service/flags.go:20: File is not `goimports`-ed with -local go.opentelemetry.io/collector (goimports)
	"fmt"

You can then run the following command to fix it automatically for you:

make fmt

service/flags.go Outdated
)

type configFlagValue struct {
values []string
sets []string
}

type componentsOutput struct {
Version string

Copy link
Member

Choose a reason for hiding this comment

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

Can you remove the extraneous empty lines?

Copy link
Contributor Author

@Chinwendu20 Chinwendu20 Oct 19, 2022

Choose a reason for hiding this comment

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

Ok, changing that. Thanks

service/flags.go Outdated Show resolved Hide resolved
service/flags.go Outdated
components.Version = set.BuildInfo.Version

yamlData, err := yaml.Marshal(components)

Copy link
Member

Choose a reason for hiding this comment

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

Remove this empty line, keeping the error check close to where the error is received.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, thank you. On it.

service/flags.go Outdated Show resolved Hide resolved
}
ExpectedYamlStruct := componentsOutput{
Version: "latest",

Copy link
Member

Choose a reason for hiding this comment

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

Reconsider the empty lines here as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok thank you

@jpkrohling jpkrohling changed the title Fixes #4671 Add "build-info" flag Oct 19, 2022
service/command.go Outdated Show resolved Hide resolved
@Chinwendu20
Copy link
Contributor Author

I tried it locally and this is what I got:

$ ./bin/otelcorecol_linux_amd64 --build-info
version: 0.62.1-dev
receivers:
    - otlp
processors:
    - batch
    - memory_limiter
exporters:
    - otlphttp
    - logging
    - otlp
extensions:
    - memory_ballast
    - zpages

This looks nice!

Thank youu

Co-authored-by: Juraci Paixão Kröhling <juraci.github@kroehling.de>
@jpkrohling
Copy link
Member

Once this is ready for review again, please ping me. Note that there's a merge conflict now that needs to be solved.

@Chinwendu20
Copy link
Contributor Author

Okay, thank you. On it.

Signed-off-by: Maureen <amaka013@gmail.com>
Signed-off-by: Maureen <amaka013@gmail.com>
Signed-off-by: Maureen <amaka013@gmail.com>
@Chinwendu20
Copy link
Contributor Author

Thanks @jpkrohling. I have pushed with the changes.

@Chinwendu20
Copy link
Contributor Author

Oh missed writing a test. I would push that soon

Signed-off-by: Maureen <amaka013@gmail.com>
@Chinwendu20
Copy link
Contributor Author

Chinwendu20 commented Oct 20, 2022

I have pushed with the test @jpkrohling

@Chinwendu20 Chinwendu20 changed the title Add "build-info" flag Add "build-info" Command Oct 20, 2022
Signed-off-by: Maureen <amaka013@gmail.com>
Copy link
Member

@jpkrohling jpkrohling left a comment

Choose a reason for hiding this comment

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

This looks good to me, but @Aneurysm9 and @codeboten had comments as well, I would want to request their approval in addition to mine.


"github.com/spf13/cobra"
"gopkg.in/yaml.v3"

"go.opentelemetry.io/collector/config"

Copy link
Member

Choose a reason for hiding this comment

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

Those two imports should be together (go.opentelemetry.io/collector/...) but I think the linter will tell you that as well :-)

Copy link
Member

Choose a reason for hiding this comment

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

It does

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 I attempted putting them together but when I ran "make fmt", it sorted them back in this order

@Chinwendu20
Copy link
Contributor Author

Thank you all for your time and patience with me. I have fixed the lint test but the build test, am afraid would still fail. I ran "make test" locally and it fails probably because there is no test in the telemetry package. I would need your guidance:

image
Similar to what is happening on the CI: https://github.com/open-telemetry/opentelemetry-collector/actions/runs/3414103074/jobs/5682633344

Signed-off-by: Maureen <amaka013@gmail.com>
Copy link
Contributor

@codeboten codeboten left a comment

Choose a reason for hiding this comment

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

You can see the issue here:

=== RUN   TestNewBuildSubCommand
==================
WARNING: DATA RACE
Write at 0x00c000209b50 by goroutine 17:
  go.opentelemetry.io/collector/service.TestNewBuildSubCommand.func1()
      /home/runner/work/opentelemetry-collector/opentelemetry-collector/service/command_build_info_test.go:73 +0xdd

Previous write at 0x00c000209b50 by goroutine 42:
  go.opentelemetry.io/collector/service.TestNewBuildSubCommand()
      /home/runner/work/opentelemetry-collector/opentelemetry-collector/service/command_build_info_test.go:78 +0xce4
  testing.tRunner()
      /opt/hostedtoolcache/go/1.18.7/x64/src/testing/testing.go:1439 +0x213
  testing.(*T).Run.func1()
      /opt/hostedtoolcache/go/1.18.7/x64/src/testing/testing.go:1486 +0x47

Goroutine 17 (running) created at:
  go.opentelemetry.io/collector/service.TestNewBuildSubCommand()
      /home/runner/work/opentelemetry-collector/opentelemetry-collector/service/command_build_info_test.go:71 +0xc85
  testing.tRunner()
      /opt/hostedtoolcache/go/1.18.7/x64/src/testing/testing.go:1439 +0x213
  testing.(*T).Run.func1()
      /opt/hostedtoolcache/go/1.18.7/x64/src/testing/testing.go:1486 +0x47

Goroutine 42 (running) created at:
  testing.(*T).Run()
      /opt/hostedtoolcache/go/1.18.7/x64/src/testing/testing.go:1486 +0x724
  testing.runTests.func1()
      /opt/hostedtoolcache/go/1.18.7/x64/src/testing/testing.go:1839 +0x99
  testing.tRunner()
      /opt/hostedtoolcache/go/1.18.7/x64/src/testing/testing.go:1439 +0x213
  testing.runTests()
      /opt/hostedtoolcache/go/1.18.7/x64/src/testing/testing.go:1837 +0x7e4
  testing.(*M).Run()
      /opt/hostedtoolcache/go/1.18.7/x64/src/testing/testing.go:1719 +0xa71
  main.main()
      _testmain.go:113 +0x2e4
==================

@Chinwendu20
Copy link
Contributor Author

Wow that is new. I would look into it

Signed-off-by: Maureen <amaka013@gmail.com>
@Chinwendu20
Copy link
Contributor Author

Thank you so much @codeboten. I have pushed a commit that should fix the error that you referenced but what I commented about the command, "make test" still stands, please look at my most recent screenshot. The codecov test also fails but I have written a test for my feature, any advice?

@codeboten
Copy link
Contributor

@Chinwendu20 I've submitted a change to your PR to use cmd.OutOrStdout to print to stdout. It allows us to use the cmd.SetOut() functionality in cobra to simplify the test and avoid the race condition. Please take a look!

@Chinwendu20
Copy link
Contributor Author

Thank you. The unit tests are passing now. I will fix the lint test

Signed-off-by: Maureen <amaka013@gmail.com>
@codeboten codeboten changed the title Add "build-info" Command Add "components" Command Nov 28, 2022
Copy link
Contributor

@codeboten codeboten 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 all the work @Chinwendu20!

@codeboten codeboten merged commit dbe9e67 into open-telemetry:main Nov 28, 2022
codeboten pushed a commit to codeboten/opentelemetry-collector that referenced this pull request Nov 28, 2022
codeboten pushed a commit that referenced this pull request Nov 28, 2022
Bit of cleanup left over from #6322.
@Chinwendu20
Copy link
Contributor Author

Hello, please I would like to push a commit updating the readme with the correct command name and I would also like to update the file name of the command

@jpkrohling
Copy link
Member

@Chinwendu20, please open a new PR with the new commit.

@Chinwendu20
Copy link
Contributor Author

Okay thank you

jaronoff97 pushed a commit to lightstep/opentelemetry-collector that referenced this pull request Dec 14, 2022
 Enhancement: Added build command to output components in collector distribution in YAML format

Signed-off-by: Maureen <amaka013@gmail.com>
Co-authored-by: Juraci Paixão Kröhling <juraci.github@kroehling.de>
Co-authored-by: Alex Boten <aboten@lightstep.com>
jaronoff97 pushed a commit to lightstep/opentelemetry-collector that referenced this pull request Dec 14, 2022
jaronoff97 pushed a commit to lightstep/opentelemetry-collector that referenced this pull request Dec 14, 2022
 Enhancement: Added build command to output components in collector distribution in YAML format

Signed-off-by: Maureen <amaka013@gmail.com>
Co-authored-by: Juraci Paixão Kröhling <juraci.github@kroehling.de>
Co-authored-by: Alex Boten <aboten@lightstep.com>
jaronoff97 pushed a commit to lightstep/opentelemetry-collector that referenced this pull request Dec 14, 2022
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.

Build info flag
5 participants