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

Code cleanup and refactoring #43

Merged
merged 10 commits into from
Apr 6, 2022
Merged

Code cleanup and refactoring #43

merged 10 commits into from
Apr 6, 2022

Conversation

ywwg
Copy link
Contributor

@ywwg ywwg commented Apr 5, 2022

  • Add support for handling SIGTERM signal
  • Refactor Run function into api module instead of binary so it can be called from e2e tests without needing to start up the binary itself.
  • Add wrappers for error and warning logging so we don't need to keep ignoring the return value

@grafanabot

This comment has been minimized.

1 similar comment
@grafanabot

This comment has been minimized.

@carrieedwards
Copy link
Contributor

I think the sigterm handling needs to change a bit if we use the pkg/server instead of the weaveworks/common server, since pkg/server doesn't have its own SignalHandler interface

@ywwg
Copy link
Contributor Author

ywwg commented Apr 5, 2022

ok I'll update after your change goes in

@ywwg ywwg changed the title Handle SIGTERM Code cleanup and refactoring Apr 6, 2022
@grafanabot

This comment has been minimized.

@ywwg
Copy link
Contributor Author

ywwg commented Apr 6, 2022

hand-tested on the command line, works

@grafanabot

This comment has been minimized.

leizor
leizor previously approved these changes Apr 6, 2022
Copy link
Contributor

@leizor leizor left a comment

Choose a reason for hiding this comment

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

I like the new logging layer!

// Error logs an error and panics if the log call itself had an error.
func Error(logger log.Logger, keyvals ...interface{}) {
if err := level.Error(logger).Log(keyvals); err != nil {
panic(fmt.Sprintf("error writing to log: %v", err))
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious - why %v and not %w?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh yeah I can do that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually I can't! %w is only supported in fmt.Errorf

Copy link
Contributor

Choose a reason for hiding this comment

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

Ohh gotcha, interesting

@ywwg
Copy link
Contributor Author

ywwg commented Apr 6, 2022

oh hm %w doesn't work in sprintf

@ywwg
Copy link
Contributor Author

ywwg commented Apr 6, 2022

looks like I broke tests so I'll do that after lunch

@grafanabot
Copy link

Go coverage report:

Click to expand.
File %
github.com/grafana/influx2cortex/pkg/errorx/errors.go 67.3%
github.com/grafana/influx2cortex/pkg/errorx/http_translator.go 100.0%
github.com/grafana/influx2cortex/pkg/influx/api.go 38.3%
github.com/grafana/influx2cortex/pkg/influx/errors.go 100.0%
github.com/grafana/influx2cortex/pkg/influx/parser.go 84.1%
github.com/grafana/influx2cortex/pkg/influx/recorder.go 91.7%
github.com/grafana/influx2cortex/pkg/remotewrite/client.go 69.1%
github.com/grafana/influx2cortex/pkg/remotewrite/measured_client.go 88.9%
github.com/grafana/influx2cortex/pkg/remotewrite/recorder.go 100.0%
github.com/grafana/influx2cortex/pkg/route/registerer.go 100.0%
github.com/grafana/influx2cortex/pkg/server/middleware/http_auth.go 0.0%
github.com/grafana/influx2cortex/pkg/server/middleware/http_fake_auth.go 0.0%
github.com/grafana/influx2cortex/pkg/server/middleware/instrument.go 6.7%
github.com/grafana/influx2cortex/pkg/server/middleware/logging.go 69.7%
github.com/grafana/influx2cortex/pkg/server/middleware/middleware.go 0.0%
github.com/grafana/influx2cortex/pkg/server/middleware/request_limits.go 81.8%
github.com/grafana/influx2cortex/pkg/server/middleware/response.go 57.1%
github.com/grafana/influx2cortex/pkg/server/middleware/route_matcher.go 0.0%
github.com/grafana/influx2cortex/pkg/server/middleware/tracer.go 13.0%
github.com/grafana/influx2cortex/pkg/server/server.go 83.3%
github.com/grafana/influx2cortex/pkg/tenant/resolver.go 75.6%
github.com/grafana/influx2cortex/pkg/tenant/tenant.go 91.7%
github.com/grafana/influx2cortex/pkg/util/bytereplacer/byte_replacer.go 100.0%
github.com/grafana/influx2cortex/pkg/util/extract_forwarded.go 66.7%
github.com/grafana/influx2cortex/pkg/util/http.go 68.3%
github.com/grafana/influx2cortex/pkg/util/log/experimental.go 0.0%
github.com/grafana/influx2cortex/pkg/util/log/log.go 0.0%
github.com/grafana/influx2cortex/pkg/util/log/rate_limit.go 90.0%
github.com/grafana/influx2cortex/pkg/util/log/wrappers.go 0.0%
github.com/grafana/influx2cortex/pkg/util/push/push.go 60.0%
total 63.1%

Go lint report:

No issues found. 😎

Copy link
Contributor

@carrieedwards carrieedwards left a comment

Choose a reason for hiding this comment

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

Looks great!

@ywwg ywwg merged commit 0986dd8 into main Apr 6, 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.

None yet

4 participants