Skip to content

Commit

Permalink
[oracle] Fix tablespace test for RDS (#27882)
Browse files Browse the repository at this point in the history
  • Loading branch information
nenadnoveljic authored Jul 23, 2024
1 parent 5b3ea17 commit a6f2368
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,16 @@ begin
if l_create_dir is null then
select SUBSTR(file_name,1,(INSTR(file_name,'/',-1,1)-1)) into dir from dba_data_files where rownum = 1;
execute immediate 'create tablespace tbs_test datafile ''' || dir || '/tbs_test01.dbf'' size 100M';
execute immediate 'create tablespace tbs_test_offline datafile ''' || dir || '/tbs_test01.dbf'' size 10M';
else
execute immediate 'create tablespace tbs_test datafile size 100M';
execute immediate 'create tablespace tbs_test_offline datafile size 10M';
end if;
end;
/

-- to avoid size getting to 0 with RDS or Oracle managed files
create table t_tbs_test(n number) tablespace tbs_test;
insert into t_tbs_test values(1);
commit;

25 changes: 12 additions & 13 deletions pkg/collector/corechecks/oracle/tablespaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,7 @@ func TestTablespaces(t *testing.T) {
err := c.Run()
require.NoError(t, err)
s.On("Gauge", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return()
var expectedPdb string
if c.hostingType == rds {
expectedPdb = "orcl"
} else if c.connectedToPdb {
expectedPdb = c.cdbName
} else {
expectedPdb = "cdb$root"
}
expectedPdb := getExpectedPdb(&c)
tags := []string{fmt.Sprintf("pdb:%s", expectedPdb), "tablespace:TBS_TEST"}
s.AssertMetricOnce(t, "Gauge", "oracle.tablespace.size", 104857600, c.dbHostname, tags)
s.AssertMetricOnce(t, "Gauge", "oracle.tablespace.offline", 0, c.dbHostname, tags)
Expand All @@ -47,26 +40,33 @@ func TestTablespaces(t *testing.T) {
func TestTablespacesOffline(t *testing.T) {
c, s := newDefaultCheck(t, "", "")
defer c.Teardown()

connection := getConnectData(t, useSysUser)
databaseUrl := go_ora.BuildUrl(connection.Server, connection.Port, connection.ServiceName, connection.Username, connection.Password, nil)
conn, err2 := sql.Open("oracle", databaseUrl)
require.NoError(t, err2)

const tablespaceName = "TBS_TEST_OFFLINE"

defer func() {
_, err := conn.Exec("ALTER TABLESPACE TBS_TEST ONLINE")
_, err := conn.Exec(fmt.Sprintf("ALTER TABLESPACE %s ONLINE", tablespaceName))
require.NoError(t, err)
conn.Close()
}()

_, err3 := conn.Exec("ALTER TABLESPACE TBS_TEST OFFLINE")
_, err3 := conn.Exec(fmt.Sprintf("ALTER TABLESPACE %s OFFLINE", tablespaceName))
require.NoError(t, err3)

time.Sleep(10 * time.Second)

err := c.Run()
require.NoError(t, err)
s.On("Gauge", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return()
expectedPdb := getExpectedPdb(&c)
tags := []string{fmt.Sprintf("pdb:%s", expectedPdb), fmt.Sprintf("tablespace:%s", tablespaceName)}
s.AssertMetricOnce(t, "Gauge", "oracle.tablespace.offline", 1, c.dbHostname, tags)
}

func getExpectedPdb(c *Check) string {
var expectedPdb string
if c.hostingType == rds {
expectedPdb = "orcl"
Expand All @@ -75,6 +75,5 @@ func TestTablespacesOffline(t *testing.T) {
} else {
expectedPdb = "cdb$root"
}
tags := []string{fmt.Sprintf("pdb:%s", expectedPdb), "tablespace:TBS_TEST"}
s.AssertMetricOnce(t, "Gauge", "oracle.tablespace.offline", 1, c.dbHostname, tags)
return expectedPdb
}

0 comments on commit a6f2368

Please sign in to comment.