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

Index out of range #121

Closed
JackyWoo opened this issue Apr 25, 2024 · 6 comments · Fixed by #122
Closed

Index out of range #121

JackyWoo opened this issue Apr 25, 2024 · 6 comments · Fixed by #122

Comments

@JackyWoo
Copy link
Contributor

JackyWoo commented Apr 25, 2024

Build with latest master branch

go version
go version go1.21.6 linux/amd64

And run as

clickhouse-flamegraph --clickhouse-dsn xx@xx/default --query-id 7d6b01fa-89f0-4eaf-9d4b-e273a6e9ee84 --flamegraph-script /data1/home/wujianchao/cmd/FlameGraph --output-dir .  --trace-type CPU --format svg --debug

But got index out of range

{"level":"info","dsn":"xxxx","time":"2024-04-25T15:10:54+08:00","message":"connected to ClickHouse"}
panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
github.com/mailru/go-clickhouse/v2.ensureHavePort({0x0, 0x0})
	/data1/home/wujianchao/go/pkg/mod/github.com/mailru/go-clickhouse/v2@v2.1.0/config.go:187 +0x13f
github.com/mailru/go-clickhouse/v2.(*Config).url(0xc000174580, 0xc00023ced8?, 0x0)
	/data1/home/wujianchao/go/pkg/mod/github.com/mailru/go-clickhouse/v2@v2.1.0/config.go:85 +0x47
github.com/mailru/go-clickhouse/v2.newConn(0xc000174580)
	/data1/home/wujianchao/go/pkg/mod/github.com/mailru/go-clickhouse/v2@v2.1.0/conn.go:68 +0x105
github.com/mailru/go-clickhouse/v2.(*chDriver).Open(0x0?, {0x7ffcb1e6c472?, 0xc00023d150?})
	/data1/home/wujianchao/go/pkg/mod/github.com/mailru/go-clickhouse/v2@v2.1.0/clickhouse.go:22 +0x3a
database/sql.dsnConnector.Connect(...)
	/usr/local/go/src/database/sql/sql.go:758
database/sql.(*DB).conn(0xc000163110, {0x8e9860, 0xbb1b20}, 0x1)
	/usr/local/go/src/database/sql/sql.go:1387 +0x717
database/sql.(*DB).query(0x0?, {0x8e9860, 0xbb1b20}, {0x84cd4a, 0x1b}, {0x0, 0x0, 0x0}, 0x98?)
	/usr/local/go/src/database/sql/sql.go:1721 +0x57
database/sql.(*DB).QueryContext.func1(0x0?)
	/usr/local/go/src/database/sql/sql.go:1704 +0x4f
database/sql.(*DB).retry(0xc00023d3b8?, 0xc00023d380)
	/usr/local/go/src/database/sql/sql.go:1538 +0x42
database/sql.(*DB).QueryContext(0x17?, {0x8e9860?, 0xbb1b20?}, {0x84cd4a?, 0x83a9cc?}, {0x0?, 0x0?, 0x1?})
	/usr/local/go/src/database/sql/sql.go:1703 +0xc5
database/sql.(*DB).Query(...)
	/usr/local/go/src/database/sql/sql.go:1717
main.fetchQuery(0x7ffcb1e6c472?, {0x84cd4a, 0x1b}, {0x0, 0x0, 0x0}, 0xc00023d690)
	/data1/home/wujianchao/project/github/clickhouse-flamegraph/main.go:586 +0x73
main.checkClickHouseVersion(...)
	/data1/home/wujianchao/project/github/clickhouse-flamegraph/main.go:398
main.generate(0xc0001486c0)
	/data1/home/wujianchao/project/github/clickhouse-flamegraph/main.go:263 +0x1ba
main.run(0xc00022c160?)
	/data1/home/wujianchao/project/github/clickhouse-flamegraph/main.go:199 +0x1e6
github.com/urfave/cli/v2.(*Command).Run(0xc00022c160, 0xc0001486c0, {0xc0000240e0, 0xe, 0xe})
	/data1/home/wujianchao/go/pkg/mod/github.com/urfave/cli/v2@v2.27.1/command.go:279 +0x9dd
github.com/urfave/cli/v2.(*App).RunContext(0xc000226000, {0x8e9860?, 0xbb1b20}, {0xc0000240e0, 0xe, 0xe})
	/data1/home/wujianchao/go/pkg/mod/github.com/urfave/cli/v2@v2.27.1/app.go:337 +0x5db
github.com/urfave/cli/v2.(*App).Run(...)
	/data1/home/wujianchao/go/pkg/mod/github.com/urfave/cli/v2@v2.27.1/app.go:311
main.main()
	/data1/home/wujianchao/project/github/clickhouse-flamegraph/main.go:152 +0x1725
@Slach
Copy link
Owner

Slach commented Apr 25, 2024

Thanks for reporting

could you check your --dsn?

according to https://github.com/mailru/go-clickhouse#dsn
it shall be http(s)://user:password@host:port/database

@JackyWoo
Copy link
Contributor Author

Thanks, it works.

@JackyWoo
Copy link
Contributor Author

hi @Slach found another error

