Skip to content

LD client doesn't correctly interpret file data sources #157

Closed as not planned
@constant-mihai

Description

Is this a support request?
No.

Describe the bug
I am trying to use a file data source, but can't seem to manage to do so.
I cannot be sure if there is some issue in my yaml file. I have tried multiple configurations, none seem to work.

To reproduce
Run the following program:

package main

import (
	"fmt"
	"os"
	"os/signal"
	"syscall"
	"time"

	"gopkg.in/launchdarkly/go-sdk-common.v2/lduser"
	sdk "gopkg.in/launchdarkly/go-server-sdk.v5"
	"gopkg.in/launchdarkly/go-server-sdk.v5/ldcomponents"
	"gopkg.in/launchdarkly/go-server-sdk.v5/ldfiledata"
	"gopkg.in/launchdarkly/go-server-sdk.v5/ldfilewatch"
)

func main() {
	sigs := make(chan os.Signal, 1)
	signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)

	ldClient, _ := sdk.MakeCustomClient("sdk-key-123abc",
		sdk.Config{
			Events: ldcomponents.NoEvents(),
			DataSource: ldfiledata.DataSource().
				FilePaths("./ld.yaml").
				Reloader(ldfilewatch.WatchFiles),
		}, 0)

	// Not sure how MakeCustomClient works, so I'm putting a sleep here.
	time.Sleep(3 * time.Second)
	context := lduser.NewUserBuilder("user-key-1").Build()
	optIn, err := ldClient.BoolVariation("opt-in", context, false)
	if err != nil {
		fmt.Printf("%s\n", err.Error())
		return
	}
	fmt.Printf("opt-in: %v\n", optIn)
}

ld.yaml

flags:
  opt-in:
    key: opt-in
    on: true
    fallthrough:
      variation: 0
    variations:
      - true
      - false
    targets:
      - contextKind: user
        variation: 0
        values:
        - user-key-1
    rules:
      - variation: 0
        clauses:
          - contextKind: user
            attribute: key
            op: in
            values:
              - user-key-1

The program prints:

[LaunchDarkly] 2024/06/17 10:44:05 INFO: Starting LaunchDarkly client 5.10.1
[LaunchDarkly] 2024/06/17 10:44:05 INFO: FileDataSource: Reloading flag data after detecting a change
opt-in: false

Expected behavior
Expected the program to print:

[LaunchDarkly] 2024/06/17 10:44:05 INFO: Starting LaunchDarkly client 5.10.1
[LaunchDarkly] 2024/06/17 10:44:05 INFO: FileDataSource: Reloading flag data after detecting a change
opt-in: true

Logs
See above.

SDK version
5.10.1

Language version, developer tools
go 1.22.1

OS/platform
Ubuntu 22.04

Additional context
N/A.

Metadata

Assignees

No one assigned

    Labels

    StalebugSomething isn't workingserver-sdkIssues affecting the Go server SDKwaiting for feedbackIndicates LaunchDarkly is waiting for customer feedback before issue is closed due to staleness.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions