@@ -67,21 +67,13 @@ func TestAddLogRecord(t *testing.T) {
6767 }
6868
6969 logs := plog .NewLogs ()
70+ scope := logs .ResourceLogs ().AppendEmpty ().ScopeLogs ().AppendEmpty ()
7071 observedTime := now .Add (time .Minute )
71- require .NoError (t , addLogRecord (logs , entry , observedTime ))
72-
73- require .Equal (t , 1 , logs .ResourceLogs ().Len ())
74- resource := logs .ResourceLogs ().At (0 )
75-
76- // Check resource attributes.
77- serviceName , ok := resource .Resource ().Attributes ().Get ("service.name" )
78- require .True (t , ok )
79- require .Equal (t , "oxide" , serviceName .Str ())
72+ require .NoError (t , addLogRecord (scope , entry , observedTime ))
8073
8174 // Check log record.
82- require .Equal (t , 1 , resource .ScopeLogs ().Len ())
83- require .Equal (t , 1 , resource .ScopeLogs ().At (0 ).LogRecords ().Len ())
84- log := resource .ScopeLogs ().At (0 ).LogRecords ().At (0 )
75+ require .Equal (t , 1 , scope .LogRecords ().Len ())
76+ log := scope .LogRecords ().At (0 )
8577
8678 require .Equal (t ,
8779 pcommon .NewTimestampFromTime (startTime ),
@@ -149,12 +141,13 @@ func TestCursor(t *testing.T) {
149141 }
150142
151143 logs := plog .NewLogs ()
144+ scope := logs .ResourceLogs ().AppendEmpty ().ScopeLogs ().AppendEmpty ()
152145 now := time .Now ()
153146 for _ , entry := range entries {
154147 if entry .Id == s .cursor .ID {
155148 continue
156149 }
157- require .NoError (t , addLogRecord (logs , entry , now ))
150+ require .NoError (t , addLogRecord (scope , entry , now ))
158151 if entry .TimeCompleted != nil {
159152 s .cursor = cursor {
160153 TimeCompleted : entry .TimeCompleted ,
@@ -187,6 +180,7 @@ func makeEntry(id string, tc *time.Time) oxide.AuditLogEntry {
187180
188181// mockAuditLogClient returns pages in sequence, allowing injection of errors.
189182type mockAuditLogClient struct {
183+ host string
190184 pages []mockPage
191185 calls int
192186}
@@ -208,11 +202,52 @@ func (m *mockAuditLogClient) AuditLogList(
208202 return page .result , page .err
209203}
210204
205+ func (m * mockAuditLogClient ) Host () string {
206+ return m .host
207+ }
208+
209+ func TestScrape (t * testing.T ) {
210+ t1 := time .Date (2025 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC )
211+
212+ client := & mockAuditLogClient {
213+ host : "https://example.oxide.computer" ,
214+ pages : []mockPage {
215+ {
216+ result : & oxide.AuditLogEntryResultsPage {
217+ Items : []oxide.AuditLogEntry {makeEntry ("id-1" , & t1 )},
218+ },
219+ },
220+ },
221+ }
222+
223+ s := newAuditLogScraper (
224+ & Config {InitialLookback : time .Hour },
225+ componenttest .NewNopTelemetrySettings (),
226+ client ,
227+ )
228+ require .NoError (t , s .Start (context .Background (), nil ))
229+
230+ logs , err := s .Scrape (context .Background ())
231+ require .NoError (t , err )
232+ require .Equal (t , 1 , logs .ResourceLogs ().Len ())
233+
234+ attrs := logs .ResourceLogs ().At (0 ).Resource ().Attributes ()
235+
236+ serviceName , ok := attrs .Get ("service.name" )
237+ require .True (t , ok )
238+ require .Equal (t , "oxide" , serviceName .Str ())
239+
240+ host , ok := attrs .Get ("oxide.host" )
241+ require .True (t , ok )
242+ require .Equal (t , "example.oxide.computer" , host .Str ())
243+ }
244+
211245func TestScrapePartialResults (t * testing.T ) {
212246 t1 := time .Date (2025 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC )
213247 t2 := time .Date (2025 , 1 , 1 , 0 , 0 , 1 , 0 , time .UTC )
214248
215249 client := & mockAuditLogClient {
250+ host : "https://example.oxide.computer" ,
216251 pages : []mockPage {
217252 {
218253 result : & oxide.AuditLogEntryResultsPage {
@@ -255,6 +290,7 @@ func TestCursorPersistence(t *testing.T) {
255290 cursorPath := filepath .Join (t .TempDir (), "cursor.json" )
256291
257292 client := & mockAuditLogClient {
293+ host : "https://example.oxide.computer" ,
258294 pages : []mockPage {
259295 {
260296 result : & oxide.AuditLogEntryResultsPage {
0 commit comments