Skip to content

Conversation

dveeden
Copy link
Contributor

@dveeden dveeden commented Sep 4, 2025

What problem does this PR solve?

Issue Number: close #855

Problem Summary:

Logging is setup based with the generic NewConfig() and used during the initial parsing of the config file. Then later the watcher is correcting things where needed. However the encoder isn't changed. This results in the encoder from the config to be ignored.

What is changed and how it works:

  1. Change the reading of the config to not use the logger at all. Messages might now go to stderr instead.
  2. Delay the setup of logger until we have a config.
  3. Print the config once we have the config and a logger.

As indicated for the changes in TestChecksum:

  • With these changes the config isn't printed again when it changes
  • The printing of the config is done in a different part of the code.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Notable changes

  • Has configuration change
  • Has HTTP API interfaces change
  • Has tiproxyctl change
  • Other user behavior changes

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

Handling of the log encoder was corrected.

Copy link

ti-chi-bot bot commented Sep 4, 2025

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

Copy link

ti-chi-bot bot commented Sep 4, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign djshow832 for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot requested review from bb7133 and xhebox September 4, 2025 07:54
@ti-chi-bot ti-chi-bot bot added the size/M label Sep 4, 2025
@dveeden
Copy link
Contributor Author

dveeden commented Sep 4, 2025

/cc @djshow832

@ti-chi-bot ti-chi-bot bot requested a review from djshow832 September 4, 2025 07:54
@dveeden dveeden marked this pull request as ready for review September 4, 2025 07:54
@dveeden
Copy link
Contributor Author

dveeden commented Sep 4, 2025

This should probably get some more tests:

  • With a logfile configured there should not be any output to stdout
  • With a json encoder configured the output should parse as valid json

@dveeden
Copy link
Contributor Author

dveeden commented Sep 4, 2025

$ ./bin/tiproxy --config=<(echo -en '[log]\nencoder = "json"\n') | head -1 | jq .
{
  "level": "INFO",
  "ts": "2025/09/04 10:00:58.199 +02:00",
  "logger": "main",
  "caller": "server/server.go:220",
  "msg": "Welcome to TiProxy.",
  "Release Version": "v1.4.0-beta.1-32-gd3f8304-dirty",
  "Git Commit Hash": "d3f830449f31e989e170340f6edc4627c0a09baa-dirty",
  "Git Branch": "main",
  "UTC Build Time": "2025-09-04 07:45:15",
  "GoVersion": "go1.24.6",
  "OS": "linux",
  "Arch": "amd64"
}

And with the current main branch:

dvaneeden@dve-carbon:~/dev/pingcap/tiproxy$ ./bin/tiproxy --config=<(echo -en '[log]\nencoder = "json"\n') | head -1 | jq .
jq: parse error: Invalid numeric literal at line 1, column 12
dvaneeden@dve-carbon:~/dev/pingcap/tiproxy$ ./bin/tiproxy --config=<(echo -en '[log]\nencoder = "json"\n') | head -1
[2025/09/04 10:02:05.431 +02:00] [INFO] [main.config] [config/config.go:71] [current config]  [cfg="{\"proxy\":{\"addr\":\"0.0.0.0:6000\",\"pd-addrs\":\"127.0.0.1:2379\",\"frontend-keepalive\":{\"enabled\":true},\"backend-healthy-keepalive\":{\"enabled\":true,\"idle\":60000000000,\"cnt\":5,\"intvl\":3000000000,\"timeout\":15000000000},\"backend-unhealthy-keepalive\":{\"enabled\":true,\"idle\":10000000000,\"cnt\":5,\"intvl\":1000000000,\"timeout\":5000000000},\"graceful-close-conn-timeout\":15},\"api\":{\"addr\":\"0.0.0.0:3080\"},\"workdir\":\"/home/dvaneeden/dev/pingcap/tiproxy/work\",\"security\":{\"server-tls\":{\"min-tls-version\":\"1.2\"},\"server-http-tls\":{\"min-tls-version\":\"1.2\"},\"cluster-tls\":{\"min-tls-version\":\"1.2\"},\"sql-tls\":{\"min-tls-version\":\"1.2\"}},\"log\":{\"encoder\":\"json\",\"level\":\"info\",\"log-file\":{\"max-size\":300,\"max-days\":3,\"max-backups\":3}},\"balance\":{\"policy\":\"resource\"},\"ha\":{},\"enable-traffic-replay\":true}"]

@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 83.33333% with 2 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@d3f8304). Learn more about missing BASE report.

Files with missing lines Patch % Lines
pkg/server/server.go 80.00% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #856   +/-   ##
=======================================
  Coverage        ?   67.09%           
=======================================
  Files           ?      129           
  Lines           ?    12261           
  Branches        ?        0           
=======================================
  Hits            ?     8226           
  Misses          ?     3451           
  Partials        ?      584           
Flag Coverage Δ
unit 67.09% <83.33%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

djshow832

This comment was marked as outdated.

@@ -68,7 +67,6 @@ func (e *ConfigManager) SetTOMLConfig(data []byte) (err error) {
if originalData == nil || !bytes.Equal(originalData, newData) {
e.sts.checksum = crc32.ChecksumIEEE(newData)
e.sts.data = newData
e.logger.Info("current config", zap.Any("cfg", e.sts.current))
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's crucial to print the config every time it changes. You can print it when the loggerManager watches a config change instead.

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

Successfully merging this pull request may close these issues.

Log encoder not picked up from config file
3 participants