clickhouse-flamegraph --clickhouse-dsn http://xxx?allow_introspection_functions=1 --query-id 7d6b01fa-89f0-4eaf-9d4b-e273a6e9ee84 --flamegraph-script /data1/home/wujianchao/cmd/FlameGraph --output-dir .  --trace-type CPU --format svg --debug --from '2024-04-25 00:00:00' --to '2024-04-26 00:00:00'
{"level":"info","dsn":"http://xxx?allow_introspection_functions=1","time":"2024-04-25T15:38:21+08:00","message":"connected to ClickHouse"}
{"level":"debug","sql":"SELECT version() AS version","sqlArgs":"[]","time":"2024-04-25T15:38:21+08:00","message":"query OK"}
{"level":"debug","sql":"\nSELECT DISTINCT hostName() AS host_name, q.query, q.query_id \nFROM system.query_log AS q\nWHERE event_time >= ? AND event_time <= ? AND query_id IN ('7d6b01fa-89f0-4eaf-9d4b-e273a6e9ee84') \n","sqlArgs":"[2024-04-25 00:00:00 +0000 UTC 2024-04-26 00:00:00 +0000 UTC]","time":"2024-04-25T15:38:21+08:00","message":"query OK"}
{"level":"info","sqlFiles":1,"time":"2024-04-25T15:38:21+08:00","message":"write .sql files"}
{"level":"debug","sql":"\nSELECT \n\thostName() AS host_name,\n    replaceAll(t.query_id,':','_') AS query_id,\n\ttrace_type,\n\tsum(abs(size)) AS total_size,\n\tcount() AS samples, \n\tconcat(\n\t\tmultiIf( \n\t\t\tposition( toString(trace_type), 'Memory') > 0 AND sum(size) >= 0, 'allocate;',\n\t\t\tposition( toString(trace_type), 'Memory') > 0 AND sum(size) < 0, 'free;',\n\t\t\tconcat( toString(trace_type), ';')\n\t\t),\n\t\tarrayStringConcat(arrayReverse(arrayMap(x -> concat( demangle(addressToSymbol(x)), '#', addressToLine(x) ), trace)), ';')\n\t) AS stack\nFROM system.trace_log AS t ANY LEFT JOIN system.query_log AS q ON q.query_id=t.query_id\nWHERE  trace_type IN ('CPU') AND event_time >= ? AND event_time <= ? AND query_id IN ('7d6b01fa-89f0-4eaf-9d4b-e273a6e9ee84') \nGROUP BY host_name, query_id, trace_type, trace\nSETTINGS allow_introspection_functions=1\n","sqlArgs":"[2024-04-25 00:00:00 +0000 UTC 2024-04-26 00:00:00 +0000 UTC]","time":"2024-04-25T15:38:21+08:00","message":"query OK"}
panic: runtime error: index out of range [1] with length 1

goroutine 1 [running]:
main.generate(0xc0001ce680)
	/data1/home/wujianchao/project/github/clickhouse-flamegraph/main.go:349 +0xb45
main.run(0xc000256160?)
	/data1/home/wujianchao/project/github/clickhouse-flamegraph/main.go:199 +0x1e6
github.com/urfave/cli/v2.(*Command).Run(0xc000256160, 0xc0001ce680, {0xc0001aa000, 0x12, 0x12})
	/data1/home/wujianchao/go/pkg/mod/github.com/urfave/cli/v2@v2.27.1/command.go:279 +0x9dd
github.com/urfave/cli/v2.(*App).RunContext(0xc00024c000, {0x8e9860?, 0xbb1b20}, {0xc0001aa000, 0x12, 0x12})
	/data1/home/wujianchao/go/pkg/mod/github.com/urfave/cli/v2@v2.27.1/app.go:337 +0x5db
github.com/urfave/cli/v2.(*App).Run(...)
	/data1/home/wujianchao/go/pkg/mod/github.com/urfave/cli/v2@v2.27.1/app.go:311
main.main()
	/data1/home/wujianchao/project/github/clickhouse-flamegraph/main.go:152 +0x1725

The formatted sql in log :

SELECT
    hostName() AS host_name,
    replaceAll(t.query_id, ':', '_') AS query_id,
    trace_type,
    sum(abs(size)) AS total_size,
    count() AS samples,
    concat(
        multiIf(
            position(toString(trace_type), 'Memory') > 0 AND sum(size) >= 0, 'allocate;',
            position(toString(trace_type), 'Memory') > 0 AND sum(size) < 0, 'free;',
            concat(toString(trace_type), ';')
        ),
        arrayStringConcat(arrayReverse(arrayMap(x -> concat(demangle(addressToSymbol(x)), '#', addressToLine(x)), trace)), ';')
    ) AS stack
FROM
    system.trace_log AS t
    ANY LEFT JOIN system.query_log AS q ON q.query_id = t.query_id
WHERE
    trace_type IN ('CPU')
    AND event_time >= '2024-04-25 00:00:00'
    AND event_time <= '2024-04-26 00:00:00'
    AND query_id IN ('7d6b01fa-89f0-4eaf-9d4b-e273a6e9ee84')
GROUP BY
    host_name,
    query_id,
    trace_type,
    trace
SETTINGS
    allow_introspection_functions = 1
;

And got 79 rows in my ClickHouse instance.

@JackyWoo
Copy link
Contributor Author

Foud the reason, I cannot use --output-dir ., but --output-dir /data1/home/wujianchao/project/github/clickhouse-flamegraph instead. Maybe we should fix it.

@JackyWoo
Copy link
Contributor Author

JackyWoo commented Apr 25, 2024

@Slach this is really an excellent project, it helps so much. Thanks.

@Slach
Copy link
Owner

Slach commented Apr 25, 2024

@JackyWoo ;) you also could use https://github.com/azat/chdig/

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 a pull request may close this issue.

2 participants