forked from grafana/sentry-datasource
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into olegyevik-sentry-datasource-select-project
- Loading branch information
Showing
17 changed files
with
486 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name: Dependabot reviewer | ||
|
||
on: pull_request_target | ||
|
||
permissions: | ||
pull-requests: write | ||
contents: write | ||
|
||
jobs: | ||
call-workflow-passing-data: | ||
uses: grafana/security-github-actions/.github/workflows/dependabot-automerge.yaml@main | ||
# with: | ||
# Add this to define production packages that dependabot can auto-update if the bump is minor | ||
# packages-minor-autoupdate: '[]' | ||
secrets: inherit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package sentry | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
"strconv" | ||
"time" | ||
) | ||
|
||
var reqFields = [...]string{ | ||
"id", | ||
"title", | ||
"project", | ||
"project.id", | ||
"release", | ||
"count()", | ||
"epm()", | ||
"last_seen()", | ||
"level", | ||
"event.type", | ||
"platform", | ||
} | ||
|
||
type SentryEvents struct { | ||
Data []SentryEvent `json:"data"` | ||
Meta map[string]interface{} `json:"meta"` | ||
} | ||
|
||
type SentryEvent struct { | ||
ID string `json:"id"` | ||
Title string `json:"title"` | ||
Project string `json:"project"` | ||
ProjectId int64 `json:"project.id"` | ||
Release string `json:"release"` | ||
Count int64 `json:"count()"` | ||
EventsPerMinute float64 `json:"epm()"` | ||
LastSeen time.Time `json:"last_seen()"` | ||
Level string `json:"level"` | ||
EventType string `json:"event.type"` | ||
Platform string `json:"platform"` | ||
} | ||
|
||
type GetEventsInput struct { | ||
OrganizationSlug string | ||
ProjectIds []string | ||
Environments []string | ||
Query string | ||
From time.Time | ||
To time.Time | ||
Sort string | ||
Limit int64 | ||
} | ||
|
||
func (gei *GetEventsInput) ToQuery() string { | ||
urlPath := fmt.Sprintf("/api/0/organizations/%s/events/?", gei.OrganizationSlug) | ||
if gei.Limit < 1 || gei.Limit > 100 { | ||
gei.Limit = 100 | ||
} | ||
params := url.Values{} | ||
params.Set("query", gei.Query) | ||
params.Set("start", gei.From.Format("2006-01-02T15:04:05")) | ||
params.Set("end", gei.To.Format("2006-01-02T15:04:05")) | ||
if gei.Sort != "" { | ||
params.Set("sort", gei.Sort) | ||
} | ||
params.Set("per_page", strconv.FormatInt(gei.Limit, 10)) | ||
for _, field := range reqFields { | ||
params.Add("field", field) | ||
} | ||
for _, projectId := range gei.ProjectIds { | ||
params.Add("project", projectId) | ||
} | ||
for _, environment := range gei.Environments { | ||
params.Add("environment", environment) | ||
} | ||
return urlPath + params.Encode() | ||
} | ||
|
||
func (sc *SentryClient) GetEvents(gei GetEventsInput) ([]SentryEvent, string, error) { | ||
var out SentryEvents | ||
executedQueryString := gei.ToQuery() | ||
err := sc.Fetch(executedQueryString, &out) | ||
return out.Data, sc.BaseURL + executedQueryString, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { EventsEditor } from './EventsEditor'; | ||
import type { SentryEventsQuery } from '../../types'; | ||
|
||
describe('EventsEditor', () => { | ||
it('should render without error', () => { | ||
const query = { | ||
queryType: 'events', | ||
projectIds: [], | ||
environments: [], | ||
eventsQuery: '', | ||
refId: 'A', | ||
} as SentryEventsQuery; | ||
const onChange = jest.fn(); | ||
const onRunQuery = jest.fn(); | ||
const result = render(<EventsEditor query={query} onChange={onChange} onRunQuery={onRunQuery} />); | ||
expect(result.container.firstChild).not.toBeNull(); | ||
}); | ||
}); |
Oops, something went wrong.