forked from galaxydi/go-loghub
-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #210 from wangkaibo34/feature/eventstore_sdk
Feature/eventstore sdk
- Loading branch information
Showing
6 changed files
with
330 additions
and
4 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
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,142 @@ | ||
package sls | ||
|
||
const ( | ||
EventStoreTelemetryType = "Event" | ||
EventStoreIndex = `{ | ||
"max_text_len": 16384, | ||
"ttl": 7, | ||
"log_reduce": false, | ||
"line": { | ||
"caseSensitive": false, | ||
"chn": true, | ||
"token": [",", " ", "'", "\"", ";", "=", "(", ")", "[", "]", "{", "}", "?", "@", "&", "<", ">", "/", ":", "\n", "\t", "\r"] | ||
}, | ||
"keys": { | ||
"specversion": { | ||
"type": "text", | ||
"doc_value": true, | ||
"alias": "", | ||
"caseSensitive": false, | ||
"chn": false, | ||
"token": [",", " ", "'", "\"", ";", "=", "(", ")", "[", "]", "{", "}", "?", "@", "&", "<", ">", "/", ":", "\n", "\t", "\r"] | ||
}, | ||
"id": { | ||
"type": "text", | ||
"doc_value": true, | ||
"alias": "", | ||
"caseSensitive": false, | ||
"chn": false, | ||
"token": [",", " ", "'", "\"", ";", "=", "(", ")", "[", "]", "{", "}", "?", "@", "&", "<", ">", "/", ":", "\n", "\t", "\r"] | ||
}, | ||
"source": { | ||
"type": "text", | ||
"doc_value": true, | ||
"alias": "", | ||
"caseSensitive": false, | ||
"chn": false, | ||
"token": [",", " ", "'", "\"", ";", "=", "(", ")", "[", "]", "{", "}", "?", "@", "&", "<", ">", "/", "\n", "\t", "\r"] | ||
}, | ||
"type": { | ||
"type": "text", | ||
"doc_value": true, | ||
"alias": "", | ||
"caseSensitive": false, | ||
"chn": false, | ||
"token": [",", " ", "'", "\"", ";", "=", "(", ")", "[", "]", "{", "}", "?", "@", "&", "<", ">", "/", ":", "\n", "\t", "\r"] | ||
}, | ||
"subject": { | ||
"type": "text", | ||
"doc_value": true, | ||
"alias": "", | ||
"caseSensitive": false, | ||
"chn": false, | ||
"token": [",", " ", "'", "\"", ";", "=", "(", ")", "[", "]", "{", "}", "?", "@", "&", "<", ">", "/", ":", "\n", "\t", "\r"] | ||
}, | ||
"datacontenttype": { | ||
"type": "text", | ||
"doc_value": true, | ||
"alias": "", | ||
"caseSensitive": false, | ||
"chn": false, | ||
"token": [",", " ", "'", "\"", ";", "=", "(", ")", "[", "]", "{", "}", "?", "@", "&", "<", ">", "/", ":", "\n", "\t", "\r"] | ||
}, | ||
"dataschema": { | ||
"type": "text", | ||
"doc_value": true, | ||
"alias": "", | ||
"caseSensitive": false, | ||
"chn": false, | ||
"token": [",", " ", "'", "\"", ";", "=", "(", ")", "[", "]", "{", "}", "?", "@", "&", "<", ">", "/", ":", "\n", "\t", "\r"] | ||
}, | ||
"data": { | ||
"type": "json", | ||
"doc_value": true, | ||
"alias": "", | ||
"caseSensitive": false, | ||
"chn": false, | ||
"token": [",", " ", "'", "\"", ";", "=", "(", ")", "[", "]", "{", "}", "?", "@", "&", "<", ">", "/", ":", "\n", "\t", "\r"], | ||
"index_all": true, | ||
"max_depth": -1, | ||
"json_keys": {} | ||
}, | ||
"time": { | ||
"type": "text", | ||
"doc_value": true, | ||
"alias": "", | ||
"caseSensitive": false, | ||
"chn": false, | ||
"token": [",", " ", "'", "\"", ";", "=", "(", ")", "[", "]", "{", "}", "?", "@", "&", "<", ">", "/", ":", "\n", "\t", "\r"] | ||
}, | ||
"title": { | ||
"type": "text", | ||
"doc_value": true, | ||
"alias": "", | ||
"caseSensitive": false, | ||
"chn": false, | ||
"token": [",", " ", "'", "\"", ";", "=", "(", ")", "[", "]", "{", "}", "?", "@", "&", "<", ">", "/", ":", "\n", "\t", "\r"] | ||
}, | ||
"message": { | ||
"type": "text", | ||
"doc_value": true, | ||
"alias": "", | ||
"caseSensitive": false, | ||
"chn": false, | ||
"token": [",", " ", "'", "\"", ";", "=", "(", ")", "[", "]", "{", "}", "?", "@", "&", "<", ">", "/", ":", "\n", "\t", "\r"] | ||
}, | ||
"status": { | ||
"type": "text", | ||
"doc_value": true, | ||
"alias": "", | ||
"caseSensitive": false, | ||
"chn": false, | ||
"token": [",", " ", "'", "\"", ";", "=", "(", ")", "[", "]", "{", "}", "?", "@", "&", "<", ">", "/", ":", "\n", "\t", "\r"] | ||
} | ||
} | ||
}` | ||
) | ||
|
||
func (c *Client) CreateEventStore(project string, eventStore *LogStore) error { | ||
eventStore.TelemetryType = EventStoreTelemetryType | ||
err := c.CreateLogStoreV2(project, eventStore) | ||
if err != nil { | ||
return err | ||
} | ||
return c.CreateIndexString(project, eventStore.Name, EventStoreIndex) | ||
} | ||
|
||
func (c *Client) UpdateEventStore(project string, eventStore *LogStore) error { | ||
eventStore.TelemetryType = EventStoreTelemetryType | ||
return c.UpdateLogStoreV2(project, eventStore) | ||
} | ||
|
||
func (c *Client) DeleteEventStore(project, name string) error { | ||
return c.DeleteLogStore(project, name) | ||
} | ||
|
||
func (c *Client) GetEventStore(project, name string) (*LogStore, error) { | ||
return c.GetLogStore(project, name) | ||
} | ||
|
||
func (c *Client) ListEventStore(project string, offset, size int) ([]string, error) { | ||
return c.ListLogStoreV2(project, offset, size, EventStoreTelemetryType) | ||
} |
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,89 @@ | ||
package sls | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
func TestEventStore(t *testing.T) { | ||
suite.Run(t, new(EventStoreTestSuite)) | ||
} | ||
|
||
type EventStoreTestSuite struct { | ||
suite.Suite | ||
endpoint string | ||
projectName string | ||
eventStoreName string | ||
accessKeyID string | ||
accessKeySecret string | ||
ttl int | ||
shardCnt int | ||
client *Client | ||
} | ||
|
||
func (m *EventStoreTestSuite) SetupSuite() { | ||
m.endpoint = os.Getenv("LOG_TEST_ENDPOINT") | ||
m.accessKeyID = os.Getenv("LOG_TEST_ACCESS_KEY_ID") | ||
m.accessKeySecret = os.Getenv("LOG_TEST_ACCESS_KEY_SECRET") | ||
suffix := time.Now().Unix() | ||
m.projectName = fmt.Sprintf("test-event-store-%d", suffix) | ||
m.eventStoreName = "test" | ||
m.ttl = 30 | ||
m.shardCnt = 2 | ||
m.client = &Client{ | ||
Endpoint: m.endpoint, | ||
AccessKeyID: m.accessKeyID, | ||
AccessKeySecret: m.accessKeySecret, | ||
} | ||
_, err := m.client.CreateProject(m.projectName, "test event store") | ||
m.Require().Nil(err) | ||
time.Sleep(time.Minute) | ||
} | ||
|
||
func (m *EventStoreTestSuite) TearDownSuite() { | ||
err := m.client.DeleteProject(m.projectName) | ||
m.Require().Nil(err) | ||
} | ||
|
||
func (m *EventStoreTestSuite) TestClient_CreateAndDeleteEventStore() { | ||
eventStore := &LogStore{ | ||
Name: m.eventStoreName, | ||
TTL: m.ttl, | ||
ShardCount: m.shardCnt, | ||
} | ||
ce := m.client.CreateEventStore(m.projectName, eventStore) | ||
m.Require().Nil(ce) | ||
de := m.client.DeleteEventStore(m.projectName, m.eventStoreName) | ||
m.Require().Nil(de) | ||
} | ||
|
||
func (m *EventStoreTestSuite) TestClient_UpdateAndGetEventStore() { | ||
eventStore := &LogStore{ | ||
Name: m.eventStoreName, | ||
TTL: m.ttl, | ||
ShardCount: m.shardCnt, | ||
} | ||
ce := m.client.CreateEventStore(m.projectName, eventStore) | ||
m.Require().Nil(ce) | ||
eventStore, ge := m.client.GetEventStore(m.projectName, m.eventStoreName) | ||
m.Require().Nil(ge) | ||
m.Require().Equal(m.eventStoreName, eventStore.Name) | ||
m.Require().Equal(m.ttl, eventStore.TTL) | ||
m.Require().Equal(m.shardCnt, eventStore.ShardCount) | ||
m.Require().Equal(EventStoreTelemetryType, eventStore.TelemetryType) | ||
|
||
eventStore.TTL = 15 | ||
ue := m.client.UpdateEventStore(m.projectName, eventStore) | ||
m.Require().Nil(ue) | ||
eventStore1, ge1 := m.client.GetEventStore(m.projectName, m.eventStoreName) | ||
m.Require().Nil(ge1) | ||
m.Require().Equal(m.eventStoreName, eventStore1.Name) | ||
m.Require().Equal(15, eventStore1.TTL) | ||
m.Require().Equal(EventStoreTelemetryType, eventStore1.TelemetryType) | ||
de := m.client.DeleteEventStore(m.projectName, m.eventStoreName) | ||
m.Require().Nil(de) | ||
} |
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