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

Can not get rows with "direct use of the package" #3

Closed
hoantv opened this issue Oct 15, 2020 · 3 comments
Closed

Can not get rows with "direct use of the package" #3

hoantv opened this issue Oct 15, 2020 · 3 comments

Comments

@hoantv
Copy link

hoantv commented Oct 15, 2020

I can not comment in closed isue.
continue issue #2
I replaced 25 by 2 (column name and value) but it still error. Here is the code (it worked with modified library)

url := fmt.Sprintf("oracle://%s:%s@%s:%d/%s", "admin", "admin", "localhost", 1521, "test")
	conn, err := go_ora.NewConnection(url)
	if err != nil {
		log.Errorln("Oracle plugin can not connect to instance: ", err)
	}
	err = conn.Open()
	stmt := go_ora.NewStmt("select name,value from v$parameter", conn)
	defer func() {
		err := stmt.Close()
		if err != nil {
			if err != nil {
				log.Errorln("Oracle plugin: can not close stmt", err)
			}

		}
	}()
	rows, err := stmt.Query(nil)
	if (err != nil) {
		log.Errorln("Oracle plugin: can not execute query", err)
	}
	defer func() {
		err := rows.Close()
		if err != nil {
			log.Errorln("Oracle plugin: can not close rows", err)
		}
	}()
	results := make(go_ora.Row, 2)
	for {
		if err == io.EOF {
			break
		}
		err = rows.Next(results)
		for _, result := range results {
			str := fmt.Sprintf("%v", result)
			resultArray := strings.Split(str, " ")
			log.Infoln(resultArray)
		}
	}

Error

panic: runtime error: index out of range [2] with length 2 [recovered]
	panic: runtime error: index out of range [2] with length 2

goroutine 20 [running]:
testing.tRunner.func1(0xc000168200)
	C:/Go/src/testing/testing.go:874 +0x3aa
panic(0xade300, 0xc00017c6e0)
	C:/Go/src/runtime/panic.go:679 +0x1c0
test_project/vendor/github.com/sijms/go-ora.(*DataSet).Next(0xc00016a180, 0xc00016f5e0, 0x2, 0x2, 0xc2ac20, 0xc00016a180)
	D:/src/test_project/vendor/github.com/sijms/go-ora/data_set.go:88 +0x1c1
test_project.TestMetrics1(0xc000168200)
	D:/src/test_project/oracle_exporter_test.go:135 +0x4cb
testing.tRunner(0xc000168200, 0xb6ae00)
	C:/Go/src/testing/testing.go:909 +0xd0
created by testing.(*T).Run
	C:/Go/src/testing/testing.go:960 +0x357

Process finished with exit code 1

if i change "results := make(go_ora.Row, 10)", the result have some duplicate rows.

@hoantv
Copy link
Author

hoantv commented Oct 15, 2020

sorry, the code above is test with modify library. I replace with your lastest library. The result is missing rows. Only has 56 rows while real is 417 rows.

=== RUN   TestMetrics1
time="2020-10-15T15:35:54+07:00" level=info msg="[<nil>]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[<nil>]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[lock_name_space]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[<nil>]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[processes]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[1920]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[sessions]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[2904]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[timed_statistics]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[TRUE]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[timed_os_statistics]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[0]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[resource_limit]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[TRUE]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[license_max_sessions]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[0]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[license_sessions_warning]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[0]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[long_module_action]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[TRUE]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[standby_db_preserve_states]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[NONE]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[instance_abort_delay_time]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[0]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[cpu_count]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[24]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[instance_groups]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[<nil>]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[event]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[<nil>]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[sga_max_size]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[20266876928]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[use_large_pages]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[TRUE]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[pre_page_sga]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[TRUE]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[shared_memory_address]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[0]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[hi_shared_memory_address]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[0]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[lock_sga]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[FALSE]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[processor_group_name]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[<nil>]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[allow_group_access_to_sga]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[FALSE]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[sga_min_size]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[0]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[shared_pool_size]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[0]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[large_pool_size]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[0]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[java_pool_size]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[0]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[streams_pool_size]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[0]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[shared_pool_reserved_size]" source="oracle_exporter_test.go:148"
time="2020-10-15T15:35:54+07:00" level=info msg="[0]" source="oracle_exporter_test.go:148"
--- PASS: TestMetrics1 (0.76s)
PASS

Query in database

SQL> select name,value from v$parameter;

NAME
--------------------------------------------------------------------------------
VALUE
--------------------------------------------------------------------------------
lock_name_space


processes
1920

sessions
2904

...
NAME
--------------------------------------------------------------------------------
VALUE
--------------------------------------------------------------------------------

default_sharing
metadata

pdb_lockdown


shrd_dupl_table_refresh_rate
60

NAME
--------------------------------------------------------------------------------
VALUE
--------------------------------------------------------------------------------


417 rows selected.


@sijms
Copy link
Owner

sijms commented Oct 15, 2020

Thank you for your help
i find the problem:
the problem is strange network behaviour of oracle where it send column count many times in the packet.

What i made is change dataset column count only if the incoming count is more than the stored one thus

if it is ok for you tell me to close the issue

@hoantv
Copy link
Author

hoantv commented Oct 16, 2020

Yeah. It worked perfectly. Thank you :)!

@hoantv hoantv closed this as completed Oct 16, 2020
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

No branches or pull requests

2 participants