Skip to content

test(bq_driver): add e2e tracing testing#1323

Open
NeerajDwivedii wants to merge 2 commits into
mainfrom
fix_logging_issue
Open

test(bq_driver): add e2e tracing testing#1323
NeerajDwivedii wants to merge 2 commits into
mainfrom
fix_logging_issue

Conversation

@NeerajDwivedii
Copy link
Copy Markdown
Collaborator

@NeerajDwivedii NeerajDwivedii commented Dec 5, 2025

This PR fixes the logging issue that was previously not working. Logging now functions correctly across all platforms and adheres to the tracing priorities defined in the design document. Additionally, max_threads has been initialized to 0 to prevent the Windows error:
Run-Time Check Failure #3 – The variable 'max_threads' is being used without being initialized.

@NeerajDwivedii NeerajDwivedii marked this pull request as ready for review December 5, 2025 16:58
@NeerajDwivedii NeerajDwivedii requested a review from a team December 5, 2025 16:58
int log_file_size;
int max_threads;
bool logging_enabled = false;
int max_threads = 0;
Copy link
Copy Markdown
Collaborator

@sachinpro sachinpro Dec 6, 2025

Choose a reason for hiding this comment

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

The default value of max_threads should be 8.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done

std::string const kLogFileCount = "LogFileCount";
std::string const kLogFileSize = "LogFileSize";
std::string const kMaxThreadsParam = "MaxThreads";
inline std::string const kLogLevel = "LogLevel";
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is this needed to fix the issue in this PR?
I don't understand why these have to be inline.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, this is needed because CreateTraceOptionsFile is invoked multiple times during driver initialization, and in some runs the constant values end up being empty.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why was this not an issue earlier? I don't believe kLogLevel can be empty in any case.

In any case, we should find the root cause. Lets have a call to discuss this.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

it is a case of static initialization fiasco , similar to how static variables should be declared in header file but defined in implementation cc file , in this case either do that or make it inline. stack-over-flow-link

options_file_ = std::shared_ptr<TraceOptions>(new TraceOptions());
}

if (log_level > 0 && logging_enabled) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Did I make some undersirable changes recently? I want to understand where we went wrong.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

No, these unwanted changes were introduced in the last logging PR.

Copy link
Copy Markdown
Collaborator

@sachinpro sachinpro left a comment

Choose a reason for hiding this comment

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

We need comprehensive e2e tests for tracing utilities doing something like:

  1. Setting GOOGLEBIGQUERYODBCINI to a new folder path
  2. Use LOG( macro with a specific testing string.
  3. No error should be thrown whether the path is valid or not.
  4. If the path was valid, check that the first log file was created.
  5. If it was created, check the contents for the testing string we logged in step 2.

On top of this, we need similar test(s) for LogFileCount andLogFileSize too.

@NeerajDwivedii
Copy link
Copy Markdown
Collaborator Author

We need comprehensive e2e tests for tracing utilities doing something like:

  1. Setting GOOGLEBIGQUERYODBCINI to a new folder path
  2. Use LOG( macro with a specific testing string.
  3. No error should be thrown whether the path is valid or not.
  4. If the path was valid, check that the first log file was created.
  5. If it was created, check the contents for the testing string we logged in step 2.

On top of this, we need similar test(s) for LogFileCount andLogFileSize too.

All the points listed above are now being validated in the existing CheckTraceLogFileExist test case, except for points 1 and 3, which will be addressed in a follow-up PR.

Copy link
Copy Markdown
Collaborator

@sachinpro sachinpro left a comment

Choose a reason for hiding this comment

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

I have created a PR #1336 with only the implementation changes because we need to have some working version of tracing.

Lets keep this PR for adding E2E tests for all logging options using GOOGLEBIGQUERYODBCINI

}

// Should have atleast 2 files if rotation worked
EXPECT_LE(log_files.size(), std::stoi(log_file_count));
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

should have used EXPECT_EQ we need to match the same and if same number of files are not coming let's write more atleast more than 2MB(log_file_count * log_file_size) to make sure we are not creating more log file than the count

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Updated the EXPECT_EQ , but kept the log file size at 1 MB. Increasing the max file size would generate more logs, which could lead to test timeouts.

}

TEST(GetOdbcTraceConfigPath, GetDefaultPath) {
auto home = ::google::cloud::internal::GetEnv("GOOGLEBIGQUERYODBCINI");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please document here why this is needed

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done

EXPECT_EQ(6, (*test_opts_file)->max_file_size);
}

#if !defined(_WIN32) && !defined(__APPLE__)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Simplify and add flag for linux only

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done

#endif // _WIN32
}

void UpdateTraceConfig(std::string const& odbc_trace_config,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe you can move this to commons.cc with generic behaviour to update registry entry

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done

std::unordered_map<std::string, std::string> kv;
std::string line;

if (fs::exists(config_path) && fs::is_regular_file(config_path)) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It should not check if file exists or not, it should simply update the entry , rest of the logic also seems unnecessary

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done

if (fs::exists(config_path) && fs::is_regular_file(config_path)) {
std::ifstream input(odbc_trace_config);
ASSERT_TRUE(input.is_open());
std::cout << "check " << std::endl;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

there should not be prints

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Removed


fs::path log_file_path = fs::path(log_path) / "odbcdriverforbigquery_0.log";
log_file = log_file_path.string();
std::cout << "odbc_ini file " << odbc_ini_path << std::endl;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

please remove prints

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Removed

@NeerajDwivedii
Copy link
Copy Markdown
Collaborator Author

@sachinpro PR ready for review

@NeerajDwivedii
Copy link
Copy Markdown
Collaborator Author

@sachinpro PR is ready for review

@NeerajDwivedii
Copy link
Copy Markdown
Collaborator Author

@sachinpro This PR has been pending review since December. It contains required logging changes and needs to be merged.

@sachinpro
Copy link
Copy Markdown
Collaborator

@shivamd-gpartner @NeerajDwivedii Please rebase and clean this PR up.

int const log_file_count = 2;
int const log_file_size = 1024;

// Unique test dir
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Added logic to create an individual googlebigqueryodbc.ini file and directory for log generation, preventing overlap with files used by other git checks, and ensuring they are cleaned up after validation.

@NeerajDwivedii
Copy link
Copy Markdown
Collaborator Author

All previous comments have already been addressed.

Here are the GHA workflow: https://github.com/googleapis/cpp-bigquery-odbc/actions/runs/24875185212

@sachinpro PR ready for review

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.

3 participants