Task #17935
WSC: show_highprilog()
Start date:
18/03/2024
Due date:
18/03/2024
% Done:
100%
Estimated time:
Files
Related issues
Updated by Aniket Shinde about 1 year ago
- Assignee set to Aniket Shinde
- Status changed from New to In Progress
Going through Elasticsearch.
Updated by Aniket Shinde about 1 year ago
- File clipboard-202402211800-nc86o.png clipboard-202402211800-nc86o.png added
- File clipboard-202402211758-woppl.png clipboard-202402211758-woppl.png added
- File clipboard-202402211758-ynu6e.png clipboard-202402211758-ynu6e.png added
installed elasticsearch and tested with dummy data:
Updated by Aniket Shinde about 1 year ago
Update: implemented elasticsearch db and golang connection, started writing API
Updated by Aniket Shinde about 1 year ago
- % Done changed from 0 to 30
added raw api to do the pagination.
working on business logic and demo seed data to do the testing
Updated by Shuvam Misra about 1 year ago
- Target version changed from Sprint 29 Feb to Sprint 15 Mar
Updated by Shuvam Misra about 1 year ago
- Follows Task #18066: Go lib: GetLogs() added
- Start date set to 18/03/2024
- Due date set to 18/03/2024
Updated by Aniket Shinde about 1 year ago
- Status changed from In Progress to On Hold
Working on Go lib, hence putting this task on hold
Ref ( WhatsApp group msg from Shuvam on(01/03/2024))
Updated by Aniket Shinde about 1 year ago
- Status changed from On Hold to In Progress
implemented library function GetLogs() to carry out request
Updated by Aniket Shinde about 1 year ago
Important:¶
GET /logharbour/_search { "from": 0, "size": 100, "query": { "match": { "_id": "fLhMI44BKyLHEbgtQwAR" } }, "sort": [ { "_doc": { "order": "desc" } }, { "when": { "order": "desc" } } ] }
created seed data for docker db test:
logharbour_demo_data.es
Updated by Aniket Shinde about 1 year ago
Completed: written a demo data insert query that will be used for migration.
In Progress: Worked on Docker test with elastic search:
package schema_test
import (
"fmt"
"log"
"os"
"testing"
"time"
"github.com/elastic/elastic-transport-go/v8/elastictransport"
"github.com/elastic/go-elasticsearch/v8"
"github.com/gin-gonic/gin"
"github.com/ory/dockertest/v3"
"github.com/ory/dockertest/v3/docker"
"github.com/remiges-tech/alya/service"
"github.com/remiges-tech/alya/wscutils"
"github.com/remiges-tech/logharbour/logharbour"
)
var r *gin.Engine
// var versionTable string = "schema_version_non_default"
func TestMain(m *testing.M) {
// Initialize Docker pool to insure it close at the end
pool, err := dockertest.NewPool("")
if err != nil {
log.Fatalf("Could not connect to Docker: %v", err)
}
fmt.Println("Initialize Docker pool")
// Deploy the Elasticsearch container.
resource, databaseUrl, err := deployElasticsearch(pool)
if err != nil {
log.Fatalf("Could not start resource: %v", err)
}
fmt.Println("Deploy the Elasticsearch container")
// ternMigrate(databaseUrl)
fmt.Println("tern migrate")
// Register routes.
r, err = registerRoutes(pool, databaseUrl)
if err != nil {
log.Fatalf("Could not start resource: %v", err)
}
fmt.Println("Register routes")
// Run the tests.
exitCode := m.Run()
// Exit with the appropriate code.
if err := pool.Purge(resource); err != nil {
log.Fatalf("Could not purge resource: %s", err)
}
fmt.Println("Exit with the appropriate code")
os.Exit(exitCode)
}
func deployElasticsearch(pool *dockertest.Pool) (*dockertest.Resource, string, error) {
// Define the Elasticsearch Docker container configuration
elasticsearchOptions := &dockertest.RunOptions{
Repository: "docker.elastic.co/elasticsearch/elasticsearch",
Tag: "8.12.2", // Replace with the desired Elasticsearch version
Cmd: []string{"elasticsearch", "-E", "discovery.type=single-node"},
PortBindings: map[docker.Port][]docker.PortBinding{
"9200/tcp": {{HostIP: "", HostPort: ""}},
},
}
// Pull the Elasticsearch image
err := pool.Client.PullImage(docker.PullImageOptions{
Repository: elasticsearchOptions.Repository,
Tag: elasticsearchOptions.Tag,
}, docker.AuthConfiguration{})
if err != nil {
return nil, "", fmt.Errorf("failed to pull Elasticsearch image: %v", err)
}
// Start the Elasticsearch container
resource, err := pool.RunWithOptions(elasticsearchOptions, func(config *docker.HostConfig) {
// set AutoRemove to true so that stopped container goes away by itself
config.AutoRemove = true
config.RestartPolicy = docker.RestartPolicy{Name: "no"}
})
if err != nil {
return nil, "", fmt.Errorf("failed to start Elasticsearch container: %v", err)
}
// Ensure that the Elasticsearch container is ready to accept connections
// ctx := context.Background()
err = pool.Retry(func() error {
url := fmt.Sprintf("http://%s", resource.GetHostPort("9200/tcp"))
fmt.Println(">>>>>>URL:", url)
// resp, err := http.Get(url)
// if err != nil {
// fmt.Println("<<<<<", err)
// return err
// }
// defer resp.Body.Close()
dbConfig := elasticsearch.Config{
Addresses: []string{url},
// Username: appConfig.DBUser,
// Password: appConfig.DBPassword,
// CertificateFingerprint: appConfig.CertificateFingerprint,
// show request query logger
Logger: &elastictransport.TextLogger{Output: log.Writer(), EnableRequestBody: true},
}
client, err := elasticsearch.NewTypedClient(dbConfig)
if err != nil {
return err
}
fmt.Println("+++++++++++", client.SearchTemplate)
return nil
})
if err != nil {
return nil, "", fmt.Errorf("failed to connect to Elasticsearch container: %v", err)
}
// Return the resource and Elasticsearch URL
elasticsearchURL := fmt.Sprintf("http://%s:%s", resource.GetHostPort("9200/tcp"), resource.GetPort("9200/tcp"))
log.Println("Connecting to database on url: ", elasticsearchURL)
resource.Expire(120) // Tell docker to hard kill the container in 120 seconds
pool.MaxWait = 120 * time.Second
return resource, elasticsearchURL, nil
}
// registerRoutes register and runs.
func registerRoutes(pool *dockertest.Pool, databaseUrl string) (*gin.Engine, error) {
// router
gin.SetMode(gin.TestMode)
r := gin.Default()
// logger setup
fallbackWriter := logharbour.NewFallbackWriter(os.Stdout, os.Stdout)
lctx := logharbour.NewLoggerContext(logharbour.Info)
l := logharbour.NewLogger(lctx, "logharbour", fallbackWriter)
// Define a custom validation tag-to-message ID map
customValidationMap := map[string]int{
"required": 101,
"gt": 102,
"alpha": 103,
"lowercase": 104,
}
// Custom validation tag-to-error code map
customErrCodeMap := map[string]string{
"required": "required",
"gt": "greater",
"alpha": "alphabet",
"lowercase": "lowercase",
}
// Register the custom map with wscutils
wscutils.SetValidationTagToMsgIDMap(customValidationMap)
wscutils.SetValidationTagToErrCodeMap(customErrCodeMap)
// Set default message ID and error code if needed
wscutils.SetDefaultMsgID(100)
wscutils.SetDefaultErrCode("validation_error")
// schema services
s := service.NewService(r).
WithLogHarbour(l)
// WithDatabase(connPool)
fmt.Println(">>>>>>>>>>>>", s)
return r, nil
}
Updated by Aniket Shinde about 1 year ago
- % Done changed from 30 to 100
- Status changed from Testing to Closed
added test cases, hence closing the task.