Project

General

Profile

Task #17935

WSC: show_highprilog()

Added by Sachin Divekar about 1 year ago. Updated about 1 year ago.

Status:
Closed
Priority:
Normal
Assignee:
Start date:
18/03/2024
Due date:
18/03/2024
% Done:

100%

Estimated time:

Files

clipboard-202402211758-ynu6e.png (61.4 KB) clipboard-202402211758-ynu6e.png Aniket Shinde, 21/02/2024 05:58 PM
clipboard-202402211758-woppl.png (118 KB) clipboard-202402211758-woppl.png Aniket Shinde, 21/02/2024 05:58 PM
clipboard-202402211800-nc86o.png (207 KB) clipboard-202402211800-nc86o.png Aniket Shinde, 21/02/2024 06:00 PM

Related issues

Follows LogHarbour: logging - Task #18066: Go lib: GetLogs()Closed15/03/2024Tushar Bhingare

Actions
#1

Updated by Shuvam Misra about 1 year ago

  • Target version set to Sprint 29 Feb
#2

Updated by Aniket Shinde about 1 year ago

  • Assignee set to Aniket Shinde
  • Status changed from New to In Progress

Going through Elasticsearch.

#4

Updated by Aniket Shinde about 1 year ago

Update: implemented elasticsearch db and golang connection, started writing API

#5

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

#6

Updated by Shuvam Misra about 1 year ago

  • Target version changed from Sprint 29 Feb to Sprint 15 Mar
#7

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
#8

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))

#9

Updated by Aniket Shinde about 1 year ago

  • Status changed from On Hold to In Progress

implemented library function GetLogs() to carry out request

#10

Updated by Shuvam Misra about 1 year ago

  • Status changed from In Progress to Testing
#11

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

#12

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

}

#13

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.

Also available in: Atom PDF